Skip to content
Prev 180825 / 398502 Next

Predicting complicated GAMMs on response scale

On Mon, 2009-05-18 at 11:48 -0700, William Paterson wrote:
Note that p.d doesn't contain Animal. Not sure this is the problem, but
I would have thought you'd need to supply new values of Animal for the
data you wish to predict for in order to get the CAR(1) errors correct.
Is it possible that the model is finding another Animal variable in the
global environment?

I have predicted from several thousand GAMMs containing correlation
structures similar to the way you do above so this does work in general.
If the above change to p.d doesn't work, you'll probably need to speak
to Simon Wood to take this further.

Is mgcv up-to-date? I am using 1.5-5 that was released in the last week
or so.

For example, this dummy example runs without error for me and is similar
to your model

y1 <- arima.sim(list(order = c(1,0,0), ar = 0.5), n = 200, sd = 1)
y2 <- arima.sim(list(order = c(1,0,0), ar = 0.8), n = 200, sd = 3)
x1 <- rnorm(200)
x2 <- rnorm(200)
ind <- rep(1:2, each = 200)
d <- data.frame(Y = c(y1,y2), X = c(x1,x2), ind = ind, time = rep(1:200,
times = 2))
require(mgcv)
mod <- gamm(Y ~ s(X), data = d, corr = corCAR1(form = ~ time | ind),
            weights = varPower(form = ~ time))
p.d <- data.frame(X = rep(seq(min(d$X), max(d$X), len = 20), 2),
                  ind = rep(1:2, each = 20),
                  time = rep(1:20, times = 2))
pred <- predict(mod$gam, newdata = p.d, se = TRUE)

Does this work for you? If not, the above would be a reproducible
example (as asked for in the posting guide) and might help Simon track
down the problem if you are running an up-to-date mgcv.

HTH

G