How to do it...

In this recipe, we will generate two ARIMA models, (0,1,0) and (1,0,0), and we will see how to work with them:

  1. We first create a function that will generate the time series. It will receive a parameter that will govern the AR coefficient:
set.seed(95) build_series = function(coef){ start_value = 90 values = c(start_value) previous_value = values for (x in 1:200){ current_value  = coef*previous_value + rnorm(1,0,10) values = c(values,current_value) previous_value = current_value}return (values)} 
  1. We now generate three time series with an AR coefficient = 1. We then plot the three of them, and interestingly, they all behave very differently. This is explained by the fact that the three of them are non-stationary (the AR coefficient ...

Get R Statistics Cookbook now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.