Created
June 18, 2019 05:39
-
-
Save josephsdavid/ce782d54e11c771788221a2da914956d to your computer and use it in GitHub Desktop.
R function for basic AR() forecasting
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
arpgen <- function(phi,vec,l,mu){ | |
v <- vec[length(vec):(length(vec)-(length(phi)-1))] | |
f <- sum(phi*(v)) + mu*(1-sum((phi))) | |
if (l==1) return(f) | |
return(arpgen(phi,append(vec,f),l-1,mu)) | |
} | |
arp <- function(phi,vec,l,mu){ | |
as.numeric(lapply(1:l, arpgen, phi = phi, vec = vec, mu = mu)) | |
} | |
# usage | |
x <- c(27.7,23.4,21.2,21.1,22.7) | |
p <- c(1.6,-.8) | |
avg <- 29.4 | |
arp(p,x,5,avg) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment