Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
541 views
in Technique[技术] by (71.8m points)

r - Simulate an AR(1) process with uniform innovations

I need to plot an AR(1) graph for the process

y[k] = 0.75 * y[k-1] + e[k] for y0 = 1. 

Assume that e[k] is uniformly distributed on the interval [-0.5, 0.5].

I am trying to use arima.sim:

library(tseries)
y.0 <- arima.sim(model=list(ar=.75), n=100)
plot(y.0)

It does not seem correct. Also, what parameters do I change if y[0] = 10?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

We want to use R base function arima.sim for this task, and no extra libraries are required.

By default, arima.sim generates ARIMA with innovations ~ N(0,1). If we want to change this, we need to control the rand.gen or innov argument. For example, you want innovations from uniform distributions U[-0.5, 0.5], we can do either of the following:

arima.sim(model=list(ar=.75), n=100, rand.gen = runif, min = -0.5, max = 0.5)

arima.sim(model=list(ar=.75), n = 100, innov = runif(100, -0.5, 0.5))

Example

set.seed(0)
y <- arima.sim(model=list(ar=.75), n = 100, innov = runif(100, -0.5, 0.5))
ts.plot(y)

enter image description here


In case we want to have explicit control on y[0], we can just shift the above time series such that it starts from y[0]. Suppose y0 is our desired starting value, we can do

y <- y - y[1] + y0

For example, starting from y0 = 1:

y <- y - y[1] + 1
ts.plot(y)

enter image description here


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...