[R] gls prediction using the correlation structure in nlme
Dr Carbon
drcarbon at gmail.com
Wed Jan 28 18:51:29 CET 2009
How does one coerce predict.gls to incorporate the fitted correlation
structure from the gls object into predictions? In the example below
the AR(1) process with phi=0.545 is not used with predict.gls. Is
there another function that does this? I'm going to want to fit a few
dozen models varying in order from AR(1) to AR(3) and would like to
look at the fits with the correlation structure included.
Thanks in advance.
-JC
PS I am including the package maintainers on this post - does this
constitute a maintainer-specific question in r-help etiquette?
# example
set.seed(123)
x <- arima.sim(list(order = c(1,0,0), ar = 0.7), n = 100)
y <-x + arima.sim(list(order = c(1,0,0), ar = 0.7), n = 100)
x <- c(x)
y <- c(y)
lm1 <- lm(y~x)
ar(residuals(lm1)) # indicates an ar1 model
cs1 <- corARMA(p=1)
fm1 <- gls(y~x,corr=cs1)
summary(fm1)
# get fits
fits <- predict(fm1)
# use coef to get fits
fits2 <- coef(fm1)[1] + (coef(fm1)[2] * x)
plot(fits,fits2)
More information about the R-help
mailing list