_fanciullo
(0 punti)
4' di lettura

Funzioni di riferimento

CARICAMENTO PACCHETTO

"library(tseries)"

CARICAMENTO DATI

xindice[math]in dice

ANALISI PRELIMINARE

max(indice)

min(indice)

mean(indice)

var(indice)

length(indice)

RICONOSCIMENTO SERIE STORICA

xtis.ts(xt)

xt

ANALISI GRAFICA

plot(xt,ylab=\text{importazioni di e
egia},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 FILTRAGGIO

xt.filtxt.filt

plot(xt.filt,main=\text{TREND STIMATO CON MEDIA MOBILE},col=\text{green})

SCOMPOSIZIONE MEDIANTE DIFFERENZIAZIONE

xt.diffxt.diff

plot(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 LIVELLAMENTO

xt.hwxt.hw

plot(xt.hw)

prevprev

DECOMPOSIZIONE DELLA SERIE STORICA CON DEC

dec.fitstag.decseasonal

trend.dec[math]trend

res.decrandom

plot(dec.fit)

DECOMPOSIZIONE DELLA SERIE STORICA CON STL

stl.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 TSR

library(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.tsr

LISCIAMENTO DELLA SERIE STORICA

plot(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 ERRORI

media.residuimedia.residui

nn

var.residuivar.residui

ss

testtest.t

pt(test.t,n-1,lower.tail=F)

qt(0.99,n-1)

VERIFICA DELLA NORMALITA'

stands=(var(x)^0.5)

z=(x-m)/s

return(z)}

res.standres.stand

plot(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 AUTOCORRELAZIONE

acf(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) AR

ar1ar1

plot(ar1,main="SIMULAZIONE DI UN PROCESSO AR(1)",col="blue")

ar11

ar11

plot(ar11,main="SIMULAZIONE DI UN PROCESSO AR(1)",col="brown")

abline(h=2.5)

abline(h=-2.5)

ar2

ar2

plot(ar2,main="SIMULAZIONE DI UN PROCESSO AR(2)")

ar22

ar22

plot(ar22,main="SIMULAZIONE DI UN PROCESSO AR(2)")

abline(h=0.15)

abline(h=-0.15)

2) MA

ma1ma1

plot(ma1,main="SIMULAZIONE DI UN PROCESSO MA(1)",col="yellow")

ma2

ma2

plot(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)

ar1fitar1fit

tsdiag(ar1fit)

ar22fitar22fit

tsdiag(ar22fit)

2)

fitma1fitma1

tsdiag(fitma1)

3)

arimafitarimafit

tsdiag(arimafit)