Hello, As I am relatively new to the R environment this question may be either a) Really simple to answer b) Or I am overlooking something relatively simple. I am trying to add a VarIdent structure to my gam model which is fitting smoothing functions to the time variables year and month for a particular species. When I try to add the varIdent weights to variable Month I get this error returned. Error in model.frame.default(formula = Chel ~ 1 + M + YM + M + YM, weights Vf1, : variable lengths differ (found for '(weights)') Here is the simple code I am using. library(mgcv); library(lattice) library(nlme) Vf1=varIdent(form=~M) Chel2=gam(Chel~s(M, fx=F, bs="tp")+ s(YM, fx=F, bs="tp")+s(M,YM, fx=F, bs="tp"), family=poisson(link="log"), weights=Vf1) # second GAM with interaction M=Month YM=Year Regards, Niall -- View this message in context: http://r.789695.n4.nabble.com/varIdent-error-using-gam-function-in-mgcv-tp2260556p2260556.html Sent from the R help mailing list archive at Nabble.com.
How exactly do you want to define your weights? varIdent returns a varFunc object, not a vector with the same length as the data variables, as required by the gam function. Cheers Joris On Fri, Jun 18, 2010 at 7:35 PM, niallllll <n.mcginty1 at nuigalway.ie> wrote:> > Hello, > > As I am relatively new to the R environment this question may be either > a) Really simple to answer > b) Or I am overlooking something relatively simple. > > I am trying to add a VarIdent structure to my gam model which is fitting > smoothing functions to the time variables year and month for a particular > species. When I try to add the varIdent weights to variable Month I get this > error returned. > > Error in model.frame.default(formula = Chel ~ 1 + M + YM + M + YM, weights > Vf1, ?: > ?variable lengths differ (found for '(weights)') > > Here is the simple code I am using. > library(mgcv); library(lattice) > library(nlme) > Vf1=varIdent(form=~M) > Chel2=gam(Chel~s(M, fx=F, bs="tp")+ s(YM, fx=F, bs="tp")+s(M,YM, fx=F, > bs="tp"), family=poisson(link="log"), weights=Vf1) # second GAM ?with > interaction > > M=Month > YM=Year > > Regards, > Niall > -- > View this message in context: http://r.789695.n4.nabble.com/varIdent-error-using-gam-function-in-mgcv-tp2260556p2260556.html > Sent from the R help mailing list archive at Nabble.com. > > ______________________________________________ > R-help at 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. >-- Joris Meys Statistical consultant Ghent University Faculty of Bioscience Engineering Department of Applied mathematics, biometrics and process control tel : +32 9 264 59 87 Joris.Meys at Ugent.be ------------------------------- Disclaimer : http://helpdesk.ugent.be/e-maildisclaimer.php
On Fri, 2010-06-18 at 10:35 -0700, niallllll wrote:> Hello, > > As I am relatively new to the R environment this question may be either > a) Really simple to answerUse gamm() not gam()> b) Or I am overlooking something relatively simple.Use gamm() not gam() ;-)> I am trying to add a VarIdent structure to my gam model which is fitting > smoothing functions to the time variables year and month for a particular > species. When I try to add the varIdent weights to variable Month I get this > error returned. > > Error in model.frame.default(formula = Chel ~ 1 + M + YM + M + YM, weights > Vf1, : > variable lengths differ (found for '(weights)')In gam(), weights is an argument where you need to specify the numeric prior weights for the observations. If you have n observations then length(weights) == n. varIdent is a variance function from the nlme package. It specifies a variance function, the parameters of which will be estimated as part of the model fitting, but only within a call to lme (and/or nlme I presume). To use it, you'll need to use the gamm() function which will eventually use lme (via glmmPQL in package MASS). Whether this is something you want to do is another matter. I'm not even sure that 'weights' in glm/gam should be used in the way you are trying to; I recall some discussion on this list that weights are for sampling weights, but I may be mis-remembering. Regardless, you can't use varIdent like that in a gam() model. HTH G> Here is the simple code I am using. > library(mgcv); library(lattice) > library(nlme) > Vf1=varIdent(form=~M) > Chel2=gam(Chel~s(M, fx=F, bs="tp")+ s(YM, fx=F, bs="tp")+s(M,YM, fx=F, > bs="tp"), family=poisson(link="log"), weights=Vf1) # second GAM with > interaction > > M=Month > YM=Year > > Regards, > Niall-- %~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~% 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/ UK. WC1E 6BT. [w] http://www.freshwaters.org.uk %~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%
Seemingly Similar Threads
- Dealing with heterogeneity with varComb weights
- Fitting heteroscedastic linear models/ problems with varIdent of nlme
- how to specify starting values in varIdent() of lme()
- Getting intervals for within-group standard errors for each group using nlme and varIdent
- GAMM : how to use a smoother for some levels of a variable, and a linear effect for other levels?