Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Use arima.sim to simulate ARIMA 1,1,1 with drift in R

I am trying to use ARIMA sim package to simulate an ARIMA simulation with a drift. My problem is that I cannot seem to get it to work.

I need to get something like this:

enter image description here

My code is producing this though:

> mean(datatime)
[1] 15881.56
> sd(datatime)
[1] 8726.893
> length(datatime)
[1] 123

# The mean and variance from the original series

originalseriesmean = 15881.56
originalseriesvariance = 8726.893*8726.893
originalseriesn=123

# Simulation using arima.sim



ts.sim <- arima.sim(model=list(c(1,1,1)), n = 123, mean=190,sd=69.2863)

ts.plot(ts.sim)


[ How do I add a drft term to this function to make it look like the simulation before?

like image 768
Timothy Mash Avatar asked Nov 14 '22 20:11

Timothy Mash


1 Answers

ARIMA process doesn't have any drift/trend by definition. Inspired by this answer on cross validated arima with trend and taking into consideration the value you want:

set.seed(123)
intercept <- 4500
b <- (32000 - intercept) / 123
x <- 1:123
y <- b * x + arima.sim(model=list(c(1, 0, 1)),
                    n = 123, mean=intercept, sd=2000)


> sd(y)
[1] 8020
> mean(y)
[1] 18370

The argument mean gives you the intercept of the process (where it starts), to obtain the variance you should detrend your process because the mean value and the sd values you give are with trend wherease to simulate such process you should decompose your process into noise + trend.

like image 137
Rémi Coulaud Avatar answered Dec 21 '22 08:12

Rémi Coulaud