Unit 25 AR(p) forecast math
ˆXt0(ℓ)=ϕ1ˆXt0(ℓ−1)+...+ϕpˆXt0(ℓ−p)+ˉX(1−ϕ1−...−ϕp))
25.1 AR(p) forecasts:
arpgen <- function(vec, l, mu, phi) {
v <- vec[length(vec):(length(vec) - (length(phi) - 1))]
f <- sum(phi * (v)) + mu * (1 - sum((phi)))
if (l == 1)
return(f)
return(arpgen(append(vec, f), l - 1, mu, phi))
}
arp <- function(vec, l, mu, phi) {
as.numeric(lapply(1:l, arpgen, phi = phi, vec = vec, mu = mu))
}
x <- c(27.7, 23.4, 21.2, 21.1, 22.7)
p <- c(1.6, -0.8)
avg <- 29.4
arp(phi = p, vec = x, l = 5, mu = avg)
## [1] 25.32000 28.23200 30.79520 32.56672 33.35059
25.1.1 With tswge
25.1.1.1 positive phi, AR(1)
data(fig6.1nf)
plotts.wge(fig6.1nf)
fore.arma.wge(fig6.1nf, phi = 0.8, n.ahead = 20, limits = F)