Error calculating Cook's distance for glm

29 views
Skip to first unread message

Kristina Wolf

unread,
Sep 16, 2015, 2:06:01 PM9/16/15
to Davis R Users' Group
Hi everyone, 

I have been running this code for weeks to calculate Cook's distance for a glm model with no issues: 

rstandard(glm1, infl=influence(glm2, do.coef = FALSE), type = c("pearson"))

I recently wanted to play around with different methods of calculating and plotting these values, and accidentally tried running some code that works only for lm models (I lost that code, sorry). 
I deleted that code and closed R, opened back up and tried to run my original code above, and I now only get his error all the time: 

Error in influence(glm1, do.coef = FALSE) : 
  Please specify either the 'group' parameter, or specify 'obs=TRUE'

Even if I try to modify the code according to the error, nothing changes, and I can no longer calculate Cook's distance with rstandard(glm1, infl=influence(glm2, do.coef = FALSE), type = c("pearson"))

Any ideas for getting around this super-annoying error? 

Thank you in advance! 

Kristina

Brandon Hurr

unread,
Sep 16, 2015, 2:09:24 PM9/16/15
to davi...@googlegroups.com
Is there something stuck in your environment that's causing the error? Maybe clear your workspace and start your code from scratch?

?rm

## remove (almost) everything in the working environment.
## You will get no warning, so don't do this unless you are really sure.
rm(list = ls())

--
Check out our R resources at http://www.noamross.net/davis-r-users-group.html
---
You received this message because you are subscribed to the Google Groups "Davis R Users' Group" group.
To unsubscribe from this group and stop receiving emails from it, send an email to davis-rug+...@googlegroups.com.
Visit this group at http://groups.google.com/group/davis-rug.
For more options, visit https://groups.google.com/d/optout.

Jaime Ashander

unread,
Sep 16, 2015, 2:09:57 PM9/16/15
to davi...@googlegroups.com, Davis R Users' Group
I've no solution without googling. But writing to suggest you provide the output of 

sessionInfo()

typed at the console prompt. It may help folks help you track it down. 

Jaime


On Wed, Sep 16, 2015 at 11:06 AM, Kristina Wolf <kmw...@ucdavis.edu> wrote:

--

Kristina Wolf

unread,
Sep 16, 2015, 2:36:42 PM9/16/15
to davi...@googlegroups.com

Brandon - I thought so too, and cleared my workspace but was still getting that same error.

Jaime - here is the output from sessionInfo():

R version 3.1.0 (2014-04-10)
Platform: x86_64-w64-mingw32/x64 (64-bit)

locale:
[1] LC_COLLATE=English_United States.1252  LC_CTYPE=English_United States.1252    LC_MONETARY=English_United States.1252
[4] LC_NUMERIC=C                           LC_TIME=English_United States.1252    

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base     

other attached packages:
[1] influence.ME_0.9-6 lme4_1.1-7         Matrix_1.1-3       glm2_1.1.2         Amelia_1.7.3       Rcpp_0.11.2       
[7] car_2.0-21         AICcmodavg_2.0-3  

loaded via a namespace (and not attached):
 [1] colorspace_1.2-4 digest_0.6.4     foreign_0.8-61   ggplot2_1.0.0    grid_3.1.0       gtable_0.1.2     lattice_0.20-29 
 [8] MASS_7.3-31      minqa_1.2.4      munsell_0.4.2    nlme_3.1-120     nloptr_1.0.4     nnet_7.3-8       plyr_1.8.1      
[15] proto_0.3-10     reshape_0.8.5    reshape2_1.4     scales_0.2.4     splines_3.1.0    stats4_3.1.0     stringr_0.6.2   
[22] tools_3.1.0      unmarked_0.10-6  VGAM_0.9-7       xtable_1.7-4

I did see the package influence.ME which I recall is a package I was playing with to detect outliers, so I unattached that, but I still got the same error

​. 

Then, I shut everything down, made sure my workspace was cleared and that influence.ME was off, and reloaded the car package, and now it works! 

Thank you Brandon and Jaime for the tips and leading me in the right directio
n!


~ Kristina

​​
Kristina Wolf

Ph.D. Candidate, Graduate Group in Ecology
M.S. Soil Science
​, 
B.S. Animal Science
KristinaMWolf.com
Restoration Ecology Lab
Department of Plant Sciences
University of California, Davis​

"We have to remember that what we observe is not nature herself, but nature exposed to our method of questioning." ~ Werner Heisenberg
 

Brandon Hurr

unread,
Sep 16, 2015, 2:39:26 PM9/16/15
to davi...@googlegroups.com
Yeah, I try to start every session with an empty workspace. Almost every time I've had weird errors like that it's because of having a package loaded or a variable already there that shouldn't be. 

B
Reply all
Reply to author
Forward
0 new messages