t c
2009-Feb-18 07:17 UTC
[R] using stepAIC with negative binomial regression - error message help
Dear List, I am having problems running stepAIC with a negative binomial regression model. I am working with data on manta ray abundance, using 20 predictor variables. Predictors include variables for location (site), time (year, cos and sin of calendar day, length of day, percent lunar illumination), oceanography (sea surface temp mean and std, sea surface height mean and std), weather (cos wind direction, sin wind direction, wind speed, temperature, barometric pressure), and tides (dummy variables for high, falling, low, and rising). So predictors are binary, categorical, and continuous variables. I ran glm.nb to fit my full model containing all first order terms. The model I ran was: glm.nb.full<glm.nb(mantas~site+year+cosday+sinday+daylength+lunarpercent+sstmean+sststd+ sshmean+sshstd+cosdir+sindir+spd+temp+alt+tideht+high+falling+low+plankton) However, when I use stepAIC on the model I get the message:> stepAIC(glm.nb.full)Start: AIC=19240.46 mantas ~ site + year + cosday + sinday + daylength + lunarpercent + sstmean + sststd + sshmean + sshstd + cosdir + sindir + spd + temp + alt + tideht + high + falling + low + plankton Error in dropterm.default(object, ...) : number of rows in use has changed: remove missing values? I know some of my predictors are missing values for certain dates. I assume this is what “number of rows in use has changed” means. Must I remove all rows that are missing values? Or is there an option that does this for me? Or am I completely off and there is something else going on? This is my first time using R for statistics, so I am not sure if this is a mistake with my data or with my use of R. I would appreciate any insight into what I am doing wrong. Thanks, Tim Tim Clark PhD Candidate Department of Zoology University of Hawaii Honolulu, HI 96816 [[alternative HTML version deleted]]
Ben Bolker
2009-Feb-18 13:32 UTC
[R] using stepAIC with negative binomial regression - error message help
t c <mudiver1200 <at> yahoo.com> writes:> > Dear List, > I am having problems running stepAIC with a > negative binomial regression model.? I am working with data on > manta ray abundance, using 20 predictor variables.?[snip] The model I ran was:> glm.nb.full<glm.nb(mantas~site+year+cosday+sinday+daylength+ lunarpercent+sstmean+sststd+> sshmean+sshstd+cosdir+sindir+spd+temp+alt+tideht+high+falling+low+plankton)> ? > However, when I use stepAIC on the model I get the message: > ? > > stepAIC(glm.nb.full) > Start:? AIC=19240.46 > mantas ~ site + year + cosday + sinday + daylength + lunarpercent + > ??? sstmean + sststd + sshmean + sshstd + cosdir + sindir + spd + > ??? temp + alt + tideht + high + falling + low + plankton > ? > Error in dropterm.default(object, ...) : > ? number of rows in use has changed: remove missing values?Yes. As the note in ?stepAIC says, The model fitting must apply the models to the same dataset. This may be a problem if there are missing values and an 'na.action' other than 'na.fail' is used (as is the default in R). We suggest you remove the missing values first. The easiest way to remove missing values is with na.omit, e.g. fullmod <- glm.nb(..., data=na.omit(mydata)) stepAIC(fullmod) aren't cosday, sinday, and daylength pretty strongly collinear ... ? Ben Bolker