In R, we can run an ACF correlogram of time series and the confidence interval bands will be plotted in light blue. But when I pull the structure of ACF object, I cannot find these values. Does anyone know how to extract the values of the confidence interval bands?
e.g.
List of 6
$ acf : num [1:27, 1, 1] 1 0.06453 -0.06354 0.00213 -0.01324 ...
$ type : chr "correlation"
$ n.used: int 501
$ lag : num [1:27, 1, 1] 0 1 2 3 4 5 6 7 8 9 ...
$ series: chr "tser[i:(i + 500)]"
$ snames: NULL
- attr(*, "class")= chr "acf"
I've had a look at the function and I can't see an easy way to extract the confidence interval. The region is calculated in the plot.acf
function. To see this function, use
getS3method("plot", "acf")
In this function, there is a variable clim
, this is the one you are after. The easiest way is to copy plot.acf
to myplot.acf
, but return the clim
value.
I know this question is super old but if anyone does want the confidence interval values it's just the z-value of the confidence level divided by the sqrt of the number of observations used. In the plot.acf
function this is calculated here:
clim0 <- if (with.ci)
qnorm((1 + ci)/2)/sqrt(x$n.used)
where with.ci
is a logical value indicating if the user wants to plot the confidence intervals or not and ci
is the desired confidence level (e.g. .95, .9, etc...)
EDIT: This is the confidence interval if you assume the lagged values are white noise, if this isn't the case there is a correction you can apply
clim <- clim0 * sqrt(cumsum(c(1, 2 * x$acf[-1, i, j]^2)))
You can read some more about that here
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With