I want to set up a model with a formula and then run dynlm(formula)
because I ultimately want to loop over a set of formulas (see end of post)
R> form <- gas~price
R> dynlm(form)
Time series regression with "ts" data:
Start = 1959(1), End = 1990(4)
<snip>
Works OK without a Lag term
R> dynlm(gas ~ L(gas,1))
Time series regression with "ts" data:
Start = 1959(2), End = 1990(4)
<snip>
Works OK with a Lag with this type of call
R> form <- gas~L(gas,1)
R> dynlm(form)
Error in merge.zoo(gas, L(gas, 1), retclass = "list", all = FALSE) :
could not find function "L"
Does not work using a predefined formula with a Lag (This type of call
works using dyn$lm from library(dyn))
How do I make the call (or how do I setup form) so that this works in dynlm?
Thanks for any help,
Ron
To be specific the following is an example of what I was attempting to do:
m1 <- gas ~ L(gas,1)
m2 <- gas ~ L(gas,1) + price
m3 <- gas ~ L(gas,1) + price + d(gas)
m4 <- gas ~ L(gas,1) + price + d(gas) + L(d(gas),1)
M <- c(m1,m2,m3,m4)
A <- array(0,c(4,2))
for(i in 1:4){
g <- dynlm(M[[i]]) ## works if use dyn$lm from library(dyn) and use
appropriate m's
A[i,1] <- AIC(g,k=2)
A[i,2] <- AIC(g,k=log(length(fitted(g))))
}
colnames(A) <- c("AIC","BIC")
rownames(A) <- c("m1","m2","m3","m4")
A
--
R. R. Burns
Retired in Oceanside, CA
______________________________________________
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.