tidymodels / broom

Convert statistical analysis objects from R into tidy format
https://broom.tidymodels.org
Other
1.45k stars 304 forks source link

no .resid column #50

Closed njtierney closed 6 years ago

njtierney commented 9 years ago

I don't get a column with of residuals, I only get the standardized residuals, not the residuals, as in the example.

When I follow the example on the github page:

lmfit <- lm(mpg ~ wt, mtcars)
head(augment(lmfit))

I get this:

.rownames mpg wt .fitted .se.fit .hat .sigma .cooksd .std.resid
Mazda RX4 21.0 2.620 23.28261 0.6335798 0.0432690 3.067494 0.0132741 -0.7661677
Mazda RX4 Wag 21.0 2.875 21.91977 0.5714319 0.0351968 3.093068 0.0017240 -0.3074305
Datsun 710 22.8 2.320 24.88595 0.7359177 0.0583757 3.072127 0.0154394 -0.7057525
Hornet 4 Drive 21.4 3.215 20.10265 0.5384424 0.0312502 3.088268 0.0030206 0.4327511
Hornet Sportabout 18.7 3.440 18.90014 0.5526562 0.0329218 3.097722 0.0000760 -0.0668188
Valiant 18.1 3.460 18.79325 0.5552829 0.0332355 3.095184 0.0009211 -0.2314831
sessionInfo()
R version 3.2.0 (2015-04-16)
Platform: x86_64-apple-darwin13.4.0 (64-bit)
Running under: OS X 10.10.3 (Yosemite)

locale:
[1] en_AU.UTF-8/en_AU.UTF-8/en_AU.UTF-8/C/en_AU.UTF-8/en_AU.UTF-8

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

other attached packages:
[1] knitr_1.9        broom_0.3.7     
[3] gridExtra_0.9.1  dplyr_0.4.1.9000
[5] ggplot2_1.0.1    GGally_0.5.0    

loaded via a namespace (and not attached):
 [1] Rcpp_0.11.6       git2r_0.10.1     
 [3] formatR_1.1       plyr_1.8.1       
 [5] bitops_1.0-6      tools_3.2.0      
 [7] rpart_4.1-9       digest_0.6.8     
 [9] memoise_0.2.1     evaluate_0.7     
[11] gtable_0.1.2      psych_1.5.1      
[13] shiny_0.11.1.9004 DBI_0.3.1        
[15] yaml_2.1.13       parallel_3.2.0   
[17] proto_0.3-10      httr_0.6.1       
[19] stringr_1.0.0     rversions_1.0.0  
[21] devtools_1.8.0    reshape_0.8.5    
[23] R6_2.0.1          XML_3.98-1.1     
[25] rmarkdown_0.6.1   reshape2_1.4.1   
[27] tidyr_0.2.0.9000  magrittr_1.5     
[29] scales_0.2.4      htmltools_0.2.6  
[31] MASS_7.3-40       assertthat_0.1   
[33] mnormt_1.5-2      mime_0.3         
[35] xtable_1.7-4      colorspace_1.2-6 
[37] httpuv_1.3.2      labeling_0.3     
[39] stringi_0.5-1     RCurl_1.95-4.6   
[41] munsell_0.4.2    
packageVersion("broom")
[1] ‘0.3.7’

Am I doing something wrong?

dgrtwo commented 9 years ago

That's odd: you're using it entirely correctly, and I can't reproduce the problem. I take it residuals(lmfit) does work?

The augment_columns function is what adds the residuals: if you get the source code and start tinkering around the line ret$.resid <- residuals0(x) (starting by changing it to ret$.resid <- residuals0(x) to avoid the error catching), you might be able to figure out what's going on (I'd be happy to help with suggestions but am of limited immediate help since I can't reproduce it!)

nilesh1984 commented 9 years ago

Even I am having this problem now . residuals(lmfit) is working

R version 3.2.0 (2015-04-16) Platform: x86_64-w64-mingw32/x64 (64-bit) Running under: Windows 8 x64 (build 9200)

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

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

other attached packages: [1] readr_0.1.1 broom_0.3.7 tidyr_0.2.0 lubridate_1.3.3 zoo_1.7-12
[6] data.table_1.9.4 dplyr_0.4.1

loaded via a namespace (and not attached): [1] Rcpp_0.11.6 lattice_0.20-31 psych_1.5.4 digest_0.6.8 assertthat_0.1 [6] R6_2.0.1 chron_2.3-45 grid_3.2.0 plyr_1.8.2 DBI_0.3.1
[11] magrittr_1.5 stringi_0.4-1 lazyeval_0.1.10 reshape2_1.4.1 tools_3.2.0
[16] stringr_1.0.0 parallel_3.2.0 mnormt_1.5-3 memoise_0.2.1

njtierney commented 9 years ago

Apologies for not replying sooner. I will try and have a look at your suggestions this week!

Thanks for being so quick at replying.

alexpghayes commented 6 years ago

Gonna close this since I can't reproduce. I presume this would have been caught in the time since the issue was opened given how much tidy.lm gets used.

github-actions[bot] commented 3 years ago

This issue has been automatically locked. If you believe you have found a related problem, please file a new issue (with a reprex: https://reprex.tidyverse.org) and link to this issue.