# ACF function confidence intervals

I'm using the acf function with the modifier type = 'covariance'

When I use the modifier, it gets rid of the confidence intervals. How can I add them back into the acf function while maintaining the covariance modifier?

Thanks!

Welcome, @marymil! It is going to be easier for folks around here to help if you include a sample of your data as well as the code you've used to get to where you are stuck. Without knowing the structure of the data or what you've already tried, it's very hard to help.

See this post for more information about best practices for writing questions and including a reproducible example (reprex).

1 Like

I looked through some of the code for `plot.acf()` and if I'm reading things correctly I don't think the function makes confidence intervals for covariances.

To look at the underlying code I ran `stats:::plot.acf` in my Console. This is the function that plots the output of `acf()`, and it is this function that controls the creation and display of any confidence intervals.

Here are the lines that I thought were relevant.
First, a logical vector based on what type of acf being computed (which is `FALSE` if the `type` is covariance):

`with.ci <- ci < 0 && x\$type != "covariance"`

Then the calculation of initial confidence interval limits based on the logical vector above. Looks like if the result is `FALSE` this returns `c(0, 0)`, which is why I think you don't get CI for covariances.

``````clim0 <- if (with.ci)
qnorm((1 + ci)/2)/sqrt(x\$n.used)
else c(0, 0)
``````

There is a lot more code in the function so I could have missed something, but I didn't see anything else where the function built CI for covariances.

If you know how to calculate a confidence interval for a covariance you could potentially add these on to the plot via `lines()`, since `plot.acf` is built on base R plotting functions.

2 Likes

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.