Eric Elguero
2014-Jan-09 14:47 UTC
[R] transmission of parameters to the glmmadmb function
Hi everybody, I wrote a function where several variables are created, and the used in a generalized mixed model, from the glmmADMB package. here is part of the function: <deleted lines where ni, spx and spy are created> print(length(spy)) uu<-summary(glmmadmb(spy~sex+poswing+spx+(1|host),data=ni, family="nbinom",zeroInflation=True)) when I run the function I get [1] 596 Error in eval(expr, envir, enclos) : object 'spy' not found (so spy is known to the function "print" but not to the function glmmadmb) now I modify my function: <deleted lines where ni, spx and spy are created> print(length(spy)) ni$spy<-spy ni$spx<-spx uu<-summary(glmmadmb(spy~sex+poswing+spx+(1|host),data=ni, family="nbinom",zeroInflation=True)) and that works. however, when I call glmmadmb interactively, it accepts in the formula variables which are in the dataframe specified by the 'data' argument, as well as variables which are not. and if in my function I replace glmmadmb by glm it works even if spy and spx are not in the 'ni' dataframe. that puzzles me.
David Winsemius
2014-Jan-09 20:49 UTC
[R] transmission of parameters to the glmmadmb function
On Jan 9, 2014, at 9:47 AM, Eric Elguero wrote:> Hi everybody, > > I wrote a function where several variables > are created, and the used in a generalized > mixed model, from the glmmADMB package. > > here is part of the function: > > <deleted lines where ni, spx and spy are created> > print(length(spy)) > > uu<-summary(glmmadmb(spy~sex+poswing+spx+(1|host),data=ni, > family="nbinom",zeroInflation=True)) > > when I run the function I get > > [1] 596 > Error in eval(expr, envir, enclos) : object 'spy' not found > > (so spy is known to the function "print" but not > to the function glmmadmb)I would have thought you should ask: length(ni$spy) glmmadmb should be looking within the data object passed to it. -- David.> > > now I modify my function: > > <deleted lines where ni, spx and spy are created> > print(length(spy)) > > ni$spy<-spy > ni$spx<-spx > > uu<-summary(glmmadmb(spy~sex+poswing+spx+(1|host),data=ni, > family="nbinom",zeroInflation=True)) > > and that works. > > however, when I call glmmadmb interactively, it > accepts in the formula variables which are in > the dataframe specified by the 'data' argument, > as well as variables which are not. > > and if in my function I replace glmmadmb by glm > it works even if spy and spx are not in the 'ni' > dataframe.Those function must be different. Get over it. Learn to pass the data in a common object.> > that puzzles me. > > _David Winsemius, MD Alameda, CA, USA