I've included an example below to show one method of how to calculate Bartlett's approximations and add them to a graph of the autocorrelation function.
In the example, I've done things by hand rather than rely on a particular package hence the code is longer than it perhaps need be. I don't claim the code to be efficient, but it does get the correct results.
The results in my example can be compared for accuracy to Figure C1.2. in Case 1 of Pankratz (1983) which uses the same dataset that I've used. Don't worry if you don't have the book because the content of Case 1 is available free to download.
Note that with slight modifications, the code below can be adapted to plot the standard errors on the pacf, which Scortchi has correctly pointed out should equal $n^{-1/2}$.
# Import data from the web
inventories <- scan("http://robjhyndman.com/tsdldata/books/pankratz.dat", skip=5, nlines=5, sep="")
# Calculate sample size and mean
n <- length(inventories)
mean.inventories <- sum(inventories)/n
# Express the data in deviations from the mean
z.bar <- rep(mean.inventories,n)
deviations <- inventories - z.bar
# Calculate the sum of squared deviations from the mean
squaredDeviations <- deviations^2
sumOfSquaredDeviations <-sum(squaredDeviations)
# Create empty vector to store autocorrelation coefficients
r <- c()
# Use a for loop to fill the vector with the coefficients
for (k in 1:n) {
ends <- n - k
starts <- 1 + k
r[k] <- sum(deviations[1:(ends)]*deviations[(starts):(n)])/sumOfSquaredDeviations
}
# Create empty vector to store Bartlett's standard errors
bart.error <- c()
# Use a for loop to fill the vector with the standard errors
for (k in 1:n) {
ends <- k-1
bart.error[k] <- ((1 + sum((2*r[0:(ends)]^2)))^0.5)*(n^-0.5)
}
# Plot the autocorrelation function
plot(r[1:(n/4)],
type="h",
main="Autocorrelation Function",
xlab="Lag",
ylab="ACF",
ylim=c(-1,1),
las=1)
abline(h=0)
# Add Bartlett's standard errors to the plot
lines(2*bart.error[1:(n/4)])
lines(2*-bart.error[1:(n/4)])
After running the code you should see the following plot: