[R] using stepAIC with negative binomial regression - error message help

Ben Bolker bolker at ufl.edu
Wed Feb 18 14:32:12 CET 2009



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




More information about the R-help mailing list