library(TSA) # generate the random walk # generate the noise (innovations) set.seed(12791) mu=0.1 sd=1 n=5000 e=rnorm(n=n,mean=mu,sd=sd) # time plot of the innovations plot(e,type='b') plot(e,type='o') abline(h=0,col='blue') y=cumsum(e) plot(y,type='o');abline(h=0,col='blue') # moving average process of order 1 # MA(1) process set.seed(12791) mu=0 sd=1 n=500 theta=0.5 e=rnorm(n=n+1,mean=mu,sd=sd) y=rep(NA,n) for (t in 1:n) y[t]=e[t+1]-theta*e[t] plot(y,type='o');abline(h=0,col='blue') plot(y=y,x=zlag(y))