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:
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?
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With