Question

I am trying to plot a time series model using R. So far I have the...

I am trying to plot a time series model using R. So far I have the following code, but I'm getting an error located at the very bottom. Can you please explain what I'm doing wrong, and what I should be doing instead in order to avoid the error? As far as the data is concerned, the first column displays time (hour-by-hour) across 20 days, giving 504 rows of data and the six columns thereafter display the bike demand/usage at each individual hour for six different bike stations. I am looking to answer the following two questions:

1.) Predict the next 3 hours of the bike stations' demands. Discuss the predicted results.

2.) Aggregating your hourly data into daily data, choose the same 6 stations to predict their next three day’s bike demands. Discuss the predicted results.

Here is my code so far (with the error):

> movavg <- function(x, n, type=c("s", "t", "w", "m", "e", "r")) {
+ stopifnot(is.numeric(x), is.numeric(n), is.character(type))
+ if (length(n) != 1 || ceiling(n != floor(n)) || n <= 1)
+ stop("Window length 'n' must be a single integer greater 1.")
+ nx <- length(x)
+ if (n >= nx)
+ stop("Window length 'n' must be greater then length of time series.")
+ y <- numeric(nx)
+ if (type == "s") { # simple
+ for (k in 1:(n-1)) y[k] <- mean(x[1:k])
+ for (k in n:nx) y[k] <- mean(x[(k-n+1):k])
+ } else if (type == "t") { # triangular
+ n <- ceiling((n + 1)/2)
+ s <- movavg(x, n, "s")
+ y <- movavg(s, n, "s")
+ } else if (type == "w") { # weighted
+ for (k in 1:(n-1)) y[k] <- 2 * sum((k:1)*x[k:1]) / (k*(k+1))
+ for (k in n:nx) y[k] <- 2 * sum((n:1)*x[k:(k-n+1)]) / (n*(n+1))
+ } else if (type == "m") { # modified
+ y[1] <- x[1]
+ for (k in 2:nx) y[k] <- y[k-1] + (x[k] - y[k-1])/n
+ } else if (type == "e") { # exponential
+ a <- 2/(n+1)
+ y[1] <- x[1]
+ for (k in 2:nx) y[k] <- a*x[k] + (1-a)*y[k-1]
+ } else if (type == "r") { # running
+ a <- 1/n
+ y[1] <- x[1]
+ for (k in 2:nx) y[k] <- a*x[k] + (1-a)*y[k-1]
+ } else
+ stop("The type must be one of 's', 't', 'w', 'm', 'e', or 'r'.")
+ return(y)
+ }
> library(readxl)
> BikeDemand <- read_excel("C:/Users/16092/Desktop/CitiBike_Oct2016_BikeDemand.xlsx",
+ range = "A1:G505")
> View(BikeDemand)
> plot(BikeDemand, type = "l", col = 1, ylim = c(0, 35), main = "Types of moving averages", sub = "Oct 3 2016--Oct 23 2016", xlab = "Hours", ylab = "Bike Usage/Demand")

Error in plot.default(...) :
formal argument "type" matched by multiple actual arguments

0 0
Add a comment Improve this question Transcribed image text
Answer #1

You are passing a data.frame to plot function which is not a correct way. You must think about

  • What should be on the x axis
  • What should be on the y axis

I would suggest you read the arguments of plot function in R and read some scripts/codes for time series.

