ProjectMOSAIC / mosaic

Project MOSAIC R package
http://mosaic-web.org/
93 stars 26 forks source link

issues with mosaic::mplot() when variables are derived in the call to lm() #770

Closed nicholasjhorton closed 4 years ago

nicholasjhorton commented 4 years ago

Is this a known issue?

suppressPackageStartupMessages(library(mosaic))
mod <- lm(log(mpg) ~ wt, data = mtcars)
mplot(mod, which = 1)
#> Error in eval(i, data, env): object '.resid' not found
sessioninfo::session_info()
#> ─ Session info ───────────────────────────────────────────────────────────────
#>  setting  value                       
#>  version  R version 4.0.2 (2020-06-22)
#>  os       macOS Catalina 10.15.6      
#>  system   x86_64, darwin17.0          
#>  ui       X11                         
#>  language (EN)                        
#>  collate  en_US.UTF-8                 
#>  ctype    en_US.UTF-8                 
#>  tz       America/New_York            
#>  date     2020-08-28                  
#> 
#> ─ Packages ───────────────────────────────────────────────────────────────────
#>  package     * version date       lib source                               
#>  assertthat    0.2.1   2019-03-21 [1] CRAN (R 4.0.0)                       
#>  backports     1.1.9   2020-08-24 [1] CRAN (R 4.0.2)                       
#>  broom         0.7.0   2020-07-09 [1] CRAN (R 4.0.2)                       
#>  cli           2.0.2   2020-02-28 [1] CRAN (R 4.0.0)                       
#>  colorspace    1.4-1   2019-03-18 [1] CRAN (R 4.0.0)                       
#>  crayon        1.3.4   2017-09-16 [1] CRAN (R 4.0.0)                       
#>  crosstalk     1.1.0.1 2020-03-13 [1] CRAN (R 4.0.0)                       
#>  digest        0.6.25  2020-02-23 [1] CRAN (R 4.0.0)                       
#>  dplyr       * 1.0.2   2020-08-18 [1] CRAN (R 4.0.2)                       
#>  ellipsis      0.3.1   2020-05-15 [1] CRAN (R 4.0.0)                       
#>  evaluate      0.14    2019-05-28 [1] CRAN (R 4.0.0)                       
#>  fansi         0.4.1   2020-01-08 [1] CRAN (R 4.0.0)                       
#>  farver        2.0.3   2020-01-16 [1] CRAN (R 4.0.0)                       
#>  generics      0.0.2   2018-11-29 [1] CRAN (R 4.0.0)                       
#>  ggdendro      0.1.21  2020-08-11 [1] CRAN (R 4.0.2)                       
#>  ggforce       0.3.2   2020-06-23 [1] CRAN (R 4.0.0)                       
#>  ggformula   * 0.9.4   2020-03-04 [1] CRAN (R 4.0.0)                       
#>  ggplot2     * 3.3.2   2020-06-19 [1] CRAN (R 4.0.0)                       
#>  ggrepel       0.8.2   2020-03-08 [1] CRAN (R 4.0.0)                       
#>  ggridges    * 0.5.2   2020-01-12 [1] CRAN (R 4.0.2)                       
#>  ggstance    * 0.3.4   2020-04-02 [1] CRAN (R 4.0.0)                       
#>  glue          1.4.1   2020-05-13 [1] CRAN (R 4.0.2)                       
#>  gridExtra     2.3     2017-09-09 [1] CRAN (R 4.0.0)                       
#>  gtable        0.3.0   2019-03-25 [1] CRAN (R 4.0.0)                       
#>  highr         0.8     2019-03-20 [1] CRAN (R 4.0.0)                       
#>  hms           0.5.3   2020-01-08 [1] CRAN (R 4.0.0)                       
#>  htmltools     0.5.0   2020-06-16 [1] CRAN (R 4.0.0)                       
#>  htmlwidgets   1.5.1   2019-10-08 [1] CRAN (R 4.0.0)                       
#>  knitr         1.29    2020-06-23 [1] CRAN (R 4.0.0)                       
#>  lattice     * 0.20-41 2020-04-02 [1] CRAN (R 4.0.2)                       
#>  lazyeval      0.2.2   2019-03-15 [1] CRAN (R 4.0.0)                       
#>  leaflet       2.0.3   2019-11-16 [1] CRAN (R 4.0.0)                       
#>  lifecycle     0.2.0   2020-03-06 [1] CRAN (R 4.0.0)                       
#>  magrittr      1.5     2014-11-22 [1] CRAN (R 4.0.0)                       
#>  MASS          7.3-52  2020-08-18 [1] CRAN (R 4.0.2)                       
#>  Matrix      * 1.2-18  2019-11-27 [1] CRAN (R 4.0.2)                       
#>  mosaic      * 1.7.0   2020-08-28 [1] Github (ProjectMOSAIC/mosaic@fb5aa64)
#>  mosaicCore    0.6.0   2018-06-24 [1] CRAN (R 4.0.0)                       
#>  mosaicData  * 0.18.0  2020-05-15 [1] CRAN (R 4.0.0)                       
#>  munsell       0.5.0   2018-06-12 [1] CRAN (R 4.0.0)                       
#>  pillar        1.4.6   2020-07-10 [1] CRAN (R 4.0.0)                       
#>  pkgconfig     2.0.3   2019-09-22 [1] CRAN (R 4.0.0)                       
#>  plyr          1.8.6   2020-03-03 [1] CRAN (R 4.0.0)                       
#>  polyclip      1.10-0  2019-03-14 [1] CRAN (R 4.0.0)                       
#>  purrr         0.3.4   2020-04-17 [1] CRAN (R 4.0.0)                       
#>  R6            2.4.1   2019-11-12 [1] CRAN (R 4.0.0)                       
#>  Rcpp          1.0.5   2020-07-06 [1] CRAN (R 4.0.2)                       
#>  readr         1.3.1   2018-12-21 [1] CRAN (R 4.0.0)                       
#>  rlang         0.4.7   2020-07-09 [1] CRAN (R 4.0.2)                       
#>  rmarkdown     2.3     2020-06-18 [1] CRAN (R 4.0.0)                       
#>  scales        1.1.1   2020-05-11 [1] CRAN (R 4.0.0)                       
#>  sessioninfo   1.1.1   2018-11-05 [1] CRAN (R 4.0.0)                       
#>  stringi       1.4.6   2020-02-17 [1] CRAN (R 4.0.0)                       
#>  stringr       1.4.0   2019-02-10 [1] CRAN (R 4.0.0)                       
#>  tibble        3.0.3   2020-07-10 [1] CRAN (R 4.0.2)                       
#>  tidyr         1.1.1   2020-07-31 [1] CRAN (R 4.0.2)                       
#>  tidyselect    1.1.0   2020-05-11 [1] CRAN (R 4.0.0)                       
#>  tweenr        1.0.1   2018-12-14 [1] CRAN (R 4.0.0)                       
#>  vctrs         0.3.2   2020-07-15 [1] CRAN (R 4.0.2)                       
#>  withr         2.2.0   2020-04-20 [1] CRAN (R 4.0.0)                       
#>  xfun          0.16    2020-07-24 [1] CRAN (R 4.0.2)                       
#>  yaml          2.2.1   2020-02-01 [1] CRAN (R 4.0.0)                       
#> 
#> [1] /Library/Frameworks/R.framework/Versions/4.0/Resources/library

Created on 2020-08-28 by the reprex package (v0.3.0)

Same problem if I use I().

suppressPackageStartupMessages(library(mosaic))
mod <- lm(I(log(mpg)) ~ wt, data = mtcars)
mplot(mod, which = 1)
#> Error in eval(i, data, env): object '.resid' not found

Created on 2020-08-28 by the reprex package (v0.3.0)

rpruim commented 4 years ago

Looks like it is a holdover from moving to use broom which uses .std.resid rather than .resid. I see two places where we didn't update the name.

Easy to fix:

suppressPackageStartupMessages(library(mosaic))
mod <- lm(log(mpg) ~ wt, data = mtcars)
mplot(mod, which = 1)
#> `geom_smooth()` using formula 'y ~ x'

Created on 2020-08-29 by the reprex package (v0.3.0)