Re: [R] GAM quasipoisson in MuMIn - SOLVED
Hi, Got my issues sorted. Error message solved: I heard from the guy who developed MuMIn and his suggestion worked. "As for the error you get, it seems you are running an old version of MuMIn. Please update the package first." I did (I was only 1 version behind in both R and in MuMIn) and error disappeared! Running quasipoisson GAM in MuMIn: As for my questions on GAM and " to include only models with smooth OR linear term (but not both) for each variable", as Gavin said, this refers only to global models with both smooth and linear terms for the *same*variableswhich I didn't have. Regards, Karen On 4 February 2011 12:31, Karen Moore wrote: > > Hi, > > I have a GAM quasipoisson that I'd like to run through MuMIn package > > >- dredge >- gettop.models >- model.avg > > > However, I'm having no luck with script from an example in MuMIn help file. > In MuMIn help they advise "include only models with smooth OR linear term > (but not both) for each variable". Their example is: > > # Example with gam models (based on "example(gam)") > > require(mgcv) > > > > dat <- gamSim(1, n = 500, dist="poisson", scale=0.1) > > > > gam1 <- gam(y ~ s(x0) + s(x1) + s(x2) + s(x3) + (x1+x2+x3)^2, family = > poisson, data = dat, method = "REML") > > > > cat(dQuote(getAllTerms(gam1)), "\n") > > > > > > # include only models with smooth OR linear term (but not both) for each > variable: > > > > > > dd <- dredge(gam1, subset=(!`s(x1)` | !x1) & (!`s(x2)` | !x2) & (!`s(x3)` | > !x3)) > > > But I'm not sure at all how to apply these instructions to my data > > > My formula is > > GAM<-gam(Species richness (count) ~ Categorical + Continous + Continous + > *s*(Continous ) + Continous : Continous + Continous : Continous, > family=quasipoisson, data =) > > > Thanks for any advice on script > > > Karen > > > > > -- Karen Moore PhD Researcher, FORESTBIO, Department of Botany, Trinity College Dublin Ireland Ph: 00 353 (0)87 9422 502 http://www.ucc.ie/en/planforbio [[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.
Re: [R] GAM quasipoisson in MuMIn
Thanks for that Gavin - yeah you're right that was not my actual model, which is: GAMV2c<-gam(VASCSR~ROTATION+ CANCOV +LAreaoldwood+ + s(SOILPH) + CANCOV:LAreaoldwood + CANCOV:SOILPH,family=quasipoisson, data =HIGHBRYOSR) For MMI the script I use, and have used successfully with *exactly* same GAM with a poisson distribution, is: - ddGAMV2c<-dredge(GAMV2c) - ddGAMV2c The above 2 steps run fine - top.models4_GAMV2c<-get.models(ddGAMV2c, subset = delta <= 4, method="REML") So after request for "top.models" I get error * Error in update.formula(formula(object), formula.) : formula expected* And this is were I'm stumbling. I also tried - bestGAMV2c <- get.models(ddGAMV2c, cumsum(weight) <= .95) *Error in update.formula(formula(object), formula.) : formula expected* Again any help with this would be much appreciated as out of the 4 models I'm running through MMI for my data this is only one giving me problems (again all of the above script works fine with *exactly* same GAM model with a poisson distribution!) Regards, Karen On 4 February 2011 12:47, Gavin Simpson wrote: > On Fri, 2011-02-04 at 12:31 +, Karen Moore wrote: > > Hi, > > > > > My formula is > > > > GAM<-gam(Species richness (count) ~ Categorical + Continous + Continous > + * > > s*(Continous ) + Continous : Continous + Continous : Continous, > > family=quasipoisson, data =) > > Ok, I'm reasonably certain that that is *not* your gam() call. Why not > post the *actual* code you would enter for your GAM model? > > dd <- dredge(GAM) > > should evaluate all possible models from the global model you specified. > The example you quote is for a global model with both smooth and linear > terms for the same variables, hence in dredge() they need to select > models that include only the smooth for a particular variable or the > linear term for that variable, but not both. > > By the looks of it, you don't have this problem. > > G > > > > > Thanks for any advice on script > > > > > > Karen > > > > [[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. > > -- > %~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~% > Dr. Gavin Simpson [t] +44 (0)20 7679 0522 > ECRC, UCL Geography, [f] +44 (0)20 7679 0565 > Pearson Building, [e] gavin.simpsonATNOSPAMucl.ac.uk > Gower Street, London [w] > http://www.ucl.ac.uk/~ucfagls/<http://www.ucl.ac.uk/%7Eucfagls/> > UK. WC1E 6BT. [w] http://www.freshwaters.org.uk > %~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~% > > > -- Karen Moore PhD Researcher, FORESTBIO, Department of Botany, Trinity College Dublin Ireland Ph: 00 353 (0)87 9422 502 http://www.ucc.ie/en/planforbio [[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.
[R] GAM quasipoisson in MuMIn
Hi, I have a GAM quasipoisson that I'd like to run through MuMIn package - dredge - gettop.models - model.avg However, I'm having no luck with script from an example in MuMIn help file. In MuMIn help they advise "include only models with smooth OR linear term (but not both) for each variable". Their example is: # Example with gam models (based on "example(gam)") require(mgcv) dat <- gamSim(1, n = 500, dist="poisson", scale=0.1) gam1 <- gam(y ~ s(x0) + s(x1) + s(x2) + s(x3) + (x1+x2+x3)^2, family = poisson, data = dat, method = "REML") cat(dQuote(getAllTerms(gam1)), "\n") # include only models with smooth OR linear term (but not both) for each variable: dd <- dredge(gam1, subset=(!`s(x1)` | !x1) & (!`s(x2)` | !x2) & (!`s(x3)` | !x3)) But I'm not sure at all how to apply these instructions to my data My formula is GAM<-gam(Species richness (count) ~ Categorical + Continous + Continous + * s*(Continous ) + Continous : Continous + Continous : Continous, family=quasipoisson, data =) Thanks for any advice on script Karen [[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.
[R] Error message: number of items to replace is not a multiple of replacement length
*Warning messages: *appear after dredging global model in MMI and requesting model selection table dd(global model)<-dredge(global model) - runs OK dd(global model) * 1: In x[i] <- value[[j]] : number of items to replace is not a multiple of replacement length* Also at model averaging stage I get this warning top.models4_global model<-get.models(ddglobal model, subset = delta <= 4, method="REML") - runs OK model.avg(top.models4_global model) *Warning message:** In m.resp[-1] == m.resp[[1]] : longer object length is not a multiple of shorter object length * I've checked length() names() str() of data - everything looks OK. I have no missing values. e.g of data from str() below: 'data.frame': 51 obs. of 5 variables: $ BRYOSR : num 7 13 10 3 13 8 4 4 7 10 ... $ CANCOV : num 16.7 36.7 78.4 20 81.7 93.4 43.4 88.4 30 81.7 ... $ SRTTOTCWD : num 0 0 0.4 0 0 0.1 0 0.3 0 0.3 ... $ WELLN : num 3.3 2.4 3.9 3.4 3.6 4.8 4.8 4.6 4.5 3.9 ... $ SiteDISTWOOD: num 800 1001 100 400 1001 ... Model I'm running is GAM with only one smoother on a continous variable (that has non linear relationship with response and 2 interactions and is Poisson distributed (response is count data). Can someone please suggest what else this may be indicating about my data. Thanks, Karen [[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.
[R] Modelling poisson distribution with variance structure
I'm dealing with count data that's nested and has spatial dependence. I ran a glmm in lmer with a random factor for nestedness. Spatial dependence seems to have been accommodated by model. However I can't add a variance strcuture to this model (to accommodate heterogeneity). Is there a model that can have a poisson distribution *AND* a variance structure *AND* have AIC in output (for model comparison and selection)? Some we've looked at that can't: - glmmPQL - can add structures BUT can't have AIC (you can calculate it but it doesn't give correct AIC with this model) - glmm in lme4 (lmer) - won't allow variance structure - gls - can add variance but can't have Poisson Thanks so much, Karen Moore PhD Researcher, FORESTBIO, Department of Botany, Trinity College Dublin Ireland [[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.
[R] Interactions in GAMMs
Hi, I've an issue adding an interaction to a GAMM: My model was of form: gamm1 <- gamm(TOTSR ~ fROT + s(PH) + s(LOI) + s(ASP) + s(SQRT_ELEV) + CANCOV + s(SQRT_TOTCWD) + s(WELLF) + s(WELLN) + s(OLDWDLD) + s(DISTWOOD) + s(Annprec) + s(OLDWDLD:DISTWOOD) + (1|fSITE), family = poisson, data = BIOFOR2) with interaction of s(OLDWDLD:DISTWOOD). However I got this error message below but don't know what it means? (my data is composed of info for 150 plots) #I Warning messages: #2: In OLDWDLD:DISTWOOD : # numerical expression has 150 elements: only the first used #3: In OLDWDLD:DISTWOOD : # numerical expression has 150 elements: only the first used Can anyone offer advice on how to include this interaction in GAMM model? Thanks Karen Moore [[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.