Funzioni di riferimento
CARICAMENTO PACCHETTO
"library(tseries)"CARICAMENTO DATIxindice[math]in diceANALISI PRELIMINAREmax(indice)min(indice)mean(indice)var(indice)length(indice)RICONOSCIMENTO SERIE STORICAxtis.ts(xt)xtANALISI GRAFICAplot(xt,ylab=\text{importazioni di eegia},xlab=\text{tempo},main=\text{GRAFICO DELLA SERIE STORICA},lwd=1,lty=1,col=\text{red})hist(indice,prob=TRUE,col=\text{yellow})CARICAMENTO PACCHETTO AST\text{library(ast)}STIMA DEL TREND CON IL FILTRAGGIOxt.filtxt.filtplot(xt.filt,main=\text{TREND STIMATO CON MEDIA MOBILE},col=\text{green})SCOMPOSIZIONE MEDIANTE DIFFERENZIAZIONExt.diffxt.diffplot(xt.diff,main=\text{GRAFICO DELLA SERIE STORICA DETRENDIZZATA},col=\text{brown})xt.diff2plot(xt.diff2,main=\text{GRAFICA DELLA SERIE STORICA DETRENDIZZATA 2},col=\text{brown})STIMA DEL TREND CON IL LIVELLAMENTOxt.hwxt.hwplot(xt.hw)prevprevDECOMPOSIZIONE DELLA SERIE STORICA CON DECdec.fitstag.decseasonaltrend.dec[math]trendres.decrandomplot(dec.fit)DECOMPOSIZIONE DELLA SERIE STORICA CON STLstl.fitattributes(stl.fit)stag.stl[math]time.series[,1]trend.stltime.series[,2]res.stlplot(stl.fit,main="GRAFICO DELLA SERIE STORICA DECOMPOSTA- funzione stl")DECOMPOSIZIONE DELLA SERIE STORICA CON TSRlibrary(ast)tsr.fitplot(tsr.fit)plot(xt.filt)lines(trend(tsr.fit),col="red")tsr2.fitplot(tsr2.fit)plot(xt.filt)lines(trend(tsr2.fit),col="blue")plot(trend(tsr2.fit),main="COMPARAZIONE DEL TREND STIMATO")lines(xt.filt,col="red")lines(trend.stl,col="green")trend.tsrstag.tsrres.tsrLISCIAMENTO DELLA SERIE STORICAplot(xt,main="LISCIAMENTO DELLA SERIE STORICA")lines(smoothts(xt~lo(2,10)),col="red")lines(smoothts(xt~s(2)),col="blue")lines(smoothts(xt~p(2)),col="black")VERIFICA SUL VALORE DELLA MEDIA DEGLI ERRORImedia.residuimedia.residuinnvar.residuivar.residuisstesttest.tpt(test.t,n-1,lower.tail=F)qt(0.99,n-1)VERIFICA DELLA NORMALITA'stands=(var(x)^0.5)z=(x-m)/sreturn(z)}res.standres.standplot(res.stand,main="DIAGRAMMA DEI RESIDUI STANDARDIZZATI")abline(h=2.5)hist(res.stand,main="ISTOGRAMMA DEI RESIDUI STANDARDIZZATI",xlab="Residui",col="green")plot(density(res.stand,kernel="gaussian"),main="Distribuzione dei residui:lisciamento",col="green")TEST DI SHAPIRO shapiro.test(res.stand)TEST DI AUTOCORRELAZIONEacf(res.stand,main="Correlogramma dei residui",col="red")
PROCESSO STOCASTICO
mean(res.stl)var(res.stl)acf(res.stl,type="correlation",plot=TRUE,main="CORRELOGRAMMA DELLA SERIE DEI RESIDUI",col="violet")acf(res.stl,type="covariance",plot=TRUE,main="GRAFICO DELLE AUTOCOVARIANZE",col="orange")acf(res.stl,type="correlation",plot=FALSE)pacf(res.stl,plot=TRUE,main="GRAFICO DELLE CORRELAZIONI PARZIALI",col="green")pacf(res.stl,plot=FALSE)
ALCUNI MODELLI STOCASTICI
1) ARar1ar1plot(ar1,main="SIMULAZIONE DI UN PROCESSO AR(1)",col="blue")ar11
ar11plot(ar11,main="SIMULAZIONE DI UN PROCESSO AR(1)",col="brown")abline(h=2.5)abline(h=-2.5)ar2
ar2plot(ar2,main="SIMULAZIONE DI UN PROCESSO AR(2)")ar22
ar22plot(ar22,main="SIMULAZIONE DI UN PROCESSO AR(2)")abline(h=0.15)abline(h=-0.15)2) MA
ma1ma1plot(ma1,main="SIMULAZIONE DI UN PROCESSO MA(1)",col="yellow")ma2
ma2plot(ma2,main="SIMULAZIONE DI UN PROCESSO MA(2)",col="green")3) ARIMA
arima1plot(arima1,main="SIMULAZIONE DI UN PROCESSO ARIMA(1,1,1)",col="red")
STIMA DEI PARAMETRI
1)ar1fitar1fittsdiag(ar1fit)ar22fitar22fittsdiag(ar22fit)2)
fitma1fitma1tsdiag(fitma1)3)
arimafitarimafittsdiag(arimafit)