[R] R Error/Warning Messages with library(MASS) using glm.

LNadler lauren.e.nadler at gmail.com
Sat Apr 14 08:34:26 CEST 2012


Hi there,

I have been having trouble running negative binomial regression (glm.nb)
using library MASS in R v2.15.0 on Mac OSX.  

I am running multiple models on the variables influencing the group size of
damselfish in coral reefs (count data).  For total group size and two of my
species, glm.nb is working great to deal with overdispersion in my count
data.  For two of my species, I am getting a mixture of warning and error
messages.  These species are different from the others in that they have
slightly smaller group sample size (so there are more 0s) and the group size
varies more widely (from 1 to 45 fish versus 1 to 11 fish for the other
species for which the model is working).  Here is a sample of my output and
the error messages:

> model1<-glm.nb(X...of.C..viridis~PC1+Average.Branch.Diameter+Average.Branch.Spacing+PC1*Average.Branch.Diameter+Average.Branch.Diameter*Average.Branch.Spacing+PC1*Average.Branch.Spacing)
There were 50 or more warnings (use warnings() to see the first 50)
> warnings()
Warning messages:
1: In theta.ml(Y, mu, sum(w), w, limit = control$maxit, trace =
control$trace >  ... :
  iteration limit reached
2: In sqrt(1/i) : NaNs produced
3: In theta.ml(Y, mu, sum(w), w, limit = control$maxit, trace =
control$trace >  ... :
  iteration limit reached (ETC...CONTINUES ON THE SAME FOR 50 WARNINGS)
> summary(model1)
Call:
glm.nb(formula = X...of.C..viridis ~ PC1 + Average.Branch.Diameter + 
    Average.Branch.Spacing + PC1 * Average.Branch.Diameter + 
    Average.Branch.Diameter * Average.Branch.Spacing + PC1 * 
    Average.Branch.Spacing, init.theta = 61302.24256, link = log)

Deviance Residuals: 
    Min       1Q   Median       3Q      Max  
-7.3292  -1.0162  -0.7605  -0.5167   8.5282  

Coefficients:
                                               Estimate Std. Error z value
Pr(>|z|)    
(Intercept)                                     -7.0591     3.5020  -2.016
0.043828 *  
PC1                                             -1.0078     0.2950  -3.416
0.000636 ***
Average.Branch.Diameter                          5.9910     4.1130   1.457
0.145230    
Average.Branch.Spacing                           6.5972     2.8974   2.277
0.022788 *  
PC1:Average.Branch.Diameter                      1.0415     0.2756   3.779
0.000158 ***
Average.Branch.Diameter:Average.Branch.Spacing  -6.5321     3.3292  -1.962
0.049755 *  
PC1:Average.Branch.Spacing                       0.6469     0.1629   3.971
7.17e-05 ***
---
Signif. codes:  0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1 

(Dispersion parameter for Negative Binomial(61302.24) family taken to be 1)

    Null deviance: 1331.8  on 177  degrees of freedom
Residual deviance:  641.1  on 171  degrees of freedom
  (3 observations deleted due to missingness)
AIC: 729.44

Number of Fisher Scoring iterations: 1

Error in prettyNum(.Internal(format(x, trim, digits, nsmall, width, 3L,  : 
  invalid 'nsmall' argument

I am also getting this Error message for my other model for this species:

> model1<-glm.nb(X...of.C..viridis~Depth+Coral.Species+Reef.Type+Depth*Coral.Species+Depth*Reef.Type+Coral.Species*Reef.Type)
Error: no valid set of coefficients has been found: please supply starting
values

I have tried everything I could find online.  I tried
family=negative.binomial(theta) but I was unsure what to use for theta so
didn't find it reliable for estimating dispersion.  I have also tried negbin
in the library aod but it is coming up with NA values where the
p-values/deviance etc should be.  I was hoping to find out if the warning
messages make the model invalid and if there was some way to get around the
error message in the second model.  Any advice would be greatly appreciated.
Thank you very much.  

Kind regards,
Lauren Nadler

--
View this message in context: http://r.789695.n4.nabble.com/R-Error-Warning-Messages-with-library-MASS-using-glm-tp4556771p4556771.html
Sent from the R help mailing list archive at Nabble.com.



More information about the R-help mailing list