I am struggling to get GAM model predictions from the top models calculated
using model.avg in the package "MuMIn".

My model looks something like the following:
gamp <- gam(log10(y)~s(x1,bs="tp",k=3)+s(x2,bs="tp",k=3)+
          s(x3,bs="tp",k=3)+s(x4,bs="tp",k=3)+s(x5,bs="tp",k=3)+
          s(x6,bs="tp",k=3)+x7,data=dat, family="gaussian")

I am trying to follow the example given in the help for "predict.averaging":

I can calculate the top models etc. without problem:

dd<-dredge(gamp)
top.models <- get.models(dd, subset=cumsum(weight) <= .95)
mavg<-model.avg(top.models) # get averaged coefficients

I then calculate means of all the data:

newdata <- as.data.frame(lapply(lapply(dat[1:6], mean), rep, 27))

And use the helper function to get my variable of interest at regular
intervals:

# helper function
    nseq <- function(x, len=length(x)) seq(min(x, na.rm=TRUE),max(x,
na.rm=TRUE), length=len)
newdata$x1 <- nseq(dat$x1, nrow(newdata))


The problem comes in when I try do the following:

pred <- cbind(sapply(top.models, predict,
newdata=newdata),averaged=predict(model.avg(top.models), newdata))

I get the following error: "Error in reformulate(allNames) :
  'termlabels' must be a character vector of length at least one"

I think the problem has something to do with the fact that I have used 3
knots in the GAM and therefore I land up with two coefficients for each
factor, but I have no idea how to get around this problem.

-- 
Vernon Visser
Post-doctoral Research Associate
Centre of Excellence for Invasion Biology
Department of Botany and Zoology
Natural Sciences Building
Private Bag X1
University of Stellenbosch
Matieland
7602
South Africa

        [[alternative HTML version deleted]]

______________________________________________
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.

Reply via email to