Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
2e3880f
commit dc156f3
Showing
80 changed files
with
696 additions
and
729 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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)) | ||
} |
Oops, something went wrong.