diff --git a/DESCRIPTION b/DESCRIPTION old mode 100644 new mode 100755 index 0a8e647..ea4adaf --- a/DESCRIPTION +++ b/DESCRIPTION @@ -2,17 +2,17 @@ Package: caschrono Title: Sries Temporelles Avec R Description: Functions, data sets and exercises solutions for the book 'Séries Temporelles Avec R' (Yves Aragon, edp sciences, 2016). For all chapters, a vignette is available with some additional material and exercises solutions. Encoding: latin1 -Version: 2.2 -Date: 2020-05-12 +Version: 2.3 +Date: 2022-12-14 Author: Yves Aragon Maintainer: Thibault Laurent Depends: graphics, stats, utils, zoo Imports: Hmisc, methods -Suggests: dse, expsmooth, fBasics, FitARMA, fGarch, forecast, polynom, +Suggests: dse, expsmooth, fBasics, fGarch, forecast, polynom, timeSeries, xtable License: GPL (>= 2) URL: http://www.seriestemporelles.com NeedsCompilation: no -Packaged: 2020-05-12 15:35:06 UTC; thibault +Packaged: 2022-11-14 14:29:46 UTC; laurent Repository: CRAN -Date/Publication: 2020-05-12 16:20:07 UTC +Date/Publication: 2022-11-15 23:30:12 UTC diff --git a/MD5 b/MD5 index c481734..02ee13c 100644 --- a/MD5 +++ b/MD5 @@ -1,14 +1,14 @@ -8a048cddefe65c126f82431b6b3d06bb *DESCRIPTION +af1ecad93065741200e0aee25187f36e *DESCRIPTION 04203139f51701835ff7068006b21939 *NAMESPACE -ba974b797edd0f6e24cdd109217eba9a *R/Box.test.2.R -d581251d9e66e1d5b296679daf2e7c06 *R/acf2y.R -528a0502271fb8ccef1ded9061b4f78d *R/armaselect.r -02f48e0a3b853049d7cf8e6f59e82f00 *R/cor.arma.r -d90a2b266fea2cadc942e359ce0284b9 *R/plot2acf.R -65fd507185138da8f7a519dbbc1ee420 *R/plotacfthemp.r -7e2d62b29d77a09eb0ce96a1b85320fb *R/t_stat.r -5c517432dd91af0375b07ba802808913 *R/xy.acfb.r -460a6c0197c3500a74fb60dea2ede973 *build/vignette.rds +e19853957155e5207c9b3c26268b2f38 *R/Box.test.2.R +8b80fd7855d59e256b9c56b8f40745f5 *R/acf2y.R +f8928e92b06795a4e7fff82c2fdadb44 *R/armaselect.r +3aa7fd680ab11e6762b7496b15a8b39b *R/cor.arma.r +2d99d6107f2659327f5187787574ba9e *R/plot2acf.R +1c0d40ce7a311763eff9172800d3592b *R/plotacfthemp.r +d9645026a40125623d9a65f505e45fe3 *R/t_stat.r +87a4a72e4e55c68731269b72f3ccb3a8 *R/xy.acfb.r +8029401002eded9891a9cbec4fd00139 *build/vignette.rds b363921c7bc4712a5011ffb72e20b972 *data/champa.ts.rda 64754290d41ebb37b3a9f9df4242a759 *data/csdl.RData 421e6a66d19f1015af13c2ad641c3fb7 *data/essil.RData @@ -21,64 +21,65 @@ be4f5997433563911a3a032df25f5855 *data/indbourse.RData e0a1159418f157790ec04799738d3b71 *inst/CITATION 8dd686a282d25f557c710eb15829429a *inst/doc/Anx1.R 35778f533a50923f678dbc3d986e21fd *inst/doc/Anx1.Rnw -c8dd655654ff4d1c539845da67734e24 *inst/doc/Anx1.pdf +47c0a89a1fd3965c3efc6bf8b622f79c *inst/doc/Anx1.pdf 2f26ecf539bb9ad2a2e03d166aec097c *inst/doc/Anx10.R 5e716979e76cf558a31d63c340e5efeb *inst/doc/Anx10.Rnw -817bd61bcfa72a175836a9d13803b2e3 *inst/doc/Anx10.pdf -3f0a7a1fb13bde948c5713e6ac5d128d *inst/doc/Anx12.R -2e4e8a80faec39516bcde3d28c55b9c7 *inst/doc/Anx12.Rnw -131c6815c92133a42c6a47ff085284e2 *inst/doc/Anx12.pdf +7c41779b3dbf20f67c324e56994b9f70 *inst/doc/Anx10.pdf +992706c033da8e4098927b433d94e797 *inst/doc/Anx12.R +8cce130c635cc84b04dfd4dd50941e2b *inst/doc/Anx12.Rnw +4d4dc63782b43767ca30fe055e5d181c *inst/doc/Anx12.pdf ba25e603cd0acefe4cefa9a1ef68fa2e *inst/doc/Anx2.R 4ee09538f49a888360bae694856fb427 *inst/doc/Anx2.Rnw -30cc6453ba32807679c78cbd52465eb0 *inst/doc/Anx2.pdf +786d05f2ecebd3ba9b88579f5e057dfd *inst/doc/Anx2.pdf aff972d89fba2aa729a24e91fc2482f4 *inst/doc/Anx3.R 1230799fab19d4bdcc873e7ba2df77d3 *inst/doc/Anx3.Rnw -261ee85e5f53b34b3461d3e890f4bee6 *inst/doc/Anx3.pdf -2f376a5e75dcb550f17da5de08dd24de *inst/doc/Anx4.R -1419a5945249775dc79a3182968b7e8c *inst/doc/Anx4.Rnw -8d4d9c1e37d8f7a767246c5805609f87 *inst/doc/Anx4.pdf +dae39435c27853e019dd9dfe7f77aaee *inst/doc/Anx3.pdf +8137fc5d86b6f09f43ec5d030e02cfe1 *inst/doc/Anx4.R +2d946eafd7d7d69694ef1b70f9d9d5ec *inst/doc/Anx4.Rnw +4ba1ca569f2f9a9768beff5f6d553b3f *inst/doc/Anx4.pdf cd84360f99c151f362f6e3d1a74f5eeb *inst/doc/Anx5.R 06c2411350b8c4bdcfce2094465fd76d *inst/doc/Anx5.Rnw -9d2278681dfdf0f189fb2926aacfde10 *inst/doc/Anx5.pdf +c183de874c2604f5b59c923aed7b11d4 *inst/doc/Anx5.pdf 10507650700cb9c7c7894e3d7da21756 *inst/doc/Anx6.R 5674fee8a18aee982f21efb3bd54b4cd *inst/doc/Anx6.Rnw -f7fa468ec1b5f5be496ce585157596b3 *inst/doc/Anx6.pdf +e14a38380b200c8082edfd598a2cd614 *inst/doc/Anx6.pdf f349a01c70e55dfef6df1b02c0080622 *inst/doc/Anx7.R 90c6a3742945a3cbb762cc9a1e05421f *inst/doc/Anx7.Rnw -0db901cfec166e3fdaf0f15ecdb3c0c3 *inst/doc/Anx7.pdf +4550f295ed0d4fa21447061d718a7aff *inst/doc/Anx7.pdf d027e42272fee1b842ed72c1990aec7b *inst/doc/Anx9.R 78164a7cd351e7eeb18539c8a32aa95f *inst/doc/Anx9.Rnw -e3ccd177274fb1daa0528e09bd5ba160 *inst/doc/Anx9.pdf +84b28d305420bc8c588a8885c642661b *inst/doc/Anx9.pdf +92f98b394468a05ee4acf8328caff86f *inst/doc/sortie.pdf e811acbf5a09f59fafcf26e7554340d2 *inst/import/Tel_extrait.csv 1ec0c47722499bbe15ff264e5c4028c2 *inst/import/champagne_2001.txt 6b35efac7e40023f57c13b822ef49dc3 *inst/import/collecteLait.txt 011e245f497d8127159f7bf52dd6661c *inst/import/conselec.csv 545db1774c5247a5af56469ea8911445 *inst/import/trafquoti.txt -8e6f4cec33bd8c00b8b4d294cca02a8d *man/Box.test.2.rd -e286ec3c1c33c4a7220dbb8b12810c0f *man/Tel_extrait.Rd -3212333dcdaf44ea4d4ac47ca53b08ad *man/acf2y.rd +aa5edf6b3a7d5066994c8ebfe698e0a7 *man/Box.test.2.rd +d93523c1710159fbc2b7abb6d857f73b *man/Tel_extrait.Rd +e3e53c7884fa097b0b55adcc5992150d *man/acf2y.rd 42ab909eb5dd533be39dfb66fe75a5a8 *man/armaselect.rd -c5b935803086c2381b022a141c2a6e62 *man/caschrono-package.Rd -3e15ecbc47174b712c0938759fa3417c *man/champa.ts.Rd +320a5b01f396bb607972fe9c172bde5d *man/caschrono-package.Rd +4ffefcd66f455c39d18f677cb601cb30 *man/champa.ts.Rd 7e08e689f4d8aa0250d46f578471886d *man/cor.arma.rd -310f6fdeb7f9f591aa42b06858ba8b5b *man/csdl.rd +f334371387d83a9e4ad67879b4c98219 *man/csdl.rd 31e141ae11ab8bbd42ed4bad4a43c92f *man/essil.rd 84c9b8199f2177d7adccd7948183bdd6 *man/indbourse.rd -3d377cf2167d08358fb367fa3a9bee65 *man/khct.rd -b301f9859f101ccc256a16049db5a329 *man/lait.Rd -8dc037c581c2d91c360ddac8047638ca *man/m30.Rd -934782ef76b1878cf7b729470c69cea5 *man/plot2acf.Rd -5d133b7ef15d1704cb903bb8da87476a *man/plotacfthemp.rd -4ff0f0cca22f17b3eda8c059fb424c70 *man/popfr.Rd -6f808a5c6deda5537b87d7f4e1fc7de9 *man/t_stat.rd +68906c790cb6b921c2b74e53a51ad41d *man/khct.rd +646001734fc4e71d1258f90a4c90a8f0 *man/lait.Rd +76e5b708f7c188c9c6ffd51a0b297b63 *man/m30.Rd +ae08e6278679fec6c0e6533d5f4670aa *man/plot2acf.Rd +9817774305a2924c3e7cefba383a2e1d *man/plotacfthemp.rd +be27147f4858ce0798f9d88a39a97e37 *man/popfr.Rd +64c17d2118131703d3126758653e5620 *man/t_stat.rd 7e7bee448755cffcaf59ed90a379ab43 *man/trafmensu.rd 7fbdd84772591ed7349d40bc3165b623 *man/xy.acfb.rd 35778f533a50923f678dbc3d986e21fd *vignettes/Anx1.Rnw 5e716979e76cf558a31d63c340e5efeb *vignettes/Anx10.Rnw -2e4e8a80faec39516bcde3d28c55b9c7 *vignettes/Anx12.Rnw +8cce130c635cc84b04dfd4dd50941e2b *vignettes/Anx12.Rnw 4ee09538f49a888360bae694856fb427 *vignettes/Anx2.Rnw 1230799fab19d4bdcc873e7ba2df77d3 *vignettes/Anx3.Rnw -1419a5945249775dc79a3182968b7e8c *vignettes/Anx4.Rnw +2d946eafd7d7d69694ef1b70f9d9d5ec *vignettes/Anx4.Rnw 06c2411350b8c4bdcfce2094465fd76d *vignettes/Anx5.Rnw 5674fee8a18aee982f21efb3bd54b4cd *vignettes/Anx6.Rnw 90c6a3742945a3cbb762cc9a1e05421f *vignettes/Anx7.Rnw diff --git a/NAMESPACE b/NAMESPACE old mode 100644 new mode 100755 diff --git a/R/Box.test.2.R b/R/Box.test.2.R old mode 100644 new mode 100755 index bf0cd4a..b6d7d73 --- a/R/Box.test.2.R +++ b/R/Box.test.2.R @@ -1,17 +1,11 @@ -Box.test.2 = function(x, nlag,type=c("Box-Pierce","Ljung-Box"), fitdf = 0, decim=8) -{ - - Box.test.inv = function(lag1,x,type = c("Box-Pierce", "Ljung-Box"), fitdf = 0) - { - # fonction Box.test mais avec ses arguments inversés pour pouvoir faire un apply - #lag1=3 - Box.test(x,lag1, type = c("Box-Pierce", "Ljung-Box"), fitdf = 0)$p.value - } - -x=as.vector(x) -nlag = as.matrix(nlag) -aa= round(apply(nlag,1,Box.test.inv,x), digits=decim) -bb = cbind(as.integer(nlag),as.matrix(aa)) -colnames(bb) = c("Retard", "p-value") -bb +Box.test.2 <- function(x, nlag, type = c("Box-Pierce", "Ljung-Box"), fitdf = 0, decim=8) { + Box.test.inv = function(lag1, x, type = c("Box-Pierce", "Ljung-Box"), fitdf = 0) { + stats::Box.test(x, lag1, type = c("Box-Pierce", "Ljung-Box"), fitdf = fitdf)$p.value + } + x <- as.vector(x) + nlag <- as.matrix(nlag) + aa <- round(apply(nlag, 1, Box.test.inv, x), digits = decim) + bb <- cbind(as.integer(nlag), as.matrix(aa)) + colnames(bb) <- c("Retard", "p-value") + bb } \ No newline at end of file diff --git a/R/acf2y.R b/R/acf2y.R old mode 100644 new mode 100755 index ea54472..9bccda2 --- a/R/acf2y.R +++ b/R/acf2y.R @@ -1,41 +1,47 @@ -acf2y <- function(y, lag.max=40, numer=TRUE) -{ -# fonction de Shumway modifiée - num <- length(y) - ACF1 <- stats::acf(as.vector(y), lag.max, plot=FALSE)$acf[-1,1,1] - PACF <- stats::pacf(as.vector(y), lag.max, plot=FALSE)$acf[,1,1] - LAG <- 1:lag.max - minA <- min(ACF1); minP <- min(PACF) - maxA <- max(ACF1); maxP <- max(PACF) - U <- 2/sqrt(num) - L <- -U - minu <- max(-1, min(minA, minP, L)-.01) ; maxu <- min(1, max(maxA, maxP) + 0.05) - -############### paramètres graphiques -mai.n = c(0, 0.8, 0.4, 0.1) # marges en pouces -mai.s = c(0.9, mai.n[2], 0, 0.1) -lar = 7 ; hau=7; # largeur et hauteur totales en pouces -a = lar-mai.n[2] # largeur de chaque graphique -b = (hau-mai.s[1]-mai.n[3])/2 # hauteur de chaque graphique -# figure du haut -(fig.n = c(0, 1, (mai.s[1]+b)/hau, 1)) -# figures du bas -(fig.s = c(0, 1, 0, (mai.s[1]+b)/hau)) -############# figure du haut -op1 = par(fig=fig.n,mai=mai.n) -plot(LAG, ACF1, type="h", ylim=c(minu,maxu), xlab="", xaxt="n", ylab="ACF", - main=paste("Time series: ", deparse(substitute(y))), cex=.8, las=1, - cex.lab=0.9, cex.axis=.8) - abline(h=0) - abline(h=L, lty="dashed", col="blue") - abline(h=U, lty="dashed", col="blue") -# ############ figure du bas -op2 = par(new=TRUE, fig=fig.s ,mai=mai.s) -plot(LAG, PACF, type="h", ylim=c(minu,maxu), xlab="Lag", ylab="PACF", cex=.8, las=1, cex.lab=0.9, cex.axis=.8) - abline(h=0) - abline(h=L, lty="dashed", col="blue") - abline(h=U, lty="dashed", col="blue") -par(op2) -par(op1) -if(numer) return(cbind(LAG, ACF1, PACF)) -} +acf2y <- function(y, lag.max=40, numer=TRUE) { +# Shumway function modified + num <- length(y) + ACF1 <- stats::acf(as.vector(y), lag.max, plot=FALSE)$acf[-1,1,1] + PACF <- stats::pacf(as.vector(y), lag.max, plot=FALSE)$acf[,1,1] + LAG <- 1:lag.max + minA <- min(ACF1) + minP <- min(PACF) + maxA <- max(ACF1) + maxP <- max(PACF) + U <- 2/sqrt(num) + L <- -U + minu <- max(-1, min(minA, minP, L) - .01) + maxu <- min(1, max(maxA, maxP) + 0.05) + + ############### graphical parameters + mai.n <- c(0, 0.8, 0.4, 0.1) + mai.s <- c(0.9, mai.n[2], 0, 0.1) + lar <- 7 + hau <- 7 + a <- lar - mai.n[2] + b <- (hau - mai.s[1] - mai.n[3]) / 2 + fig.n <- c(0, 1, (mai.s[1] + b) / hau, 1) + fig.s <- c(0, 1, 0, (mai.s[1] + b) / hau) + + ############# 1st figure + op1 <- par(fig = fig.n, mai = mai.n) + plot(LAG, ACF1, type = "h", ylim = c(minu, maxu), xlab = "", + xaxt = "n", ylab = "ACF", main = paste("Time series: ", deparse(substitute(y))), + cex = .8, las = 1, cex.lab = 0.9, cex.axis = .8) + abline(h = 0) + abline(h = L, lty = "dashed", col = "blue") + abline(h = U, lty = "dashed", col = "blue") + + # ############ 2nd figure + op2 <- par(new = TRUE, fig = fig.s, mai = mai.s) + plot(LAG, PACF, type = "h", ylim = c(minu, maxu), xlab = "Lag", + ylab = "PACF", cex = .8, las = 1, cex.lab = 0.9, cex.axis = .8) + abline(h = 0) + abline(h = L, lty = "dashed", col = "blue") + abline(h = U, lty = "dashed", col = "blue") + par(op2) + par(op1) + # return result + if (numer) + return(cbind(LAG, ACF1, PACF)) +} diff --git a/R/armaselect.r b/R/armaselect.r old mode 100644 new mode 100755 index 269eaac..7f770dd --- a/R/armaselect.r +++ b/R/armaselect.r @@ -1,84 +1,66 @@ -armaselect = function(y, max.p = 15, max.q = 15, nbmod = 10) -{ - matlag <- function(y, maxlag) - { - # entrée matrice colonne ou vecteur - # sortie matrice de maxlag colonne des valeurs retardée - # contient un triangle de manquants - y = as.matrix(y); n = nrow(y) - x = matrix(1, nrow=n, ncol=1) - for(i in 1:maxlag) - {x = cbind(x, Lag(y,i))} - x = x[,-1] - colnames(x) = paste("Lag_", as.character(1:maxlag), sep = "") - x - } -# calcule une autorégression longue puis des régressions linéaires sur y passés et résidus -# pour chacune, BIC -# inter.p = c(p1,p2) -# inter.q = c(q1,q2) intervalles de valeurs p et q -n = length(y); pmaxi = floor(min(n-1, 10*log10(n))) -# centrage de la série -yc = y - mean(y) -# residus d'une longue autorégression -z.tilde = ar(yc, aic = FALSE, order.max = pmaxi, method = "yule-walker", demean = FALSE)$resid -# pmaxi résidus manquants au début -## remplacés par les pmaxi derniers résidus de la régression sur série retournée -#aa1 = ar(rev(yc),aic = FALSE, order.max = pmaxi, method= "yule-walker", demean=FALSE) -#z.tilde[1:pmaxi] = rev(aa1$resid)[1:pmaxi] -## organisation en matrice -## y retardés -## calcul de la matrice des y retardés -## ici on prédit à l'horizon pmaxi la série retardée pour avoir des non manquants dans y -## prédiction par date croissante -#pred.rev= rev(predict(aa1, n.ahead=max.p)$pred) -#yret = matlag(c(pred.rev,yc),max.p)[-(1:max.p),] -yret = matlag(yc, max.p) -# organisation des résidus -resret = matlag(z.tilde, max.q) -# boucle sur toutes les régressions p : 0:max.p et q : 0:max.q -# stockage data frame de 3 colonnes : p,q, bic -# ordres nuls -# p et q nuls -mm = lm(yc ~ 0) -sbc = nrow(resret)*log(var(mm$residuals)) -# autre critère d'information -bic = AIC(mm, k = log(nrow(resret))) -resul = matrix(NA, nrow = (max.p+1)*(max.q+1), ncol = 4) -colnames(resul) = c("p", "q", "bic", "sbc") -ili=1; resul[ili,] = c(0, 0, bic, sbc) -# q nul -for(ip in 1:max.p) -{ - ili = ili+1 - iq = 0 - mm = lm(yc ~ yret[,1:ip]-1) - bic = AIC(mm, k = log(nrow(resret))) - sbc = nrow(resret)*log(var(mm$residuals))+ ip*log(nrow(resret)) - resul[ili,] = c(ip,0,bic,sbc) -} -#p nul -for(iq in 1:max.q) -{ - ili = ili+1 ; ip=0 - mm = lm(yc ~ resret[,1:iq]-1) - bic = AIC(mm, k = log(nrow(resret))) - sbc = nrow(resret)*log(var(mm$residuals)) + iq*log(nrow(resret)) - resul[ili,] = c(0, iq, bic, sbc) -} -for(ip in 1:max.p) -{ - for(iq in 1:max.q) - { - ili = ili+1 - mm = lm(yc ~ yret[,1:ip] + resret[,1:iq] - 1) - bic = AIC(mm, k = log(nrow(resret))) - sbc = nrow(resret)*log(var(mm$residuals))+ (ip+iq)*log(nrow(resret)) - resul[ili,] = c(ip, iq, bic, sbc) - } -} -ordre = order(resul[,4]) -sbc_opt = resul[ordre,][1:nbmod, c(1, 2, 4)] -colnames(sbc_opt ) = c("p", "q", "sbc") -sbc_opt +armaselect = function(y, max.p = 15, max.q = 15, nbmod = 10) { + matlag <- function(y, maxlag) { + # input: column matrix or vector + # output: matrix with maxlag columns + y <- as.matrix(y) + n <- nrow(y) + x <- matrix(1, nrow = n, ncol = 1) + for (i in 1:maxlag) { + x <- cbind(x, Lag(y,i)) + } + x <- x[, -1] + colnames(x) <- paste("Lag_", as.character(1:maxlag), sep = "") + x + } + # step 1) : compute autoregression, step 2) OLS on y lagged and residuals + n <- length(y) + pmaxi <- floor(min(n - 1, 10 * log10(n))) + # centering data + yc <- y - mean(y) + # residuals + z.tilde = ar(yc, aic = FALSE, order.max = pmaxi, + method = "yule-walker", demean = FALSE)$resid + yret <- matlag(yc, max.p) + # residuals + resret <- matlag(z.tilde, max.q) + # loop + mm <- lm(yc ~ 0) + sbc <- nrow(resret) * log(var(mm$residuals)) + # crieria + bic <- AIC(mm, k = log(nrow(resret))) + resul <- matrix(NA, nrow = (max.p + 1) * (max.q + 1), ncol = 4) + colnames(resul) <- c("p", "q", "bic", "sbc") + ili <- 1 + resul[ili, ] <- c(0, 0, bic, sbc) + # q nul + for(ip in 1:max.p) { + ili <- ili + 1 + iq <- 0 + mm <- lm(yc ~ yret[, 1:ip] - 1) + bic <- AIC(mm, k = log(nrow(resret))) + sbc <- nrow(resret) * log(var(mm$residuals)) + ip * log(nrow(resret)) + resul[ili, ] <- c(ip, 0, bic, sbc) + } + # p nul + for (iq in 1:max.q) { + ili <- ili + 1 + ip <- 0 + mm <- lm(yc ~ resret[, 1:iq] - 1) + bic <- AIC(mm, k = log(nrow(resret))) + sbc <- nrow(resret) * log(var(mm$residuals)) + iq * log(nrow(resret)) + resul[ili,] <- c(0, iq, bic, sbc) + } + for (ip in 1:max.p) { + for(iq in 1:max.q) { + ili <- ili + 1 + mm <- lm(yc ~ yret[, 1:ip] + resret[, 1:iq] - 1) + bic <- AIC(mm, k = log(nrow(resret))) + sbc <- nrow(resret) * log(var(mm$residuals)) + (ip + iq) * log(nrow(resret)) + resul[ili,] <- c(ip, iq, bic, sbc) + } + } + ordre <- order(resul[, 4]) + sbc_opt <- resul[ordre,][1:nbmod, c(1, 2, 4)] + colnames(sbc_opt ) <- c("p", "q", "sbc") + sbc_opt } \ No newline at end of file diff --git a/R/cor.arma.r b/R/cor.arma.r old mode 100644 new mode 100755 index 0ac96f9..6156e29 --- a/R/cor.arma.r +++ b/R/cor.arma.r @@ -1,11 +1,7 @@ -cor.arma = function(mod) -{ -# calcul des corrélations des estimateurs dans une modélisation arima -# input un modele, résultat d'un appel à arima() -# output la matrice des correlations des estimateurs -aa= mod$var.coef -bb = diag(diag(aa)^(-.5)) -cc = bb%*% aa%*%bb -dimnames(cc) = dimnames(aa) -cc -} +cor.arma = function(mod) { + aa <- mod$var.coef + bb <- diag(diag(aa) ^ (-.5)) + cc <- bb %*% aa %*% bb + dimnames(cc) <- dimnames(aa) + cc +} diff --git a/R/plot2acf.R b/R/plot2acf.R old mode 100644 new mode 100755 index 6843dc6..fcae42e --- a/R/plot2acf.R +++ b/R/plot2acf.R @@ -1,41 +1,39 @@ -plot2acf= function(y1, y2, lag.max=40, main=c("","")) -{ - -acfa = stats::acf(y1, lag.max = lag.max, plot=FALSE)$acf[-1] -acfb = stats::acf(y2, lag.max = lag.max, plot=FALSE)$acf[-1] - -titre1 = main[1]; titre2=main[2] - -# une meme echelle pour les 2 graphiques -# 2 acf calcules au mm retard -maxu = min(1, 1.1*max(c(abs(acfa),abs(acfb)))) -maxlag= length(acfa) -LAG = 1:maxlag -# en haut -op <- par(no.readonly = TRUE) -par(fig= c(0,1,0.5,1), cex=.9) -par(mai=c(0,0.810,0.5,0.324)) # mai remplace mar - -# par()$fin -# ACF Haut et titre ############################################################## -plot(LAG, acfa, type="h",ylim=c(-maxu,maxu),xlab="",xaxt="n",ylab="", - cex=.5,cex.lab=.6,cex.axis=.8,las=1) -abline(h=c(-1.96/sqrt(length(y1)),1.96/sqrt(length(y1))),lty=2,col='blue') -abline(h=0) -# text(.8*maxlag,0.9*maxu, labels=titre1, pos=3, cex=.9,font=3) -legend("topright", legend=titre1, cex=.9, bty="n") -# ACF bas ############################################################## -par(new=TRUE) -par(fig= c(0,1,0,0.5)) #, cex=.8, mex=.6,cex.lab=.85) -par(mai=c(0.5,0.810,0,0.324)) -plot(LAG, acfb, type="h",ylim=c(-maxu,maxu),xlab="",xaxt="n",ylab="", - cex=.5,cex.lab=.6,cex.axis=.8,las=1) -abline(h=c(-1.96/sqrt(length(y2)),1.96/sqrt(length(y2))),lty=2,col='blue') -axis(1, at = c(1,12,24,36), labels = c("1","12","24","36"), tick = TRUE, line = NA, - pos = NA, outer = FALSE, font = NA, lty = "solid", - lwd = 1, lwd.ticks = 0.5, col = NULL, col.ticks = NULL, - hadj = NA, padj = NA) -abline(h=0) -legend("topright", legend=titre2, cex=.9, bty="n") -par(op) +plot2acf <- function(y1, y2, lag.max = 40, main = c("", "")) { + + acfa <- stats::acf(y1, lag.max = lag.max, plot = FALSE)$acf[-1] + acfb <- stats::acf(y2, lag.max = lag.max, plot = FALSE)$acf[-1] + + titre1 <- main[1] + titre2 <- main[2] + + maxu <- min(1, 1.1 * max(c(abs(acfa), abs(acfb)))) + maxlag <- length(acfa) + LAG <- 1:maxlag + + # en haut + op <- par(no.readonly = TRUE) + par(fig = c(0, 1, 0.5, 1), cex = .9) + par(mai = c(0, 0.810, 0.5, 0.324)) + + # par()$fin + # ACF Haut et titre ############################################################## + plot(LAG, acfa, type = "h", ylim = c(-maxu, maxu), xlab = "", xaxt = "n", ylab = "", + cex = .5, cex.lab = .6, cex.axis = .8, las = 1) + abline(h = c(-1.96 / sqrt(length(y1)), 1.96 / sqrt(length(y1))), lty = 2, col = 'blue') + abline(h = 0) + legend("topright", legend = titre1, cex = .9, bty = "n") + # ACF bas ############################################################## + par(new = TRUE) + par(fig = c(0, 1, 0, 0.5)) + par(mai = c(0.5, 0.810, 0, 0.324)) + plot(LAG, acfb, type = "h", ylim = c(-maxu, maxu), xlab = "", xaxt = "n", ylab = "", + cex = .5, cex.lab = .6, cex.axis = .8, las = 1) + abline(h = c(-1.96 / sqrt(length(y2)), 1.96 / sqrt(length(y2))), lty = 2, col = 'blue') + axis(1, at = c(1, 12, 24, 36), labels = c("1", "12", "24", "36"), tick = TRUE, line = NA, + pos = NA, outer = FALSE, font = NA, lty = "solid", + lwd = 1, lwd.ticks = 0.5, col = NULL, col.ticks = NULL, + hadj = NA, padj = NA) + abline(h = 0) + legend("topright", legend = titre2, cex = .9, bty = "n") + par(op) } diff --git a/R/plotacfthemp.r b/R/plotacfthemp.r old mode 100644 new mode 100755 index 0524cf3..8ed07f0 --- a/R/plotacfthemp.r +++ b/R/plotacfthemp.r @@ -1,79 +1,74 @@ -plotacfthemp= function(y, ar = numeric(0), ma = numeric(0), lag.max = 20, titre="") -{ - -# computes theoretical ACF and PACF -acf.th =ARMAacf(ar=ar, ma=ma, lag.max=lag.max, pacf=FALSE) -pacf.th =ARMAacf(ar=ar, ma=ma, lag.max=lag.max, pacf=TRUE) - -# computes empirical ACF and PACF -pacf.emp=stats::acf(y,lag.max=lag.max,type="partial",plot=FALSE) -acf.emp= stats::acf(y,lag.max=lag.max,type="correlation",plot=FALSE) - -n = lag.max -ly = length(y) - -# Initialisation -LAG = 1:n -pacfemp= list(y= pacf.emp$acf[,1,1], bsup=(1.96/sqrt(ly))*rep(1,n)) -acfemp= list(y= acf.emp$acf[-1,1,1], bsup=(1.96/sqrt(ly))*rep(1,n)) -pacfth= list(y= pacf.th, bsup= rep(0,n)) -acfth= list(y= acf.th[-1], bsup= rep(0,n)) - - - -# une même échelle pour les 4 graphiques -maxu = min(1, 1.1*max(c(abs(pacfemp$y),abs(acfemp$y), abs(pacfth$y), abs(acfth$y)))) -maxlag= max(LAG) -L = -acfemp$bsup[1]; U=-L -# en haut à gauche -op <- par(no.readonly = TRUE) -par(fig=c(0,0.5,0.5,1)) -par(mai=c(0,0.5,0.5,0)) -par()$fin -# ACF TH Haut gauche et titre ############################################################## -plot(LAG, acfth$y, type="h",ylim=c(-maxu,maxu),xlab="",xaxt="n",ylab="", - cex=.5,cex.lab=.6,cex.axis=.8,las=1) -abline(h=0) -text(.8*maxlag,0.9*maxu, labels=titre, pos=3, cex=.9,font=3) -text(.8*maxlag,0.7*maxu, labels="ACF th.", pos=3, cex=.9) -par(new=TRUE) -par(fig=c(0.5,1,0.5,1)) -par(mai=c(0,0,0.5,0)) -par()$fin -# PACF th haut droit ############################################################## - plot(LAG, pacfth$y, type="h",ylim=c(-maxu,maxu),xlab="",xaxt="n",yaxt="n", - cex=.5,cex.lab=.6,cex.axis=.6,las=1) - abline(h=0) - text(.8*maxlag,0.7*maxu, labels="PACF th.", pos=3, cex=.9) -par(new=TRUE) -par(fig=c(0,0.5,0,0.5)) -par(mai=c(0.5,0.5,0,0)) -par()$fin -# ACF emp bas gauche ############################################################## -plot(LAG, acfemp$y, type="h",ylim=c(-maxu,maxu),xlab="",xaxt="n",ylab="", - cex=.5,cex.lab=.6,cex.axis=.8,las=1) -axis(1, at = c(1,5,10,15,20), labels = c("1","5","10","15","20"), tick = TRUE, line = NA, - pos = NA, outer = FALSE, font = NA, lty = "solid", - lwd = 1, lwd.ticks = 0.5, col = NULL, col.ticks = NULL, - hadj = NA, padj = NA) -abline(h=0) -abline(h=L,lty=2,col="blue") -abline(h=U,lty=2,col="blue") -text(.8*maxlag,0.7*maxu, labels="ACF emp.", pos=3, cex=.9) -# PACF emp bas droit ############################################################## -par(new=TRUE) -par(fig=c(0.5,1,0,0.5)) -par(mai=c(0.5,0,0,0)) -par()$fin -plot(LAG, pacfemp$y, type="h",ylim=c(-maxu,maxu),xlab="",xaxt="n",ylab="",yaxt="n", - cex=.5,cex.lab=.6,cex.axis=.6,las=1) -axis(1, at = c(1,5,10,15,20), labels = c("1","5","10","15","20"), tick = TRUE, line = NA, - pos = NA, outer = FALSE, font = NA, lty = "solid", - lwd = 1, lwd.ticks = 0.5, col = NULL, col.ticks = NULL, - hadj = NA, padj = NA) -abline(h=0) -abline(h=L,lty=2,col="blue") -abline(h=U,lty=2,col="blue") -text(.8*maxlag,0.7*maxu, labels="PACF emp.", pos=3, cex=.9) -par(op) -} +plotacfthemp= function(y, ar = numeric(0), ma = numeric(0), lag.max = 20, titre = "") { + # computes theoretical ACF and PACF + acf.th <- ARMAacf(ar = ar, ma = ma, lag.max = lag.max, pacf = FALSE) + pacf.th <- ARMAacf(ar = ar, ma = ma, lag.max = lag.max, pacf = TRUE) + + pacf.emp <- stats::acf(y, lag.max = lag.max, type = "partial", plot = FALSE) + acf.emp <- stats::acf(y, lag.max = lag.max, type = "correlation", plot = FALSE) + + n <- lag.max + ly <- length(y) + + # Initialisation + LAG <- 1:n + pacfemp <- list(y = pacf.emp$acf[, 1, 1], bsup = (1.96 / sqrt(ly)) * rep(1, n)) + acfemp <- list(y = acf.emp$acf[-1, 1, 1], bsup = (1.96 / sqrt(ly)) * rep(1, n)) + pacfth <- list(y = pacf.th, bsup = rep(0, n)) + acfth <- list(y = acf.th[-1], bsup = rep(0, n)) + + # scale + maxu <- min(1, 1.1 * max(c(abs(pacfemp$y), abs(acfemp$y), abs(pacfth$y), abs(acfth$y)))) + maxlag <- max(LAG) + L <- -acfemp$bsup[1] + U <- -L + # Left + op <- par(no.readonly = TRUE) + par(fig = c(0, 0.5, 0.5, 1)) + par(mai = c(0, 0.5, 0.5, 0)) + par()$fin + # ACF top Left ############################################################## + plot(LAG, acfth$y, type = "h", ylim = c(-maxu, maxu), xlab = "", xaxt = "n", ylab = "", + cex = .5, cex.lab = .6, cex.axis = .8, las = 1) + abline(h = 0) + text(.8 * maxlag, 0.9 * maxu, labels = titre, pos = 3, cex = .9, font = 3) + text(.8 * maxlag, 0.7 * maxu, labels = "ACF th.", pos = 3, cex = .9) + par(new = TRUE) + par(fig = c(0.5, 1, 0.5, 1)) + par(mai = c(0, 0, 0.5, 0)) + par()$fin + # PACF top Right ############################################################## + plot(LAG, pacfth$y, type = "h", ylim = c(-maxu, maxu), xlab = "", xaxt = "n", yaxt = "n", + cex = .5, cex.lab = .6, cex.axis = .6, las = 1) + abline(h = 0) + text(.8 * maxlag, 0.7 * maxu, labels = "PACF th.", pos = 3, cex = .9) + par(new = TRUE) + par(fig = c(0, 0.5, 0, 0.5)) + par(mai = c(0.5, 0.5, 0, 0)) + par()$fin + # ACF bottom Left ############################################################## + plot(LAG, acfemp$y, type = "h", ylim = c(-maxu, maxu), xlab = "", xaxt = "n", ylab = "", + cex = .5, cex.lab = .6, cex.axis = .8, las = 1) + axis(1, at = c(1, 5, 10, 15, 20), labels = c("1", "5", "10", "15", "20"), + tick = TRUE, line = NA, pos = NA, outer = FALSE, font = NA, lty = "solid", + lwd = 1, lwd.ticks = 0.5, col = NULL, col.ticks = NULL, hadj = NA, padj = NA) + abline(h = 0) + abline(h = L, lty = 2, col = "blue") + abline(h = U, lty = 2, col = "blue") + text(.8 * maxlag, 0.7 * maxu, labels = "ACF emp.", pos = 3, cex = .9) + # PACF bottom droit ############################################################## + par(new = TRUE) + par(fig = c(0.5, 1, 0, 0.5)) + par(mai = c(0.5, 0, 0, 0)) + par()$fin + plot(LAG, pacfemp$y, type = "h", ylim = c(-maxu, maxu), xlab = "", + xaxt = "n", ylab = "", yaxt = "n", cex = .5, cex.lab = .6, cex.axis = .6, las = 1) + axis(1, at = c(1, 5, 10, 15, 20), labels = c("1", "5", "10", "15", "20"), + tick = TRUE, line = NA, pos = NA, outer = FALSE, font = NA, lty = "solid", + lwd = 1, lwd.ticks = 0.5, col = NULL, col.ticks = NULL, + hadj = NA, padj = NA) + abline(h = 0) + abline(h = L, lty = 2, col = "blue") + abline(h = U, lty = 2, col = "blue") + text(.8 * maxlag, 0.7 * maxu, labels = "PACF emp.", pos = 3, cex = .9) + par(op) +} diff --git a/R/t_stat.r b/R/t_stat.r old mode 100644 new mode 100755 index 541748c..35af809 --- a/R/t_stat.r +++ b/R/t_stat.r @@ -1,11 +1,9 @@ -t_stat = function(modarima, decim = 6) -{# fonction pour calculer les p-value d'un modele arima avec éventuellement contraintes sur certains paramètres -# modarima = reg.av3 -if(!is(modarima, "Arima")) stop("modarima may be an Arima object from package forecast") - t.stat <- modarima$coef[modarima$mask == TRUE]/sqrt(diag(modarima$var.coef)) - p.val <- rep(0,length(t.stat)) - p.val[t.stat<0] <- 2*pnorm(t.stat[t.stat<0]) - p.val[t.stat>0] <- 2*(1 - pnorm(t.stat[t.stat>0])) - round(rbind(t.stat, p.val), digits = decim) - #dimnames(ab)[[1]] = c("t-stat", "p-value") -} +t_stat = function(modarima, decim = 6) { + if(!is(modarima, "Arima")) + stop("modarima may be an Arima object from package forecast") + t.stat <- modarima$coef[modarima$mask == TRUE] / sqrt(diag(modarima$var.coef)) + p.val <- rep(0, length(t.stat)) + p.val[t.stat < 0] <- 2 * pnorm(t.stat[t.stat < 0]) + p.val[t.stat > 0] <- 2 * (1 - pnorm(t.stat[t.stat > 0])) + round(rbind(t.stat, p.val), digits = decim) +} diff --git a/R/xy.acfb.r b/R/xy.acfb.r old mode 100644 new mode 100755 index d539d42..a0ff97a --- a/R/xy.acfb.r +++ b/R/xy.acfb.r @@ -1,37 +1,38 @@ -xy.acfb=function(y, lag.max=40, numer=TRUE) -{ -num=length(y) -mp1=lag.max+1 - -ACF1=stats::acf(y, lag.max, plot=FALSE)$acf[2:mp1] -PACF= stats::pacf(y, lag.max, plot=FALSE)$acf - -LAG=1:lag.max -minA=min(ACF1); minP=min(PACF) -maxA=max(ACF1); maxP=max(PACF) -U=2/sqrt(num) -L=-U -# minu=min(minA,minP,L)-0.01 -# minu = -1 -minu=max(-1, min(minA,minP,L)-.01) ; maxu= min(1, max(maxA,maxP)+0.05) - -op<-par(fig= c(0,1,0.6,1), mar=c(1,5,3,2)) -plot(y, xlab="", cex=.8, cex.lab=0.9, ylab=names(y)) - par(new=TRUE, fig= c(0,1,0.32,0.55), mar=c(0,5,0,2)) - plot(LAG, ACF1, type="h", ylim=c(minu,maxu), xlab="", xaxt="n", - cex=.8, cex.lab=0.9, las=1, ylab="ACF") - abline(h=0) - abline(h=L, lty="dashed", col="blue") - abline(h=U, lty="dashed", col="blue") - legend("topright", legend= paste("Time Series:",deparse(substitute(y))), - bty="n", cex=.9) - - par(new=TRUE,fig= c(0,1,0,0.32), mar=c(3,5,0,2)) - plot(LAG, PACF, type="h" ,ylim=c(minu,maxu), xlab="", cex=.8, las=1, - cex.lab=0.9, ylab="PACF") - abline(h=0) - abline(h=L, lty="dashed", col="blue") - abline(h=U, lty="dashed", col="blue") - if(numer) return(cbind(LAG, ACF1, PACF)) -par(op) +xy.acfb=function(y, lag.max = 40, numer = TRUE) { + num <- length(y) + mp1 <- lag.max + 1 + + ACF1 <- stats::acf(y, lag.max, plot = FALSE)$acf[2:mp1] + PACF <- stats::pacf(y, lag.max, plot = FALSE)$acf + + LAG <- 1:lag.max + minA <- min(ACF1) + minP <- min(PACF) + maxA <- max(ACF1) + maxP <- max(PACF) + U <- 2/sqrt(num) + L <- -U + minu <- max(-1, min(minA, minP, L) - .01) + maxu <- min(1, max(maxA, maxP) + 0.05) + + op <- par(fig = c(0, 1, 0.6, 1), mar = c(1, 5, 3, 2)) + plot(y, xlab = "", cex = .8, cex.lab = 0.9, ylab = names(y)) + par(new = TRUE, fig = c(0, 1, 0.32, 0.55), mar = c(0, 5, 0, 2)) + plot(LAG, ACF1, type = "h", ylim = c(minu, maxu), xlab = "", xaxt = "n", + cex = .8, cex.lab = 0.9, las = 1, ylab = "ACF") + abline(h = 0) + abline(h = L, lty = "dashed", col = "blue") + abline(h = U, lty = "dashed", col = "blue") + legend("topright", legend = paste("Time Series:", deparse(substitute(y))), + bty = "n", cex = .9) + + par(new = TRUE, fig = c(0, 1, 0, 0.32), mar = c(3, 5, 0, 2)) + plot(LAG, PACF, type = "h", ylim = c(minu, maxu), xlab = "", cex = .8, las = 1, + cex.lab = 0.9, ylab = "PACF") + abline(h = 0) + abline(h = L, lty = "dashed", col = "blue") + abline(h = U, lty = "dashed", col = "blue") + if(numer) + return(cbind(LAG, ACF1, PACF)) + par(op) } \ No newline at end of file diff --git a/build/vignette.rds b/build/vignette.rds index 9bb9fe5..a5724d6 100644 Binary files a/build/vignette.rds and b/build/vignette.rds differ diff --git a/data/champa.ts.rda b/data/champa.ts.rda old mode 100644 new mode 100755 diff --git a/data/csdl.RData b/data/csdl.RData old mode 100644 new mode 100755 diff --git a/data/essil.RData b/data/essil.RData old mode 100644 new mode 100755 diff --git a/data/indbourse.RData b/data/indbourse.RData old mode 100644 new mode 100755 diff --git a/data/khct.rda b/data/khct.rda old mode 100644 new mode 100755 diff --git a/data/lait.rda b/data/lait.rda old mode 100644 new mode 100755 diff --git a/data/m30.rda b/data/m30.rda old mode 100644 new mode 100755 diff --git a/data/popfr.rda b/data/popfr.rda old mode 100644 new mode 100755 diff --git a/data/trafmensu.rda b/data/trafmensu.rda old mode 100644 new mode 100755 diff --git a/inst/CITATION b/inst/CITATION old mode 100644 new mode 100755 diff --git a/inst/doc/Anx1.Rnw b/inst/doc/Anx1.Rnw old mode 100644 new mode 100755 diff --git a/inst/doc/Anx1.pdf b/inst/doc/Anx1.pdf index 8eca7da..7533ce3 100644 Binary files a/inst/doc/Anx1.pdf and b/inst/doc/Anx1.pdf differ diff --git a/inst/doc/Anx10.Rnw b/inst/doc/Anx10.Rnw old mode 100644 new mode 100755 diff --git a/inst/doc/Anx10.pdf b/inst/doc/Anx10.pdf index 623f92c..8cbd23d 100644 Binary files a/inst/doc/Anx10.pdf and b/inst/doc/Anx10.pdf differ diff --git a/inst/doc/Anx12.R b/inst/doc/Anx12.R index 4df7062..c42eb19 100644 --- a/inst/doc/Anx12.R +++ b/inst/doc/Anx12.R @@ -221,7 +221,7 @@ cat("stat de test et p-value : ", ################################################### ### code chunk number 27: lor.1a ################################################### -# require(fBasics) +require(fBasics) data(csdl) aa = returns(csdl, percentage = TRUE) aab = aa[complete.cases(aa) == TRUE,] @@ -284,8 +284,8 @@ bsup.garch.lor = pred.garch.lor$meanForecast+demi ### code chunk number 31: ajust (eval = FALSE) ################################################### ## par(oma=rep(0.5,4)) -## mat.lor = cbind(binf.arima.lor,bsup.arima.lor, -## binf.garch.lor, bsup.garch.lor, r.lor.1[1:npred]) +## mat.lor = cbind(binf.arima.lor, bsup.arima.lor, +## binf.garch.lor, bsup.garch.lor, as.numeric(r.lor.1[1:npred])) ## matplot(1:npred,mat.lor, type = "l", col = "black", ## lty = c(1, 1, 2, 2, 3), lwd = 2, ## xlab = "horizon 50", ylab = "rendement") @@ -299,8 +299,8 @@ bsup.garch.lor = pred.garch.lor$meanForecast+demi .PngNo <- .PngNo + 1; file = paste(nom.fich, .PngNo, sep="") pdf(file=paste(file,".pdf",sep=""), width = 7, height = 4, pointsize = 10, bg = "white") par(oma=rep(0.5,4)) -mat.lor = cbind(binf.arima.lor,bsup.arima.lor, - binf.garch.lor, bsup.garch.lor, r.lor.1[1:npred]) +mat.lor = cbind(binf.arima.lor, bsup.arima.lor, + binf.garch.lor, bsup.garch.lor, as.numeric(r.lor.1[1:npred])) matplot(1:npred,mat.lor, type = "l", col = "black", lty = c(1, 1, 2, 2, 3), lwd = 2, xlab = "horizon 50", ylab = "rendement") @@ -309,8 +309,8 @@ legend(14, 3, leg.txt, lty = c(1, 2, 3)) dev.null <- dev.off() postscript(file=paste(file,".ps",sep=""), width = 7, height =4, pointsize = 10, bg = "white",horizontal= FALSE,paper="special") par(oma=rep(0.5,4)) -mat.lor = cbind(binf.arima.lor,bsup.arima.lor, - binf.garch.lor, bsup.garch.lor, r.lor.1[1:npred]) +mat.lor = cbind(binf.arima.lor, bsup.arima.lor, + binf.garch.lor, bsup.garch.lor, as.numeric(r.lor.1[1:npred])) matplot(1:npred,mat.lor, type = "l", col = "black", lty = c(1, 1, 2, 2, 3), lwd = 2, xlab = "horizon 50", ylab = "rendement") @@ -363,9 +363,9 @@ bsup.garch.dan = pred.garch.dan$meanForecast + demi ################################################### ### code chunk number 36: pred.dan (eval = FALSE) ################################################### -## par(oma=rep(0.5,4)) +## par(oma=rep(0.5, 4)) ## mat.dan = cbind(binf.arima.dan, bsup.arima.dan, -## binf.garch.dan, bsup.garch.dan, r.dan.1[1:npred]) +## binf.garch.dan, bsup.garch.dan, as.numeric(r.dan.1[1:npred])) ## matplot(1:npred, mat.dan, type = "l", col = "black", ## lty = c(1, 1, 2, 2, 3), lwd = 2, ## xlab = "horizon 50", ylab = "rendement") @@ -378,9 +378,9 @@ bsup.garch.dan = pred.garch.dan$meanForecast + demi ################################################### .PngNo <- .PngNo + 1; file = paste(nom.fich, .PngNo, sep="") pdf(file=paste(file,".pdf",sep=""), width = 7, height = 4, pointsize = 10, bg = "white") -par(oma=rep(0.5,4)) +par(oma=rep(0.5, 4)) mat.dan = cbind(binf.arima.dan, bsup.arima.dan, - binf.garch.dan, bsup.garch.dan, r.dan.1[1:npred]) + binf.garch.dan, bsup.garch.dan, as.numeric(r.dan.1[1:npred])) matplot(1:npred, mat.dan, type = "l", col = "black", lty = c(1, 1, 2, 2, 3), lwd = 2, xlab = "horizon 50", ylab = "rendement") @@ -388,9 +388,9 @@ leg.txt = c("GARCH", "AR", "realisation") legend(14, 3, leg.txt, lty = c(1, 2, 3)) dev.null <- dev.off() postscript(file=paste(file,".ps",sep=""), width = 7, height =4, pointsize = 10, bg = "white",horizontal= FALSE,paper="special") -par(oma=rep(0.5,4)) +par(oma=rep(0.5, 4)) mat.dan = cbind(binf.arima.dan, bsup.arima.dan, - binf.garch.dan, bsup.garch.dan, r.dan.1[1:npred]) + binf.garch.dan, bsup.garch.dan, as.numeric(r.dan.1[1:npred])) matplot(1:npred, mat.dan, type = "l", col = "black", lty = c(1, 1, 2, 2, 3), lwd = 2, xlab = "horizon 50", ylab = "rendement") diff --git a/inst/doc/Anx12.Rnw b/inst/doc/Anx12.Rnw old mode 100644 new mode 100755 index c3a89eb..97f59c2 --- a/inst/doc/Anx12.Rnw +++ b/inst/doc/Anx12.Rnw @@ -508,7 +508,7 @@ du r\'esidu du premier ajustement. Tout d'abord, nous r\'eestimons le mod\`ele A {\small <>= -# require(fBasics) +require(fBasics) data(csdl) aa = returns(csdl, percentage = TRUE) aab = aa[complete.cases(aa) == TRUE,] @@ -582,8 +582,8 @@ puis par la mod\'elisation ARMA. {\small <>= par(oma=rep(0.5,4)) -mat.lor = cbind(binf.arima.lor,bsup.arima.lor, - binf.garch.lor, bsup.garch.lor, r.lor.1[1:npred]) +mat.lor = cbind(binf.arima.lor, bsup.arima.lor, + binf.garch.lor, bsup.garch.lor, as.numeric(r.lor.1[1:npred])) matplot(1:npred,mat.lor, type = "l", col = "black", lty = c(1, 1, 2, 2, 3), lwd = 2, xlab = "horizon 50", ylab = "rendement") @@ -684,9 +684,9 @@ puis par la mod\'elisation ARMA. {\small <>= -par(oma=rep(0.5,4)) +par(oma=rep(0.5, 4)) mat.dan = cbind(binf.arima.dan, bsup.arima.dan, - binf.garch.dan, bsup.garch.dan, r.dan.1[1:npred]) + binf.garch.dan, bsup.garch.dan, as.numeric(r.dan.1[1:npred])) matplot(1:npred, mat.dan, type = "l", col = "black", lty = c(1, 1, 2, 2, 3), lwd = 2, xlab = "horizon 50", ylab = "rendement") diff --git a/inst/doc/Anx12.pdf b/inst/doc/Anx12.pdf index be39bce..a8163da 100644 Binary files a/inst/doc/Anx12.pdf and b/inst/doc/Anx12.pdf differ diff --git a/inst/doc/Anx2.Rnw b/inst/doc/Anx2.Rnw old mode 100644 new mode 100755 diff --git a/inst/doc/Anx2.pdf b/inst/doc/Anx2.pdf index c54c5b3..b5ffa1b 100644 Binary files a/inst/doc/Anx2.pdf and b/inst/doc/Anx2.pdf differ diff --git a/inst/doc/Anx3.Rnw b/inst/doc/Anx3.Rnw old mode 100644 new mode 100755 diff --git a/inst/doc/Anx3.pdf b/inst/doc/Anx3.pdf index 804d19f..521e179 100644 Binary files a/inst/doc/Anx3.pdf and b/inst/doc/Anx3.pdf differ diff --git a/inst/doc/Anx4.R b/inst/doc/Anx4.R index ad2a4bc..12f7425 100644 --- a/inst/doc/Anx4.R +++ b/inst/doc/Anx4.R @@ -127,11 +127,11 @@ ARMAtoMA(c(rep(0, 11), -.7), 0, 25) ################################################### -### code chunk number 17: Anx4.Rnw:296-299 +### code chunk number 17: Anx4.Rnw:296-299 (eval = FALSE) ################################################### -require(FitARMA) -ImpulseCoefficientsARMA(-.7, 0, lag.max = 10) -ImpulseCoefficientsARMA(c(rep(0, 11), -.7), 0, lag.max = 25) +## require(FitARMA) +## ImpulseCoefficientsARMA(-.7, 0, lag.max = 10) +## ImpulseCoefficientsARMA(c(rep(0, 11), -.7), 0, lag.max = 25) ################################################### @@ -223,36 +223,36 @@ cat("\\includegraphics[width=0.9\\textwidth]{", file, "}\n\n", sep="") ################################################### -### code chunk number 26: simar2 +### code chunk number 26: simar2 (eval = FALSE) ################################################### -require(FitARMA) -set.seed(51) -nsim <- 100 -nobs <- 200 -nsim <- 50 -nlag <- 20 -y.mat <- matrix(0, nrow = nobs, ncol = nsim) -facp.mat <- matrix(0, nrow = nlag, ncol = nsim) -y.mat <- matrix(0, nrow = 200, ncol = nsim) -facp.mat <- matrix(0, nrow = nlag, ncol = nsim) -for(isim in 1:nsim){ - y.mat[, isim] <- arima.sim(n = nobs, - list(ar = c(-0.7, 0.2)), - sd = sqrt(2)) - facp.mat[, isim] = pacf(y.mat[,isim], 20, plot = FALSE)$acf -} -aa <- t(apply(facp.mat,1, "quantile", probs = c(0.25, .75))) -# pacf theo -theo <- TacvfARMA(phi = c(-.7, .2), lag.max = 20) -pacf.theo <- PacfDL(theo/theo[1], LinearPredictor = TRUE)$Pacf -# intervalle autour de 0 \`a 50% -binf <- qnorm(.25)/nobs^.5 -bsup <- qnorm(.75)/nobs^.5 -aaa <- cbind(aa, pacf.theo, binf, bsup) +## require(FitARMA) +## set.seed(51) +## nsim <- 100 +## nobs <- 200 +## nsim <- 50 +## nlag <- 20 +## y.mat <- matrix(0, nrow = nobs, ncol = nsim) +## facp.mat <- matrix(0, nrow = nlag, ncol = nsim) +## y.mat <- matrix(0, nrow = 200, ncol = nsim) +## facp.mat <- matrix(0, nrow = nlag, ncol = nsim) +## for(isim in 1:nsim){ +## y.mat[, isim] <- arima.sim(n = nobs, +## list(ar = c(-0.7, 0.2)), +## sd = sqrt(2)) +## facp.mat[, isim] = pacf(y.mat[,isim], 20, plot = FALSE)$acf +## } +## aa <- t(apply(facp.mat,1, "quantile", probs = c(0.25, .75))) +## # pacf theo +## theo <- TacvfARMA(phi = c(-.7, .2), lag.max = 20) +## pacf.theo <- PacfDL(theo/theo[1], LinearPredictor = TRUE)$Pacf +## # intervalle autour de 0 \`a 50% +## binf <- qnorm(.25)/nobs^.5 +## bsup <- qnorm(.75)/nobs^.5 +## aaa <- cbind(aa, pacf.theo, binf, bsup) ################################################### -### code chunk number 27: Anx4.Rnw:487-491 (eval = FALSE) +### code chunk number 27: Anx4.Rnw:488-492 (eval = FALSE) ################################################### ## matplot(1:20, aaa, type = "l", ylab = "PACF", ## xlab = "retard", col = "black") @@ -270,22 +270,22 @@ aaa <- cbind(aa, pacf.theo, binf, bsup) ################################################### -### code chunk number 29: Anx4.Rnw:508-515 +### code chunk number 29: Anx4.Rnw:509-516 (eval = FALSE) ################################################### -.PngNo <- .PngNo + 1; file = paste(nom.fich, .PngNo, sep="") -pdf(file=paste(file,".pdf",sep=""), width = 6, height = 6, pointsize = 10, bg = "white") -matplot(1:20, aaa, type = "l", ylab = "PACF", - xlab = "retard", col = "black") -legend("topright", paste("nombre de simulations : ", - as.character(nsim))) -dev.null <- dev.off() -postscript(file=paste(file,".ps",sep=""), width = 6, height = 6, pointsize = 10, bg = "white",horizontal= FALSE,paper="special") -matplot(1:20, aaa, type = "l", ylab = "PACF", - xlab = "retard", col = "black") -legend("topright", paste("nombre de simulations : ", - as.character(nsim))) -dev.null <- dev.off() -cat("\\includegraphics[width=0.9\\textwidth]{", file, "}\n\n", sep="") +## .PngNo <- .PngNo + 1; file = paste(nom.fich, .PngNo, sep="") +## pdf(file=paste(file,".pdf",sep=""), width = 6, height = 6, pointsize = 10, bg = "white") +## matplot(1:20, aaa, type = "l", ylab = "PACF", +## xlab = "retard", col = "black") +## legend("topright", paste("nombre de simulations : ", +## as.character(nsim))) +## dev.null <- dev.off() +## postscript(file=paste(file,".ps",sep=""), width = 6, height = 6, pointsize = 10, bg = "white",horizontal= FALSE,paper="special") +## matplot(1:20, aaa, type = "l", ylab = "PACF", +## xlab = "retard", col = "black") +## legend("topright", paste("nombre de simulations : ", +## as.character(nsim))) +## dev.null <- dev.off() +## cat("\\includegraphics[width=0.9\\textwidth]{", file, "}\n\n", sep="") ################################################### @@ -315,28 +315,28 @@ t(aa) ################################################### -### code chunk number 33: Anx4.Rnw:592-599 +### code chunk number 33: Anx4.Rnw:593-600 (eval = FALSE) ################################################### -theo <- TacvfARMA(theta = c(.3, -.6), lag.max = 20) -(acf.theo <- theo[-1]/theo[1]) -(pacf.theo <- PacfDL(theo/theo[1], LinearPredictor = TRUE)$Pacf) -set.seed(12) -y <- arima.sim(n = 200, list(ma = c(-0.3, .6)), sd = sqrt(1.5)) -(acf.emp <- acf(y, 20, plot = FALSE)$acf[-1]) -(pacf.emp <- pacf(y, 20, plot = FALSE)$acf) +## theo <- TacvfARMA(theta = c(.3, -.6), lag.max = 20) +## (acf.theo <- theo[-1]/theo[1]) +## (pacf.theo <- PacfDL(theo/theo[1], LinearPredictor = TRUE)$Pacf) +## set.seed(12) +## y <- arima.sim(n = 200, list(ma = c(-0.3, .6)), sd = sqrt(1.5)) +## (acf.emp <- acf(y, 20, plot = FALSE)$acf[-1]) +## (pacf.emp <- pacf(y, 20, plot = FALSE)$acf) ################################################### -### code chunk number 34: Anx4.Rnw:617-625 +### code chunk number 34: Anx4.Rnw:618-626 (eval = FALSE) ################################################### -theo <- TacvfARMA(phi = -.8, lag.max = 20) -(acf.theo <- theo[-1]/theo[1]) -(pacf.theo <- PacfDL(theo/theo[1], LinearPredictor = TRUE)$Pacf) -set.seed(23) -y <- arima.sim(n = 200, list(ar = -.8), - sd = sqrt(1.5)) - 10 -(acf.emp <- acf(y, 20, plot = FALSE)$acf[-1]) -(pacf.emp <- pacf(y, 20, plot = FALSE)$acf) +## theo <- TacvfARMA(phi = -.8, lag.max = 20) +## (acf.theo <- theo[-1]/theo[1]) +## (pacf.theo <- PacfDL(theo/theo[1], LinearPredictor = TRUE)$Pacf) +## set.seed(23) +## y <- arima.sim(n = 200, list(ar = -.8), +## sd = sqrt(1.5)) - 10 +## (acf.emp <- acf(y, 20, plot = FALSE)$acf[-1]) +## (pacf.emp <- pacf(y, 20, plot = FALSE)$acf) ################################################### @@ -364,7 +364,7 @@ pacf.th <- ARMAacf(ar = -0.8, ma = c(-0.3, 0.6), ################################################### -### code chunk number 38: Anx4.Rnw:674-681 +### code chunk number 38: Anx4.Rnw:675-682 ################################################### .PngNo <- .PngNo + 1; file = paste(nom.fich, .PngNo, sep="") pdf(file=paste(file,".pdf",sep=""), width = 7, height = 7, pointsize = 12, bg = "white") diff --git a/inst/doc/Anx4.Rnw b/inst/doc/Anx4.Rnw old mode 100644 new mode 100755 index 0fd014a..7e64902 --- a/inst/doc/Anx4.Rnw +++ b/inst/doc/Anx4.Rnw @@ -290,10 +290,10 @@ ARMAtoMA(c(rep(0, 11), -.7), 0, 25) @ } -Par \code{ImpulseCoefficientsARMA()} de \pkg{FitARMA} : +Par \code{ImpulseCoefficientsARMA()} de \pkg{FitARMA} (Attention, le package \pkg{FitARMA} n'est plus maintenu sur le CRAN) {\small -<<>>= +<>= require(FitARMA) ImpulseCoefficientsARMA(-.7, 0, lag.max = 10) ImpulseCoefficientsARMA(c(rep(0, 11), -.7), 0, lag.max = 25) @@ -449,9 +449,10 @@ et calculer la PACF empirique jusqu'au retard 4. Comparer avec l'exemple pr\'ec\ D'autre part nous effectuons \code{nsim} simulations pour comparer la pr\'ecision de l'estimateur et nous superposons valeur th\'eorique et quantile empirique d'ordres .25 et .75 pour chaque retard : +(Attention, le package \pkg{FitARMA} n'est plus maintenu sur le CRAN, mais il est disponible sur Github https://github.com/cran/FitARMA) {\small -<>= +<>= require(FitARMA) set.seed(51) nsim <- 100 @@ -479,7 +480,7 @@ aaa <- cbind(aa, pacf.theo, binf, bsup) @ } \code{binf} et \code{bsup} d\'efinissent la bande de confiance asymptotique, valable \'evidemment \`a partir du retard 3, voir la propri\'et\'e 4.6, alors que les quantiles -d'ordres .25 et .75, matrice \code{aa}, donnent les quantiles empiriques d'apr\`es les \Sexpr{nsim} simulations. +d'ordres .25 et .75, matrice \code{aa}, donnent les quantiles empiriques d'apr\`es les 50 simulations. On obtient le graphique (fig. \ref{matplot}) pour 50 simulations par @@ -505,7 +506,7 @@ legend("topright", paste("nombre de simulations : ", \begin{figure}[htbp] \begin{center} -<>= +<>= <> <> <> @@ -589,7 +590,7 @@ par \code{arima.sim()}. \textbf{R\'eponse.} {\small -<<>>= +<< eval = F>>= theo <- TacvfARMA(theta = c(.3, -.6), lag.max = 20) (acf.theo <- theo[-1]/theo[1]) (pacf.theo <- PacfDL(theo/theo[1], LinearPredictor = TRUE)$Pacf) @@ -614,7 +615,7 @@ R\'epondre pour ce mod\`ele, aux questions de l'exercice pr\'ec\'edent. \textbf{R\'eponse.} {\small -<<>>= +<< eval = F>>= theo <- TacvfARMA(phi = -.8, lag.max = 20) (acf.theo <- theo[-1]/theo[1]) (pacf.theo <- PacfDL(theo/theo[1], LinearPredictor = TRUE)$Pacf) diff --git a/inst/doc/Anx4.pdf b/inst/doc/Anx4.pdf index 87a6247..330a0a6 100644 Binary files a/inst/doc/Anx4.pdf and b/inst/doc/Anx4.pdf differ diff --git a/inst/doc/Anx5.Rnw b/inst/doc/Anx5.Rnw old mode 100644 new mode 100755 diff --git a/inst/doc/Anx5.pdf b/inst/doc/Anx5.pdf index 0c99472..e1e224d 100644 Binary files a/inst/doc/Anx5.pdf and b/inst/doc/Anx5.pdf differ diff --git a/inst/doc/Anx6.Rnw b/inst/doc/Anx6.Rnw old mode 100644 new mode 100755 diff --git a/inst/doc/Anx6.pdf b/inst/doc/Anx6.pdf index e8a48ca..1d92011 100644 Binary files a/inst/doc/Anx6.pdf and b/inst/doc/Anx6.pdf differ diff --git a/inst/doc/Anx7.Rnw b/inst/doc/Anx7.Rnw old mode 100644 new mode 100755 diff --git a/inst/doc/Anx7.pdf b/inst/doc/Anx7.pdf index fcf60d3..fce2c1c 100644 Binary files a/inst/doc/Anx7.pdf and b/inst/doc/Anx7.pdf differ diff --git a/inst/doc/Anx9.Rnw b/inst/doc/Anx9.Rnw old mode 100644 new mode 100755 diff --git a/inst/doc/Anx9.pdf b/inst/doc/Anx9.pdf index e9e0e14..c873668 100644 Binary files a/inst/doc/Anx9.pdf and b/inst/doc/Anx9.pdf differ diff --git a/inst/doc/sortie.pdf b/inst/doc/sortie.pdf new file mode 100755 index 0000000..2c0186f Binary files /dev/null and b/inst/doc/sortie.pdf differ diff --git a/inst/import/Tel_extrait.csv b/inst/import/Tel_extrait.csv old mode 100644 new mode 100755 diff --git a/inst/import/champagne_2001.txt b/inst/import/champagne_2001.txt old mode 100644 new mode 100755 diff --git a/inst/import/collecteLait.txt b/inst/import/collecteLait.txt old mode 100644 new mode 100755 diff --git a/inst/import/conselec.csv b/inst/import/conselec.csv old mode 100644 new mode 100755 diff --git a/inst/import/trafquoti.txt b/inst/import/trafquoti.txt old mode 100644 new mode 100755 diff --git a/man/Box.test.2.rd b/man/Box.test.2.rd old mode 100644 new mode 100755 index 2eb0111..e831689 --- a/man/Box.test.2.rd +++ b/man/Box.test.2.rd @@ -1,28 +1,28 @@ -\name{Box.test.2} -\alias{Box.test.2} -\title{'Portemanteau' tests} -\description{\code{Box.test.2} computes at different lags, a 'Portemanteau' statistic -for testing that a time series is a white noise.} -\usage{ -Box.test.2(x, nlag, type = c("Box-Pierce", "Ljung-Box"), fitdf = 0, decim = 8) -} -\arguments{ - \item{x}{a time series object} - \item{nlag}{a vector of integers: the lags where the statistic are computed} - \item{type}{test to be performed} - \item{fitdf}{number of degrees of freedom to be subtracted if x is a series of residuals} - \item{decim}{an integer, the precision of the results} -} -\details{This function uses the \code{Box.test}.} -\value{ -It returns a matrix of size \code{nlag} x 2 with the statistics and the p-value -} - -\author{Yves Aragon} - -\examples{ -set.seed(123) -y1 = arima.sim(n = 100, list(ar = -.7), sd = sqrt(4)) -a1 = Box.test.2(y1, nlag = c(3, 6, 9, 12), type = "Ljung-Box", decim = 4) -} -\keyword{ts} +\name{Box.test.2} +\alias{Box.test.2} +\title{'Portemanteau' tests} +\description{\code{Box.test.2} computes at different lags, a 'Portemanteau' statistic +for testing that a time series is a white noise.} +\usage{ +Box.test.2(x, nlag, type = c("Box-Pierce", "Ljung-Box"), fitdf = 0, decim = 8) +} +\arguments{ + \item{x}{a time series object} + \item{nlag}{a vector of integers: the lags where the statistic are computed} + \item{type}{test to be performed} + \item{fitdf}{number of degrees of freedom to be subtracted if x is a series of residuals} + \item{decim}{an integer, the precision of the results} +} +\details{This function uses the \code{Box.test}.} +\value{ +It returns a matrix of size \code{nlag} x 2 with the statistics and the p-value +} + +\author{Yves Aragon} + +\examples{ +set.seed(123) +y1 <- arima.sim(n = 100, list(ar = -.7), sd = sqrt(4)) +a1 <- Box.test.2(y1, nlag = c(3, 6, 9, 12), type = "Ljung-Box", decim = 4) +} +\keyword{ts} diff --git a/man/Tel_extrait.Rd b/man/Tel_extrait.Rd old mode 100644 new mode 100755 index c1e1f00..3759af1 --- a/man/Tel_extrait.Rd +++ b/man/Tel_extrait.Rd @@ -1,15 +1,14 @@ -\name{Tel_extrait} -\alias{Tel_extrait} -\docType{data} -\title{Telephone consumption in a firm} -\description{ -The file "Tel_extrait.csv" has been created by an automatic telephone exchange system in a firm; -the date includes the day, the month and the year ordered like this : D, M, Y. -} -\format{The series is first imported as a \code{data.frame} object and then transformed into a \code{ts} object} -\examples{ -don.mois1=read.csv2(file= system.file("/import/Tel_extrait.csv",package="caschrono"), - col.names=c("Date.app","Heur.deb.app", "Code Dest", "Dest Det","Dur app sec.", - "Mont app EU"), skip=0, stringsAsFactors=FALSE) -} -\keyword{datasets} +\name{Tel_extrait} +\alias{Tel_extrait} +\docType{data} +\title{Telephone consumption in a firm} +\description{ +The file "Tel_extrait.csv" has been created by an automatic telephone exchange system in a firm; the date includes the day, the month and the year ordered like this : D, M, Y. +} +\format{The series is first imported as a \code{data.frame} object and then transformed into a \code{ts} object} +\examples{ +don.mois1 <- read.csv2(file = system.file("/import/Tel_extrait.csv", package = "caschrono"), + col.names = c("Date.app", "Heur.deb.app", "Code Dest", "Dest Det","Dur app sec.", + "Mont app EU"), skip = 0, stringsAsFactors = FALSE) +} +\keyword{datasets} diff --git a/man/acf2y.rd b/man/acf2y.rd old mode 100644 new mode 100755 index 9b69dbd..8d1e21e --- a/man/acf2y.rd +++ b/man/acf2y.rd @@ -1,30 +1,30 @@ -\name{acf2y} -\alias{acf2y} -\title{Plots of the ACF and PACF of a time series} -\description{Plots of the ACF and PACF at the same lags} -\usage{ -acf2y(y, lag.max=40, numer=TRUE) -} -\arguments{ - \item{y}{A time series object} - \item{lag.max}{An integer, the maximum lag} - \item{numer}{A boolean; if TRUE the ACF and PACF are printed} -} -\details{ -The ACF and PACF are plotted with the same scale.} - -\value{ -if numer=TRUE, it returns the values of ACF and PACF for each lag -} - -\author{Yves Aragon, Thibault Laurent} -\seealso{\code{\link{xy.acfb}}} - -\references{Shumway R. and Stoffer D., Time Series Analysis and Its Applications - With R Examples, 2nd ed., 2006, -Springer.} - -\examples{ -data("nottem") -acf2y(nottem) -} -\keyword{ts} +\name{acf2y} +\alias{acf2y} +\title{Plots of the ACF and PACF of a time series} +\description{Plots of the ACF and PACF at the same lags} +\usage{ +acf2y(y, lag.max = 40, numer = TRUE) +} +\arguments{ + \item{y}{A time series object} + \item{lag.max}{An integer, the maximum lag} + \item{numer}{A boolean; if TRUE the ACF and PACF are printed} +} +\details{ +The ACF and PACF are plotted with the same scale.} + +\value{ +if numer=TRUE, it returns the values of ACF and PACF for each lag +} + +\author{Yves Aragon, Thibault Laurent} +\seealso{\code{\link{xy.acfb}}} + +\references{Shumway R. and Stoffer D., Time Series Analysis and Its Applications - With R Examples, 2nd ed., 2006, +Springer.} + +\examples{ +data("nottem") +acf2y(nottem) +} +\keyword{ts} diff --git a/man/armaselect.rd b/man/armaselect.rd old mode 100644 new mode 100755 diff --git a/man/caschrono-package.Rd b/man/caschrono-package.Rd old mode 100644 new mode 100755 index 297e33a..d9c05e1 --- a/man/caschrono-package.Rd +++ b/man/caschrono-package.Rd @@ -6,15 +6,14 @@ Series Temporelles Avec R } \description{ -Functions, data sets and exercises solutions for the book 'Series temporelles avec R' (Yves Aragon, -edp sciences, 2016). For all chapters, a vignette is available with some additional material and exercises solutions. +Functions, data sets and exercises solutions for the book 'Series temporelles avec R' (Yves Aragon, edp sciences, 2016). For all chapters, a vignette is available with some additional material and exercises solutions. } \details{ \tabular{ll}{ Package: \tab caschrono\cr Type: \tab Package\cr -Version: \tab 2.2\cr -Date: \tab 2020-05-12\cr +Version: \tab 2.3\cr +Date: \tab 2022-11-14\cr License: \tab GPL2\cr LazyLoad: \tab yes\cr } diff --git a/man/champa.ts.Rd b/man/champa.ts.Rd old mode 100644 new mode 100755 index 2fa82ac..76b4370 --- a/man/champa.ts.Rd +++ b/man/champa.ts.Rd @@ -1,19 +1,20 @@ -\name{champa.ts} -\alias{champa.ts} -\docType{data} -\title{Monthly shipments of bottles of champagne for the period 2001-2010} -\description{ -The file "/import/champagne_2001.txt" contains monthly total shipping of 75 cl bottles of Champagne wine, in the world. 2001-2010. -} -\format{The series first is imported as a vector of numeric type with function \code{scan} - and then transformed into a \code{ts} object. Is is then converted in 1,000 of bottles.} -\source{SRISE-DRAAF Champagne-Ardenne} -\examples{ -data("champa.ts") -# The executed code is : -## Not run: -aa <- scan(system.file("/import/champagne_2001.txt", package = "caschrono")) -champa.ts <- ts(aa/1000, start = c(2001,1), frequency = 12) -## End(Not run) -} -\keyword{datasets} +\name{champa.ts} +\alias{champa.ts} +\docType{data} +\title{Monthly shipments of bottles of champagne for the period 2001-2010} +\description{ +The file "/import/champagne_2001.txt" contains monthly total shipping of 75 cl bottles of Champagne wine, in the world. 2001-2010. +} +\format{The series first is imported as a vector of numeric type with function \code{scan} + and then transformed into a \code{ts} object. Is is then converted in 1,000 of bottles.} + +\source{SRISE - DRAAF Champagne-Ardenne} +\examples{ +data("champa.ts") +# The executed code is : +## Not run: +aa <- scan(system.file("/import/champagne_2001.txt", package = "caschrono")) +champa.ts <- ts(aa/1000, start = c(2001,1), frequency = 12) +## End(Not run) +} +\keyword{datasets} diff --git a/man/cor.arma.rd b/man/cor.arma.rd old mode 100644 new mode 100755 diff --git a/man/csdl.rd b/man/csdl.rd old mode 100644 new mode 100755 index fa4ee5a..b525a90 --- a/man/csdl.rd +++ b/man/csdl.rd @@ -1,29 +1,29 @@ -\name{csdl} -\alias{csdl} -\docType{data} -\title{French stock and returns} -\description{ -French stocks (Cac40, Société générale, Danone, L'Oréal) for the period 2006 - 2009, on Euronext Paris.} -\usage{data(csdl)} -\format{This \code{its} object contains the following firms close prices: -\itemize{ -\item \code{Cac40}, ^FCHI (name of the quote symbol), common used French stock market index -\item \code{Socgen}, GLE.PA (name of the quote symbol), Société générale -\item \code{Danone}, BN.PA (name of the quote symbol), Danone -\item \code{L_Oreal}, OR.PA (name of the quote symbol), L'Oréal -} -from 2006-01-02 to 2009-06-30.} - -\source{http://fr.finance.yahoo.com/} -\examples{ -if(require("timeSeries")){ -data(csdl) -# we create then the returns -aa = returns(csdl, percentage = TRUE) -aab <- aa[complete.cases(aa) == TRUE,] -# in previous version we use package its which will not be maintained anymore -# r.csdl = its(aab, as.POSIXct(row.names(aab))) -r.csdl = zoo(aab, as.POSIXct(row.names(aab))) -} -} -\keyword{datasets} +\name{csdl} +\alias{csdl} +\docType{data} +\title{French stock and returns} +\description{ +French stocks (Cac40, SG, Danone, L'Oreal) for the period 2006 - 2009, on Euronext Paris.} +\usage{data(csdl)} +\format{This \code{its} object contains the following firms close prices: +\itemize{ +\item \code{Cac40}, ^FCHI (name of the quote symbol), common used French stock market index +\item \code{Socgen}, GLE.PA (name of the quote symbol), SG +\item \code{Danone}, BN.PA (name of the quote symbol), Danone +\item \code{L_Oreal}, OR.PA (name of the quote symbol), L'Oreal +} +from 2006-01-02 to 2009-06-30.} + +\source{http://fr.finance.yahoo.com/} +\examples{ +if(require("timeSeries")){ +data(csdl) +# we create then the returns +aa <- returns(csdl, percentage = TRUE) +aab <- aa[complete.cases(aa) == TRUE,] +# in previous version we use package its which will not be maintained anymore +# r.csdl = its(aab, as.POSIXct(row.names(aab))) +r.csdl <- zoo(aab, as.POSIXct(row.names(aab))) +} +} +\keyword{datasets} diff --git a/man/essil.rd b/man/essil.rd old mode 100644 new mode 100755 diff --git a/man/indbourse.rd b/man/indbourse.rd old mode 100644 new mode 100755 diff --git a/man/khct.rd b/man/khct.rd old mode 100644 new mode 100755 index a006945..ca4051b --- a/man/khct.rd +++ b/man/khct.rd @@ -1,34 +1,32 @@ -\name{khct} -\alias{khct} -\docType{data} -\title{Monthly electricity comsumption for the period 1970-1984} -\description{ -Monthly electricity consumption, heating degree days and cooling degree days in some region for the period 1970-1984.} -\value{\code{csdl} is a multivariate \code{ts} object which contains: - \item{kwh}{electricity consumption in kilo-watt-hours} - \item{htdd}{heating degree days, in Fahrenheit degrees} - \item{cldd}{cooling degree days, in Fahrenheit degrees} -} -\details{ -\code{htdd} (heating degree days) is minus the sum over the month of the daily difference between the average daily temperature, -if it is lower than 65 F. degrees, and 65 F. degrees, the equilibrium temperature above which a house does not need to be heated. \cr -\code{cldd} (cooling degree days) is the sum over the month of the daily difference between the average daily temperature, -if it is greater than 65 F. degrees, and 65, the equilibrium temperature above which air conditioning is switched on. \cr -The dataset is from the book by Pankratz (1981). -} -\usage{data(csdl)} -\source{Pankratz A., Forecasting with dynamic regression models, 1991, Wiley.} -\examples{ -data(khct) -# The executed code is : -## Not run: -khct = read.csv2(file= system.file("/import/conselec.csv",package="caschrono")) -attach(khct) -khc = ts(cbind(kwh, htdd,cldd), frequency = 12, start=c(1970,1)) -kwh = khc[,1] -htdd = khc[,2] -cldd = khc[,3] -temps = time(kwh) -## End(Not run) -} -\keyword{datasets} +\name{khct} +\alias{khct} +\docType{data} +\title{Monthly electricity comsumption for the period 1970-1984} +\description{ +Monthly electricity consumption, heating degree days and cooling degree days in some region for the period 1970-1984.} +\value{\code{csdl} is a multivariate \code{ts} object which contains: + \item{kwh}{electricity consumption in kilo-watt-hours} + \item{htdd}{heating degree days, in Fahrenheit degrees} + \item{cldd}{cooling degree days, in Fahrenheit degrees} +} +\details{ +\code{htdd} (heating degree days) is minus the sum over the month of the daily difference between the average daily temperature, if it is lower than 65 F. degrees, and 65 F. degrees, the equilibrium temperature above which a house does not need to be heated. \cr +\code{cldd} (cooling degree days) is the sum over the month of the daily difference between the average daily temperature, if it is greater than 65 F. degrees, and 65, the equilibrium temperature above which air conditioning is switched on. \cr +The dataset is from the book by Pankratz (1991). +} +\usage{data(csdl)} +\source{Pankratz A., Forecasting with dynamic regression models, 1991, Wiley.} +\examples{ +data(khct) +# The executed code is : +## Not run: +khct = read.csv2(file= system.file("/import/conselec.csv",package="caschrono")) +attach(khct) +khc = ts(cbind(kwh, htdd,cldd), frequency = 12, start=c(1970,1)) +kwh = khc[,1] +htdd = khc[,2] +cldd = khc[,3] +temps = time(kwh) +## End(Not run) +} +\keyword{datasets} diff --git a/man/lait.Rd b/man/lait.Rd old mode 100644 new mode 100755 index bd05d75..049f444 --- a/man/lait.Rd +++ b/man/lait.Rd @@ -1,13 +1,12 @@ -\name{lait} -\alias{lait} -\docType{data} -\title{Milk collection in France} -\description{\code{lait} is the monthly milk collection in France, January 1980 - January 2010} -\format{\code{lait} is a \code{ts} object} -\details{Data are expressed in thousands of tons} -\source{Enquête laitière mensuelle - Service de la Statistique et de la Prospective (SSP) - Ministère de l'Alimentation, -de l'Agriculture et de la Pêche.} -\examples{ -data(lait) -} -\keyword{datasets} +\name{lait} +\alias{lait} +\docType{data} +\title{Milk collection in France} +\description{\code{lait} is the monthly milk collection in France, January 1980 - January 2010} +\format{\code{lait} is a \code{ts} object} +\details{Data are expressed in thousands of tons} +\source{Service de la Statistique et de la Prospective (SSP) - French Ministery de l'Alimentation, de l'Agriculture et de la Peche.} +\examples{ +data(lait) +} +\keyword{datasets} diff --git a/man/m30.Rd b/man/m30.Rd old mode 100644 new mode 100755 index 9b642bf..54664dc --- a/man/m30.Rd +++ b/man/m30.Rd @@ -1,18 +1,18 @@ -\name{m30} -\alias{m30} -\docType{data} -\title{Fatalities in car accidents in France for the period 1973-2006} -\description{ -\code{m30} is the series of monthly fatalities in car accidents in France for the period 1973-2006.} -\usage{data(m30)} -\format{Time series data} -\details{The data from July 1973 to December 2004 have been multiplied by 1.069 to take -into account the change of the definition of a fatal accident. -Until 2004, an accident is fatal if death occurs within 6 days whereas from -2006 the deadline moves to 30 days. -} -\source{http://www.securite-routiere.org/Fiches/statistiques/statmensuelles.htm} -\examples{ -data(m30) -} -\keyword{datasets} +\name{m30} +\alias{m30} +\docType{data} +\title{Fatalities in car accidents in France for the period 1973-2006} +\description{ +\code{m30} is the series of monthly fatalities in car accidents in France for the period 1973-2006.} +\usage{data(m30)} +\format{Time series data} +\details{The data from July 1973 to December 2004 have been multiplied by 1.069 to take +into account the change of the definition of a fatal accident. +Until 2004, an accident is fatal if death occurs within 6 days whereas from +2006 the deadline moves to 30 days. +} +\source{http://www.securite-routiere.org/} +\examples{ +data(m30) +} +\keyword{datasets} diff --git a/man/plot2acf.Rd b/man/plot2acf.Rd old mode 100644 new mode 100755 index 94b7c57..5460827 --- a/man/plot2acf.Rd +++ b/man/plot2acf.Rd @@ -1,31 +1,31 @@ -\name{plot2acf} -\alias{plot2acf} -\title{ACF plots of two series} -\description{Plots the ACF of two series at the same lags} -\usage{ -plot2acf(y1, y2, lag.max=40, main=c("","")) -} -\arguments{ - \item{y1}{A time series object} - \item{y2}{A time series object} - \item{lag.max}{An integer, the value of the maximum lag} - \item{main}{A vector of character, the title of the plot} -} -\details{ -We keep the same scale for the two graphs} - -\value{ -no value -} - -\author{Yves Aragon and Thibault Laurent} - -\examples{ -data(nottem) -set.seed(2561) -innov1 = rnorm(290,sd=4.18) -y = arima.sim(list(order = c(12,0,1), ma=-.7, ar=c(rep(0,11),.9)), -innov =innov1, n.start =50, n = 240) + 50 -plot2acf(nottem, y, main=c("ACF nottem","ACF SAR")) -} -\keyword{ts} +\name{plot2acf} +\alias{plot2acf} +\title{ACF plots of two series} +\description{Plots the ACF of two series at the same lags} +\usage{ +plot2acf(y1, y2, lag.max = 40, main = c("", "")) +} +\arguments{ + \item{y1}{A time series object} + \item{y2}{A time series object} + \item{lag.max}{An integer, the value of the maximum lag} + \item{main}{A vector of character, the title of the plot} +} +\details{ +We keep the same scale for the two graphs} + +\value{ +no value +} + +\author{Yves Aragon and Thibault Laurent} + +\examples{ +data(nottem) +set.seed(2561) +innov1 <- rnorm(290,sd=4.18) +y <- arima.sim(list(order = c(12, 0, 1), ma = -.7, ar = c(rep(0, 11), .9)), + innov = innov1, n.start = 50, n = 240) + 50 +plot2acf(nottem, y, main = c("ACF nottem", "ACF SAR")) +} +\keyword{ts} diff --git a/man/plotacfthemp.rd b/man/plotacfthemp.rd old mode 100644 new mode 100755 index efaf05a..da8143c --- a/man/plotacfthemp.rd +++ b/man/plotacfthemp.rd @@ -1,29 +1,29 @@ -\name{plotacfthemp} -\alias{plotacfthemp} -\title{Plots the ACF and PACF of a theoretical ARMA model and the empirical ACF and PACF of an observed series} -\description{\code{plotacfthemp} plots the ACF and PACF of a theoretical ARMA model and the empirical ACF and PACF of an observed series.} -\usage{ -plotacfthemp(y, ar = numeric(0), ma = numeric(0), lag.max = 20, titre="") -} -\arguments{ - \item{y}{time series, a \code{ts} object} - \item{ar}{numeric vector of AR coefficients} - \item{ma}{numeric vector of MA coefficients} - \item{lag.max}{integer, Maximum lag required.} - \item{titre}{a string of characters for the title} - } -\details{This function uses the \code{ARMAacf} and \code{acf} functions to -compute theoritical and empirical ACF and PACF} -\value{ -No values -} - -\author{Yves Aragon and Thibault Laurent} - -\examples{ -set.seed(951) -ya <- arima.sim(n=200, list(ma = c(-0.3, 0.6)), -sd = sqrt(1.5)) -plotacfthemp(ya, ma=c(-0.3,0.6), titre="MA(2)") -} -\keyword{ts} +\name{plotacfthemp} +\alias{plotacfthemp} +\title{Plots the ACF and PACF of a theoretical ARMA model and the empirical ACF and PACF of an observed series} +\description{\code{plotacfthemp} plots the ACF and PACF of a theoretical ARMA model and the empirical ACF and PACF of an observed series.} +\usage{ +plotacfthemp(y, ar = numeric(0), ma = numeric(0), lag.max = 20, titre = "") +} +\arguments{ + \item{y}{time series, a \code{ts} object} + \item{ar}{numeric vector of AR coefficients} + \item{ma}{numeric vector of MA coefficients} + \item{lag.max}{integer, Maximum lag required.} + \item{titre}{a string of characters for the title} + } +\details{This function uses the \code{ARMAacf} and \code{acf} functions to +compute theoritical and empirical ACF and PACF} +\value{ +No values +} + +\author{Yves Aragon and Thibault Laurent} + +\examples{ +set.seed(951) +ya <- arima.sim(n=200, list(ma = c(-0.3, 0.6)), +sd = sqrt(1.5)) +plotacfthemp(ya, ma=c(-0.3,0.6), titre="MA(2)") +} +\keyword{ts} diff --git a/man/popfr.Rd b/man/popfr.Rd old mode 100644 new mode 100755 index 526df85..6c93489 --- a/man/popfr.Rd +++ b/man/popfr.Rd @@ -1,15 +1,14 @@ -\name{popfr} -\alias{popfr} -\docType{data} -\title{French population for the period 1846-1951} -\description{ -\code{popfr} is the French population average for the period 1846-1951.} -\usage{data(popfr)} -\format{Time series data} -\details{One unit: 1,000 inhabitants. Two missing values in 1916 and 1941} -\source{http://www.insee.fr/fr/themes/tableau.asp?ref_id=NATnon02145 \cr -http://dev-www.ined.fr/fr/pop_chiffres/france/structure_population/recensement_1846/} -\examples{ -data(popfr) -} -\keyword{datasets} +\name{popfr} +\alias{popfr} +\docType{data} +\title{French population for the period 1846-1951} +\description{ +\code{popfr} is the French population average for the period 1846-1951.} +\usage{data(popfr)} +\format{Time series data} +\details{One unit: 1,000 inhabitants. Two missing values in 1916 and 1941} +\source{https://www.insee.fr/fr/statistiques} +\examples{ +data(popfr) +} +\keyword{datasets} diff --git a/man/t_stat.rd b/man/t_stat.rd old mode 100644 new mode 100755 index fc52cf7..0577572 --- a/man/t_stat.rd +++ b/man/t_stat.rd @@ -3,14 +3,13 @@ \title{Arima coefficients tests} \description{It computes the t-statistics tests for the coefficients of an Arima model} \usage{ -t_stat(modarima, decim=6) +t_stat(modarima, decim = 6) } \arguments{ \item{modarima}{an \code{Arima} object} \item{decim}{an integer, the precision of the results} } -\details{\code{modarima} may be created with the function \code{Arima} (package \code{forecast}) -or \code{arimax} (package TSA)} +\details{\code{modarima} may be created with the function \code{Arima} (package \code{forecast}) or \code{arimax} (package TSA)} \value{ It returns a matrix 2 x (number of free coefficients) of the t-statistics and the p-values. } diff --git a/man/trafmensu.rd b/man/trafmensu.rd old mode 100644 new mode 100755 diff --git a/man/xy.acfb.rd b/man/xy.acfb.rd old mode 100644 new mode 100755 diff --git a/vignettes/Anx1.Rnw b/vignettes/Anx1.Rnw old mode 100644 new mode 100755 diff --git a/vignettes/Anx10.Rnw b/vignettes/Anx10.Rnw old mode 100644 new mode 100755 diff --git a/vignettes/Anx12.Rnw b/vignettes/Anx12.Rnw old mode 100644 new mode 100755 index c3a89eb..97f59c2 --- a/vignettes/Anx12.Rnw +++ b/vignettes/Anx12.Rnw @@ -508,7 +508,7 @@ du r\'esidu du premier ajustement. Tout d'abord, nous r\'eestimons le mod\`ele A {\small <>= -# require(fBasics) +require(fBasics) data(csdl) aa = returns(csdl, percentage = TRUE) aab = aa[complete.cases(aa) == TRUE,] @@ -582,8 +582,8 @@ puis par la mod\'elisation ARMA. {\small <>= par(oma=rep(0.5,4)) -mat.lor = cbind(binf.arima.lor,bsup.arima.lor, - binf.garch.lor, bsup.garch.lor, r.lor.1[1:npred]) +mat.lor = cbind(binf.arima.lor, bsup.arima.lor, + binf.garch.lor, bsup.garch.lor, as.numeric(r.lor.1[1:npred])) matplot(1:npred,mat.lor, type = "l", col = "black", lty = c(1, 1, 2, 2, 3), lwd = 2, xlab = "horizon 50", ylab = "rendement") @@ -684,9 +684,9 @@ puis par la mod\'elisation ARMA. {\small <>= -par(oma=rep(0.5,4)) +par(oma=rep(0.5, 4)) mat.dan = cbind(binf.arima.dan, bsup.arima.dan, - binf.garch.dan, bsup.garch.dan, r.dan.1[1:npred]) + binf.garch.dan, bsup.garch.dan, as.numeric(r.dan.1[1:npred])) matplot(1:npred, mat.dan, type = "l", col = "black", lty = c(1, 1, 2, 2, 3), lwd = 2, xlab = "horizon 50", ylab = "rendement") diff --git a/vignettes/Anx2.Rnw b/vignettes/Anx2.Rnw old mode 100644 new mode 100755 diff --git a/vignettes/Anx3.Rnw b/vignettes/Anx3.Rnw old mode 100644 new mode 100755 diff --git a/vignettes/Anx4.Rnw b/vignettes/Anx4.Rnw old mode 100644 new mode 100755 index 0fd014a..7e64902 --- a/vignettes/Anx4.Rnw +++ b/vignettes/Anx4.Rnw @@ -290,10 +290,10 @@ ARMAtoMA(c(rep(0, 11), -.7), 0, 25) @ } -Par \code{ImpulseCoefficientsARMA()} de \pkg{FitARMA} : +Par \code{ImpulseCoefficientsARMA()} de \pkg{FitARMA} (Attention, le package \pkg{FitARMA} n'est plus maintenu sur le CRAN) {\small -<<>>= +<>= require(FitARMA) ImpulseCoefficientsARMA(-.7, 0, lag.max = 10) ImpulseCoefficientsARMA(c(rep(0, 11), -.7), 0, lag.max = 25) @@ -449,9 +449,10 @@ et calculer la PACF empirique jusqu'au retard 4. Comparer avec l'exemple pr\'ec\ D'autre part nous effectuons \code{nsim} simulations pour comparer la pr\'ecision de l'estimateur et nous superposons valeur th\'eorique et quantile empirique d'ordres .25 et .75 pour chaque retard : +(Attention, le package \pkg{FitARMA} n'est plus maintenu sur le CRAN, mais il est disponible sur Github https://github.com/cran/FitARMA) {\small -<>= +<>= require(FitARMA) set.seed(51) nsim <- 100 @@ -479,7 +480,7 @@ aaa <- cbind(aa, pacf.theo, binf, bsup) @ } \code{binf} et \code{bsup} d\'efinissent la bande de confiance asymptotique, valable \'evidemment \`a partir du retard 3, voir la propri\'et\'e 4.6, alors que les quantiles -d'ordres .25 et .75, matrice \code{aa}, donnent les quantiles empiriques d'apr\`es les \Sexpr{nsim} simulations. +d'ordres .25 et .75, matrice \code{aa}, donnent les quantiles empiriques d'apr\`es les 50 simulations. On obtient le graphique (fig. \ref{matplot}) pour 50 simulations par @@ -505,7 +506,7 @@ legend("topright", paste("nombre de simulations : ", \begin{figure}[htbp] \begin{center} -<>= +<>= <> <> <> @@ -589,7 +590,7 @@ par \code{arima.sim()}. \textbf{R\'eponse.} {\small -<<>>= +<< eval = F>>= theo <- TacvfARMA(theta = c(.3, -.6), lag.max = 20) (acf.theo <- theo[-1]/theo[1]) (pacf.theo <- PacfDL(theo/theo[1], LinearPredictor = TRUE)$Pacf) @@ -614,7 +615,7 @@ R\'epondre pour ce mod\`ele, aux questions de l'exercice pr\'ec\'edent. \textbf{R\'eponse.} {\small -<<>>= +<< eval = F>>= theo <- TacvfARMA(phi = -.8, lag.max = 20) (acf.theo <- theo[-1]/theo[1]) (pacf.theo <- PacfDL(theo/theo[1], LinearPredictor = TRUE)$Pacf) diff --git a/vignettes/Anx5.Rnw b/vignettes/Anx5.Rnw old mode 100644 new mode 100755 diff --git a/vignettes/Anx6.Rnw b/vignettes/Anx6.Rnw old mode 100644 new mode 100755 diff --git a/vignettes/Anx7.Rnw b/vignettes/Anx7.Rnw old mode 100644 new mode 100755 diff --git a/vignettes/Anx9.Rnw b/vignettes/Anx9.Rnw old mode 100644 new mode 100755 diff --git a/vignettes/pratiquer.sty b/vignettes/pratiquer.sty old mode 100644 new mode 100755