runnig

MA(1) Model

Jan 19th, 2016
257
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
R 0.76 KB | None | 0 0
  1. set.seed(123);
  2. # Simulate 250 observations from the described MA(1) model
  3. ma1_sim <- arima.sim(model=list(ma=0.5), n=250, mean=0, sd=0.1) + 0.05;
  4. # Generate the theoretical ACF with upto lag 10
  5. acf_ma1_model <- ARMAacf(ar=0, ma=0.5, lag.max=10)
  6.  
  7. # Split plotting window in three rows
  8. par(mfrow=c(3,1))
  9.  
  10. # First plot: The simulated observations
  11. plot(ma1_sim, type="l",main="MA(1) Process: mu=0.05, theta=0.5",xlab="time",ylab="y(t)")
  12. abline(h=0)
  13.  
  14. # Second plot: Theoretical ACF
  15. plot(1:10, acf_ma1_model[2:11], type="h", col="blue",  ylab="ACF", main="theoretical ACF")
  16.  
  17. # Third plot: Sample ACF
  18. # Assign to tmp the Sample ACF
  19. tmp <- acf(ma1_sim, lag.max=10)
  20. plot(acf_ma1_model, main="Sample ACF")
  21.  
  22. # Reset graphical window to only one graph
  23. par(mfrow=c(1,1))
Advertisement
Add Comment
Please, Sign In to add comment