Les notes de cours sont disponibles ici.

Simulation d’un modèle ARMA(2,1)

y <- arima.sim(model = list(ar = c(0.9, -0.2), ma = 0.8), rand.gen=rnorm, sd = sqrt(0.1), n = 10000)
plot.ts(y)

Estimation des fonctions d’autocovariance et d’autocovariance partielle

y_s_acf <- acf(y, type="correlation", lag.max=21)

y_s_pacf <- acf(y, type="partial", lag.max=21)

Comparaison avec les moments théoriques

require(ggplot2)


y_acf <- ARMAacf(ar=c(0.9, -0.2), ma=0.8, lag.max=21)

h = seq(0,21,1)
theoretical_acf = array(y_acf)
simulated_acf = y_s_acf$acf

df <- data.frame(h,theoretical_acf,simulated_acf)

g <- ggplot(df, aes(h))
g <- g + geom_point(aes(y=theoretical_acf), colour="red")
g <- g + geom_point(aes(y=simulated_acf), colour="black")
g <- g + labs(y = "Autocorrelation")
g


y_pacf <- ARMAacf(ar=c(0.9, -0.2), ma=0.8, lag.max=21, pacf=TRUE)

h = seq(1,21,1)
theoretical_pacf = array(y_pacf)
simulated_pacf = y_s_pacf$acf

df <- data.frame(h,theoretical_pacf,simulated_pacf)

g <- ggplot(df, aes(h))
g <- g + geom_point(aes(y=theoretical_pacf), colour="red")
g <- g + geom_point(aes(y=simulated_pacf), colour="black")
g <- g + labs(y = "Partial autocorrelation")
g <- g +theme(legend.position="bottom")
g

Estimation de modèles ARMA

y <- arima.sim(model = list(ar = c(0.9, -0.2), ma = 0.8), rand.gen=rnorm, sd = sqrt(0.1), n = 500)
arma10 <- arima(y, order = c(1, 0, 0), include.mean = FALSE)
arma20 <- arima(y, order = c(2, 0, 0), include.mean = FALSE)
arma30 <- arima(y, order = c(3, 0, 0), include.mean = FALSE)
arma40 <- arima(y, order = c(4, 0, 0), include.mean = FALSE)
arma50 <- arima(y, order = c(5, 0, 0), include.mean = FALSE)
arma11 <- arima(y, order = c(1, 0, 1), include.mean = FALSE)
arma21 <- arima(y, order = c(2, 0, 1), include.mean = FALSE)
arma31 <- arima(y, order = c(3, 0, 1), include.mean = FALSE)
arma41 <- arima(y, order = c(4, 0, 1), include.mean = FALSE)
arma51 <- arima(y, order = c(5, 0, 1), include.mean = FALSE)
arma12 <- arima(y, order = c(1, 0, 2), include.mean = FALSE)
arma22 <- arima(y, order = c(2, 0, 2), include.mean = FALSE)
arma32 <- arima(y, order = c(3, 0, 2), include.mean = FALSE)
arma42 <- arima(y, order = c(4, 0, 2), include.mean = FALSE)
arma52 <- arima(y, order = c(5, 0, 2), include.mean = FALSE)
arma13 <- arima(y, order = c(1, 0, 3), include.mean = FALSE)
arma23 <- arima(y, order = c(2, 0, 3), include.mean = FALSE)
arma33 <- arima(y, order = c(3, 0, 3), include.mean = FALSE)
arma43 <- arima(y, order = c(4, 0, 3), include.mean = FALSE)
arma53 <- arima(y, order = c(5, 0, 3), include.mean = FALSE)
arma14 <- arima(y, order = c(1, 0, 4), include.mean = FALSE)
arma24 <- arima(y, order = c(2, 0, 4), include.mean = FALSE)
arma34 <- arima(y, order = c(3, 0, 4), include.mean = FALSE)
problème de convergence possible : optim renvoie un code = 1
arma44 <- arima(y, order = c(4, 0, 4), include.mean = FALSE)
arma54 <- arima(y, order = c(5, 0, 4), include.mean = FALSE)
arma15 <- arima(y, order = c(1, 0, 5), include.mean = FALSE)
arma25 <- arima(y, order = c(2, 0, 5), include.mean = FALSE)
arma35 <- arima(y, order = c(3, 0, 5), include.mean = FALSE)
arma45 <- arima(y, order = c(4, 0, 5), include.mean = FALSE)
arma55 <- arima(y, order = c(5, 0, 5), include.mean = FALSE)
arma01 <- arima(y, order = c(0, 0, 1), include.mean = FALSE)
arma02 <- arima(y, order = c(0, 0, 2), include.mean = FALSE)
arma03 <- arima(y, order = c(0, 0, 3), include.mean = FALSE)
arma04 <- arima(y, order = c(0, 0, 4), include.mean = FALSE)
arma05 <- arima(y, order = c(0, 0, 5), include.mean = FALSE)
aic <- AIC(arma01,arma02,arma03,arma04,arma05,
    arma11,arma12,arma13,arma14,arma15,
    arma21,arma22,arma23,arma24,arma25,
    arma31,arma32,arma33,arma34,arma35,
    arma41,arma42,arma43,arma44,arma45,
    arma51,arma52,arma53,arma54,arma55)
bic <- BIC(arma01,arma02,arma03,arma04,arma05,
    arma11,arma12,arma13,arma14,arma15,
    arma21,arma22,arma23,arma24,arma25,
    arma31,arma32,arma33,arma34,arma35,
    arma41,arma42,arma43,arma44,arma45,
    arma51,arma52,arma53,arma54,arma55)


aic[which(aic$AIC==min(aic$AIC)),]
bic[which(bic$BIC==min(bic$BIC)),]
arma21

Call:
arima(x = y, order = c(2, 0, 1), include.mean = FALSE)

Coefficients:
         ar1      ar2     ma1
      0.8226  -0.1991  0.8303
s.e.  0.0538   0.0533  0.0372

sigma^2 estimated as 0.09296:  log likelihood = -117.12,  aic = 242.24
LS0tCnRpdGxlOiAiYXJtYS1lc3RpbWF0aW9uIgpvdXRwdXQ6CiAgaHRtbF9ub3RlYm9vazogbnVsbAogIGh0bWxfZG9jdW1lbnQ6CiAgICBkZl9wcmludDogcGFnZWQKLS0tCgpMZXMgbm90ZXMgZGUgY291cnMgc29udCBkaXNwb25pYmxlcyBbaWNpXShodHRwczovL2xlLW1hbnMuYWRqZW1pYW4uZXUvcyVDMyVBOXJpZXMtdGVtcG9yZWxsZXMvZXN0aW1hdGlvbi1hcm1hL0VzdGltYXRpb24lMjBkZXMlMjBtb2QlQzMlQThsZXMlMjBBUk1BLnBkZikuCgojIyBTaW11bGF0aW9uIGQndW4gbW9kw6hsZSBBUk1BKDIsMSkKCmBgYHtyfQp5IDwtIGFyaW1hLnNpbShtb2RlbCA9IGxpc3QoYXIgPSBjKDAuOSwgLTAuMiksIG1hID0gMC44KSwgcmFuZC5nZW49cm5vcm0sIHNkID0gc3FydCgwLjEpLCBuID0gMTAwMDApCnBsb3QudHMoeSkKYGBgCiMjIEVzdGltYXRpb24gZGVzIGZvbmN0aW9ucyBkJ2F1dG9jb3ZhcmlhbmNlIGV0IGQnYXV0b2NvdmFyaWFuY2UgcGFydGllbGxlCgpgYGB7cn0KeV9zX2FjZiA8LSBhY2Yo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