Add a comment
Know the answer?
Add Answer to:
I am trying to plot a time series model using R. So far I have the...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • I have spent so much time on this and I am having trouble getting all the...

    I have spent so much time on this and I am having trouble getting all the methods to work together correctly to run the code right, and I am not sure what is wrong with it. /* You will recreate one or two versions of the logic game shown in the Algorithms movie and you will ask which one the user would like to play. Upon completion of the game, display who won and ask if they would like to...

  • Here is the code I have so far. I'm trying to figure out how to implement...

    Here is the code I have so far. I'm trying to figure out how to implement a boolean and use precedence. The 2nd expression should be 14 but it comes out as 28 so I'm definitely not understanding. #include <stack> #include <iostream> #include <string> using namespace std; // Function to find precedence of // operators. int precedence(char op) {    if (op == '+' || op == '-')        return 1;    if (op == '*' || op ==...

  • I am trying to create a function to read 2 csv files that contain 5 columns...

    I am trying to create a function to read 2 csv files that contain 5 columns of data. Columns 1-4 are floats and column 5 is a string. I want to only work on with the floats to perform some calculations such as sum of the first 2 columns of each file and then return the closest numbers then return the string to identify the 2 rows of data. Below is what I have so far. There is a stipulation...

  • This is what I have so far 31. Solow model modification. Consider an economy with the...

    This is what I have so far 31. Solow model modification. Consider an economy with the production function y = Vk where n=0.03, and 8 =0.07. The only missing part for our model is s which we generally have assumed is fixed and exogenous. i. Calculate the steady state level of capital per effective worker if s = 0.2. k* = It is unrealistic to assume that saving is a fixed percentage of income regardless of the circumstances so let's...

  • I am getting an error in R and am unsure how to correct it. I am getting an error from the r2 line, "Error in xc[1:(...

    I am getting an error in R and am unsure how to correct it. I am getting an error from the r2 line, "Error in xc[1:(n - 2)] : only 0's may be mixed with negative subscripts." tmpFn <- function(xVec) { xc <- xVec - mean(xVec) denom <- sum(xc^2) n <- length(x) r1 <- sum( xc[2:n] * xc[1:(n-1)] )/denom r2 <- sum( xc[3:n] * xc[1:(n-2)] )/denom list(r1 = r1, r2 = r2) } tmpFn(seq(2, 56, 3)) 10. (a) Given a...

  • Hello, I am having trouble with part c of this question. Here is my work so far: The solution for part c states that a...

    Hello, I am having trouble with part c of this question. Here is my work so far: The solution for part c states that a possible solution is (e^16 * 4^3) / 3! I am having trouble understanding how they got e^16 or why they decided to use e^(4^2) for M in the equation |f(x) - Tn(x)| <= (M / (n + 1)!) * |x - 0|^(n + 1). From my understanding, I have to maximize H^3(x) (i.e. 3rd derivative...

  • I am trying to make it so that radio buttons when clicked execute a javascript file....

    I am trying to make it so that radio buttons when clicked execute a javascript file. I have to to have the exercises in external files. Here is what I have so far. I am reusing a script that was used to make radio buttons switch CSS files so I think I have to change the set attribute options. HTML <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>Document</title> </head> <body> <p> 4.2 Output: The first 20 Fibonacci numbers, which are...

  • Please help. I'm stuck. Also, is what I have so far right? Quiz 4 Bonus 2...

    Please help. I'm stuck. Also, is what I have so far right? Quiz 4 Bonus 2 [12 % points] You have a spring whose relaxed length is L with stiffness k. You attach one end to the ceiling and hang a block of mass m from the bottom end. Next you pull rapidly downward on the block and release the block when the length of the spring is Li, and the block has a downward sneed of v. A short...

  • Heres what I have so far: /* Preprocessor directives */ #include <stdio.h> #include <math.h> #define pi...

    Heres what I have so far: /* Preprocessor directives */ #include <stdio.h> #include <math.h> #define pi 3.14159 #define inputfile "c:\\engr 200\\oil_explore.txt" #define outputfile "c:\\engr 200\\oil_report.txt" /* Main function */ int main(void) { /* Declare variables */ double ratio, depth, ideal_charge, length, weight, number_sticks, wellsite; int i; FILE *explore, *report;    /* Open input file */ explore = fopen(inputfile,"r"); report = fopen(outputfile,"w"); /* Verify input file */ if(explore == NULL) { printf("\n\nERROR OPENING INPUT FILE\n\nPROGRAM TERMINATED\n\n"); return 0; } /* Read...

  • I am currently using eclipse to write in java. A snapshot of the output would be...

    I am currently using eclipse to write in java. A snapshot of the output would be greatly appreciated to verify that the program is indeed working. Thanks in advance for both your time and effort. Here is the previous exercise code: /////////////////////////////////////////////////////Main /******************************************* * Week 5 lab - exercise 1 and exercise 2: * * ArrayList class with search algorithms * ********************************************/ import java.util.*; /** * Class to test sequential search, sorted search, and binary search algorithms * implemented in...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT