## --------------------------------------------------------------------------------------- # Example to show how the PACF is calculated set.seed(972) n <- 1000 x <- arima.sim(list(ar=c(0.5,-0.4)), n=n) #acf(x) #pacf(x) library(onlineforecast) D <- lagdf(c(x), 0:50) # A way to calculate the PACF lag.max <- 10 pacf1 <- numeric(lag.max) # First, calculate it with the function val <- pacf(x, lag.max, plot=FALSE) # Then calc on our own for(k in 1:lag.max){ (frml <- pst("k0 ~ 1 + ",pst("k",1:k, collapse=" + "))) fit <- lm(frml, D) pacf1[k] <- fit$coef[pst("k",k)] } ## ----fig.height=0.8*figheight----------------------------------------------------------- # It's very close! pacf1 - val$acf plot(val$acf, type="b", xlab="lag", ylab="PACF") lines(pacf1, type="b", col=2) ## ----acf-nonstat,dev="tikz",echo=FALSE,fig.height=0.9*textheight------------------------ set.seed(29) acf(arima.sim(model = list(ar = 0.6,order=c(1,1,0)),n= 500),type="covariance")