$$ previsione con smorzamento esponenziale semplice di un white noise x <- 1:30 y.stat <- rnorm(x) ts.plot(y.stat) p.stat <- HoltWinters(y.stat, gamma=0, beta=0) plot(p.stat) p.stat p.stat.07 <- HoltWinters(y.stat, gamma=0, beta=0, alpha=0.7) plot(p.stat.07) -------------------------- $$ controllo a mano che p.stat è meglio di p.stat.07 res.stat <- as.ts(abs(y.stat[2:length(y.stat)]-p.stat$fitted[,1])) res.stat.07 <- as.ts(abs(y.stat[2:length(y.stat)]-p.stat.07$fitted[,1])) ts.plot(res.stat,res.stat.07,col = c("red","blue")) res.stat <- abs(y.stat[2:length(y.stat)]-p.stat$fitted[,1]) res.stat.07 <- abs(y.stat[2:length(y.stat)]-p.stat.07$fitted[,1]) plot(res.stat) points(res.stat.07,col = "red") plot(res.stat.07-res.stat) abline(0,0) ---------------------------- $$ previsione con smorzamento esponenziale semplice di un white noise con trend y.trend <- x+y.stat ts.plot(y.trend) p.trend <- HoltWinters(y.trend, gamma=0, beta=0) plot(p.trend) p.trend p.trend.02 <- HoltWinters(y.trend, gamma=0, beta=0, alpha=0.2) plot(p.trend.02) ----------------------------- p.vero.trend <- HoltWinters(y.trend, gamma=0) plot(p.vero.trend) p.vero.trend ----------------------------- F <- c(0,2,3,0,-3,-2) F.5<-c(F,F,F,F,F) ts.plot(F.5) y.per <- y.trend+F.5 ts.plot(y.per) p.per.0 <- HoltWinters(y.per) $$ non funziona! la soluzione è piuttosto difficile: plot(co2) co2.W<-HoltWinters(co2) plot(co2.W) $$ questa funziona. Cosa manca? La dichiarazione della "frequenza" nella serie temporale: y.per.new<-ts(data = y.per, frequency = 6) p.per <- HoltWinters(y.per.new) plot(p.per) $$ funziona! Quindi in pratica il periodo di Winters lo stiamo fissando noi. dec<-decompose(y.per.new) plot(dec) $$ Predizione valori futuri: p <- predict(p.per, 12, prediction.interval = TRUE) plot(p.per,p)