SERIE TEMPORALE MOTORCYCLES 2000-2010 Percorso e preparazione cartelle
Eurostat, Statistics Database, Database by themes, Industry, trade and services, Short-term business statistics (sts), Industry (NACE Rev.2) (sts_ind), Industry production index (NACE Rev.2) (sts_ind_prod), Industry production index - monthly data - (2005=100) (NACE Rev.2) (sts_inpr_m), select data: Italy, Nace R2:
C3091 Manufacture of motorcycles;; dal 2000 ad oggi (2010 mese 9);; update, view table, sort ascending.
Download come file Excel, copiata la pagina su proprio file “motorcycles.xls” foglio 1. Creata cartella Lezione 12 con file word o simile, file motorcycles.xls, file Lezione12.RData. Caricare stringa dati (motorcycles relativi a Italia) in R con Mot <- scan("clipboard",dec=',') e trasformarla in M1 col comando M1 <- ts(Mot, frequency=12, start=c(2000,1)). Verificare con plot(M1). Il grafico si può vedere sotto, in occasione di Holt-Winters. Salvare per il futuro.
Analisi dati
M1.dec <- decompose(M1);; plot(M1.dec) o meglio:
M1
.stl <- stl(
M1, 6)
;; plot(M1.stl) (I residui recenti sono piccoli)acf(M1,30)
conferma l’elevata periodicità annuale. Eseguiamo due analisi/predizioni, con metodi AR e con Holt-Winters. La più banale da eseguire è Holt-Winters:
HW<-HoltWinters(M1) pred<-predict(HW,24) ts.plot(M1, pred, lty=c(3,1))
Smoothing parameters:
alpha: 0.4382169 beta : 0.04056454 gamma: 0.6822595
Esaminiamo gli AR:
ar.ols.best <- ar.ols(M1);; ar.ols.best
Coefficients:
1 2 3 4 5 6 7 8
0.4602 0.0559 0.1837 -0.1149 -0.0426 0.0210 -0.0556 0.1047 9 10 11 12 13 14 15 16
-0.0392 -0.0002 -0.0152 0.9128 -0.4464 -0.0418 -0.2130 0.1038 17 18 19 20 21
0.0275 -0.0602 0.0558 -0.1072 0.0113 Intercept: -0.2939 (1.241)
Order selected 21 sigma^2 estimated as 156.4
Ovviamente 21 è eccessivo ed abbiamo capito che 12 è rilevante. Esaminiamo l’indice AIC:
plot(0:(length(ar.ols(M1)$aic)-1),ar.ols(M1)$aic)
Chiaramente 12 contiene un miglioramento drastico, mentre i raffinamenti ulteriori possono essere trascurati a vantaggio dell’economicità del modello. Comunque per semplicità usiamo tutto:
pred <- predict(ar.ols.best, n.ahead=24) ;; ts.plot(M1, pred$pred, lty=c(3,1))