I am trying to run a for-loop in order to create a list/ dataframe object that would give me the set of ACF coefficients that are significantly different to 0 (that are outside of the confidence interval). I am not too sure my for-loop does this, and anyways it gives me the following error message :
Error in if (acf_res$ci[2, i + 1] < acf_res$acf[i + 1] || acf_res$ci[1, :
missing value where TRUE/FALSE needed
Here is my current code, I am working on a univariate time series of electricity production from 1981 to 1999 included in France :
production_periode_1 <-periode_1$`Production brute d'électricité nucléaire (en GWh)`
prod_periode_1 <- ts(periode_1, frequency=12)
prod_periode_1 <- ts(production_periode_1, start=c(1981,1) , end=c(1999,12),
frequency=12)
summary(prod_periode_1)
plot.ts(prod_periode_1)
plot(ts.union(prod_periode_1,log(prod_periode_1)))
acf(prod_periode_1,lag.max=150)
acf(diff(prod_periode_1),lag.max=150)
acf(diff(diff(prod_periode_1,12)),lag.max=150)
pacf(prod_periode_1, lag.max = 250)
pacf(diff(prod_periode_1), lag.max = 250)
pacf(diff(diff(prod_periode_1,12), lag.max = 250))
for (i in 1:228) {
acf_res <- acf(prod_periode_1, lag.max = i, plot = FALSE)
if (acf_res$ci[2, i+1] < acf_res$acf[i+1] || acf_res$ci[1, i+1] > acf_res$acf[i+1]) {
print(paste("Coefficient significatif pour lag", i))
} else {
print(paste("Pas de coefficient significatif pour lag", i))
}
}
Here is the structure of my dataset for reproducibility :
structure(c(36509.514, 34485.002, 33702.518, 31274.906, 30241.116,
31542.381), tsp = c(1981, 1981.41666666667, 12), class = "ts")
I would be grateful for any advice !
acf_res$ciis NULL. Theacf()function returns an object of typeacf. This class does not have a field called "ci". Please see?acfA confidence interval is shown when you plot an object of typeacf. See also: stats.stackexchange.com/questions/211628/…acflike so: stackoverflow.com/questions/14266333/… or by usingAcf(note capital A) from {forecast}.