SHARE
TWEET

Untitled

a guest Mar 20th, 2017 54 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. > kt
  2.  [1] 16.63292944 17.10746185 16.03326222 16.24631736 14.67784276
  3.  [6] 14.54126450 14.12032640 14.08797796 13.69164459 13.32990466
  4. [11] 13.15672641 12.57994701 12.50856702 12.49292845 11.91980041
  5. [16] 11.84854379 11.69906707 11.27068958 11.46658995 11.07480840
  6. [21] 11.71810389 10.24234202  9.98624154  9.69563628  8.77524312
  7. [26]  8.42607407  8.03839654  7.46459155  6.90364116  6.46802360
  8. [31]  6.18895143  5.66047744  5.06493622  4.87223437  4.47053611
  9. [36]  4.31558216  3.80968168  3.54183060  3.32698878  3.01142929
  10. [41]  2.61087797  2.16596582  1.84685422  1.73129589  1.44568725
  11. [46]  1.38868046  1.05136432  0.65361666  0.31751012 -0.06360237
  12. [51] -0.56454474 -0.78109888 -0.82625274 -0.81258738 -1.01088682
  13. [56] -0.83005175 -1.05284966 -0.88126429 -0.88002998 -0.73160603
  14. [61] -0.73800657 -0.82408653 -0.84909859 -0.86868214 -0.82202275
  15. [66] -0.67518149
  16.    
  17. > ktF.fit <- auto.arima(kt, d=1, trace=T)
  18.    
  19. ktF.for <- forecast(ktF.fit,h=horizonte,level=c(95))
  20.    
  21. set.seed(1)
  22. ktF.coef <- rmvnorm(nsimul, ktF.fit$coef, ktF.fit$var.coef, method="chol")
  23.    
  24. set.seed(1)
  25. NkF <- (horizonte+2)*nsimul
  26. normalkF <- matrix(rnorm(NkF,0,sqrt(ktF.fit$sigma2)),(horizonte+2),nsimul)
  27.    
  28. ktF <- matrix(NA,(horizonte+4),nsimul)
  29.  
  30. ktF[1,] <- ktF.fit$x[tiempo-2]
  31. ktF[2,] <- ktF.fit$x[tiempo-1]
  32. ktF[3,] <- ktF.fit$x[tiempo]
  33.    
  34. for(i in 4:(horizonte+4)){
  35.   for(j in 1:nsimul){
  36.     ktF[i,j] <- ktF[i-1,j] +
  37.       ktF.coef[j,4]*(1-ktF.coef[j,1]-ktF.coef[j,2]) + #drift
  38.       ktF.coef[j,1]*(ktF[i-1,j]-ktF[i-2,j]) + #Ar(1)
  39.       ktF.coef[j,2]*(ktF[i-2,j]-ktF[i-3,j]) + #Ar(2)
  40.       normalkF[i-2,j] +
  41.       ktF.coef[j,3]*normalkF[i-3,j] #MA(1)
  42.   }
  43. }
  44.  
  45. ktF1<-ktF[4:(horizonte+4),1:nsimul]
  46.    
  47. ic.ktF<-matrix(NA,(horizonte+1),3)
  48. for(i in 1:(horizonte+1)){
  49.   ic.ktF[i,]<-quantile(ktF1[i,],probs=c(0.025,0.5,0.975),
  50.                        type = 8,names=FALSE,na.rm=T)
  51. }
RAW Paste Data
Top