Concetti Chiave

  • Il contenuto descrive l'uso di diversi pacchetti R, come "tseries" e "ast", per l'analisi delle serie storiche, tra cui funzioni per il caricamento dati e l'analisi preliminare.
  • Viene spiegato come effettuare l'analisi grafica e la decomposizione delle serie storiche tramite metodi come il filtraggio, la differenziazione e il livellamento.
  • Il testo illustra vari metodi di decomposizione delle serie storiche, inclusi STL e TSR, al fine di identificare trend e componenti stagionali.
  • Viene trattata la verifica statistica delle serie storiche, compresi test di normalità come il test di Shapiro e l'analisi dell'autocorrelazione dei residui.
  • Il contenuto include la simulazione e stima di modelli stocastici, come AR, MA e ARIMA, per comprendere meglio le dinamiche delle serie storiche.

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)

Domande da interrogazione

  1. Quali pacchetti sono necessari per l'analisi delle serie storiche nel testo?
  2. Il testo menziona l'uso dei pacchetti "tseries" e "ast" per l'analisi delle serie storiche, che includono funzioni per la stima del trend, la decomposizione e la simulazione di processi stocastici.

  3. Come viene stimato il trend di una serie storica secondo il testo?
  4. Il trend di una serie storica viene stimato utilizzando il filtraggio con media mobile, il livellamento e la decomposizione con metodi come STL e TSR, che permettono di isolare il trend dai dati grezzi.

  5. Quali test vengono utilizzati per verificare le proprietà dei residui?
  6. Il testo descrive l'uso del test di Shapiro per la normalità e l'analisi dell'autocorrelazione tramite correlogrammi per verificare le proprietà dei residui delle serie storiche.

Domande e risposte

Hai bisogno di aiuto?
Chiedi alla community