Vernon Visser
2011-Sep-20 12:43 UTC
[R] Problems using predict from GAM model averaging (MuMIn)
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]]
Reasonably Related Threads
- MuMIn - assessing variable importance following model averaging, z-stats/p-values or CI?
- GAM quasipoisson in MuMIn - SOLVED
- GAM quasipoisson in MuMIn
- Model Averaging Help
- [EXTERNAL] Re: NOTE: multiple local function definitions for ?fun? with different formal arguments