Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Suggested improvement for null_lm #17

Open
emitanaka opened this issue Oct 16, 2021 · 3 comments
Open

Suggested improvement for null_lm #17

emitanaka opened this issue Oct 16, 2021 · 3 comments

Comments

@emitanaka
Copy link
Contributor

emitanaka commented Oct 16, 2021

When fitting null_lm, you need the data to have a column .resid otherwise it produces a graph like below. I've been manually adding the .resid column to "true" data before, but I think it will be easier if the residual is computed also for it during the lineup. Additionally, this method could be generalised further so that it is not just for lm but can cater for other statistical models.

library(tidyverse)
library(nullabor)
set.seed(1)
df1 <- tibble(id = 1:200) %>% 
  mutate(x = sample(rnorm(12), replace = TRUE, size = n()),
         y = 2 * x + 1)

lineup(null_lm(y ~ x), true = df1, n = 20, pos = 13) %>% 
  ggplot(aes(x, .resid)) +
  geom_point() +
  facet_wrap(~.sample)
#> Warning: Removed 200 rows containing missing values (geom_point).

Created on 2021-10-16 by the reprex package (v2.0.0)

Session info
sessioninfo::session_info()
#> ─ Session info ───────────────────────────────────────────────────────────────
#>  setting  value                       
#>  version  R version 4.0.1 (2020-06-06)
#>  os       macOS  10.16                
#>  system   x86_64, darwin17.0          
#>  ui       X11                         
#>  language (EN)                        
#>  collate  en_AU.UTF-8                 
#>  ctype    en_AU.UTF-8                 
#>  tz       Australia/Melbourne         
#>  date     2021-10-16                  
#> 
#> ─ Packages ───────────────────────────────────────────────────────────────────
#>  package     * version date       lib source        
#>  assertthat    0.2.1   2019-03-21 [2] CRAN (R 4.0.0)
#>  backports     1.2.1   2020-12-09 [1] CRAN (R 4.0.2)
#>  broom         0.7.9   2021-07-27 [1] CRAN (R 4.0.2)
#>  cellranger    1.1.0   2016-07-27 [2] CRAN (R 4.0.0)
#>  class         7.3-19  2021-05-03 [2] CRAN (R 4.0.2)
#>  cli           3.0.1   2021-07-17 [1] CRAN (R 4.0.2)
#>  cluster       2.1.2   2021-04-17 [2] CRAN (R 4.0.2)
#>  colorspace    2.0-2   2021-06-24 [1] CRAN (R 4.0.2)
#>  crayon        1.4.1   2021-02-08 [1] CRAN (R 4.0.2)
#>  curl          4.3.2   2021-06-23 [1] CRAN (R 4.0.2)
#>  DBI           1.1.1   2021-01-15 [1] CRAN (R 4.0.2)
#>  dbplyr        2.1.1   2021-04-06 [1] CRAN (R 4.0.2)
#>  DEoptimR      1.0-8   2016-11-19 [2] CRAN (R 4.0.0)
#>  digest        0.6.28  2021-09-23 [1] CRAN (R 4.0.2)
#>  diptest       0.76-0  2021-05-04 [2] CRAN (R 4.0.2)
#>  dplyr       * 1.0.7   2021-06-18 [1] CRAN (R 4.0.2)
#>  ellipsis      0.3.2   2021-04-29 [1] CRAN (R 4.0.2)
#>  evaluate      0.14    2019-05-28 [2] CRAN (R 4.0.0)
#>  fansi         0.5.0   2021-05-25 [1] CRAN (R 4.0.2)
#>  farver        2.1.0   2021-02-28 [1] CRAN (R 4.0.2)
#>  fastmap       1.1.0   2021-01-25 [1] CRAN (R 4.0.2)
#>  flexmix       2.3-17  2020-10-12 [1] CRAN (R 4.0.2)
#>  forcats     * 0.5.1   2021-01-27 [1] CRAN (R 4.0.2)
#>  fpc           2.2-9   2020-12-06 [2] CRAN (R 4.0.2)
#>  fs            1.5.0   2020-07-31 [1] CRAN (R 4.0.2)
#>  generics      0.1.0   2020-10-31 [2] CRAN (R 4.0.2)
#>  ggplot2     * 3.3.5   2021-06-25 [1] CRAN (R 4.0.2)
#>  glue          1.4.2   2020-08-27 [1] CRAN (R 4.0.2)
#>  gtable        0.3.0   2019-03-25 [2] CRAN (R 4.0.0)
#>  haven         2.4.1   2021-04-23 [2] CRAN (R 4.0.2)
#>  highr         0.9     2021-04-16 [2] CRAN (R 4.0.2)
#>  hms           1.1.1   2021-09-26 [1] CRAN (R 4.0.2)
#>  htmltools     0.5.2   2021-08-25 [1] CRAN (R 4.0.2)
#>  httr          1.4.2   2020-07-20 [1] CRAN (R 4.0.2)
#>  jsonlite      1.7.2   2020-12-09 [1] CRAN (R 4.0.2)
#>  kernlab       0.9-29  2019-11-12 [2] CRAN (R 4.0.0)
#>  knitr         1.34    2021-09-09 [1] CRAN (R 4.0.2)
#>  labeling      0.4.2   2020-10-20 [1] CRAN (R 4.0.2)
#>  lattice       0.20-44 2021-05-02 [2] CRAN (R 4.0.2)
#>  lifecycle     1.0.1   2021-09-24 [1] CRAN (R 4.0.2)
#>  lubridate     1.7.10  2021-02-26 [1] CRAN (R 4.0.2)
#>  magrittr      2.0.1   2020-11-17 [1] CRAN (R 4.0.2)
#>  MASS          7.3-54  2021-05-03 [1] CRAN (R 4.0.2)
#>  mclust        5.4.7   2020-11-20 [2] CRAN (R 4.0.2)
#>  mime          0.11    2021-06-23 [1] CRAN (R 4.0.2)
#>  modelr        0.1.8   2020-05-19 [2] CRAN (R 4.0.0)
#>  modeltools    0.2-23  2020-03-05 [2] CRAN (R 4.0.0)
#>  moments       0.14    2015-01-05 [2] CRAN (R 4.0.0)
#>  munsell       0.5.0   2018-06-12 [2] CRAN (R 4.0.0)
#>  nnet          7.3-16  2021-05-03 [2] CRAN (R 4.0.2)
#>  nullabor    * 0.3.9   2020-02-25 [1] CRAN (R 4.0.2)
#>  pillar        1.6.3   2021-09-26 [1] CRAN (R 4.0.1)
#>  pkgconfig     2.0.3   2019-09-22 [2] CRAN (R 4.0.0)
#>  prabclus      2.3-2   2020-01-08 [2] CRAN (R 4.0.0)
#>  purrr       * 0.3.4   2020-04-17 [2] CRAN (R 4.0.0)
#>  R6            2.5.1   2021-08-19 [1] CRAN (R 4.0.1)
#>  Rcpp          1.0.7   2021-07-07 [1] CRAN (R 4.0.2)
#>  readr       * 2.0.1   2021-08-10 [1] CRAN (R 4.0.2)
#>  readxl        1.3.1   2019-03-13 [2] CRAN (R 4.0.0)
#>  reprex        2.0.0   2021-04-02 [1] CRAN (R 4.0.2)
#>  rlang         0.4.11  2021-04-30 [1] CRAN (R 4.0.2)
#>  rmarkdown     2.11    2021-09-14 [1] CRAN (R 4.0.2)
#>  robustbase    0.93-7  2021-01-04 [2] CRAN (R 4.0.2)
#>  rstudioapi    0.13    2020-11-12 [1] CRAN (R 4.0.1)
#>  rvest         1.0.1   2021-07-26 [1] CRAN (R 4.0.2)
#>  scales        1.1.1   2020-05-11 [2] CRAN (R 4.0.0)
#>  sessioninfo   1.1.1   2018-11-05 [2] CRAN (R 4.0.0)
#>  stringi       1.7.4   2021-08-25 [1] CRAN (R 4.0.2)
#>  stringr     * 1.4.0   2019-02-10 [2] CRAN (R 4.0.0)
#>  styler        1.4.1   2021-03-30 [1] CRAN (R 4.0.2)
#>  tibble      * 3.1.5   2021-09-30 [1] CRAN (R 4.0.2)
#>  tidyr       * 1.1.3   2021-03-03 [1] CRAN (R 4.0.2)
#>  tidyselect    1.1.1   2021-04-30 [1] CRAN (R 4.0.2)
#>  tidyverse   * 1.3.1   2021-04-15 [1] CRAN (R 4.0.2)
#>  tzdb          0.1.2   2021-07-20 [1] CRAN (R 4.0.2)
#>  utf8          1.2.2   2021-07-24 [1] CRAN (R 4.0.2)
#>  vctrs         0.3.8   2021-04-29 [1] CRAN (R 4.0.2)
#>  withr         2.4.2   2021-04-18 [1] CRAN (R 4.0.2)
#>  xfun          0.26    2021-09-14 [1] CRAN (R 4.0.2)
#>  xml2          1.3.2   2020-04-23 [2] CRAN (R 4.0.0)
#>  yaml          2.2.1   2020-02-01 [1] CRAN (R 4.0.2)
#> 
#> [1] /Users/etan0038/Library/R/4.0/library
#> [2] /Library/Frameworks/R.framework/Versions/4.0/Resources/library
@dicook
Copy link
Owner

dicook commented Jul 5, 2022

yes, agree with this. would you make the pull request?

@emitanaka
Copy link
Contributor Author

I already did the pull request for #20 and you are asking me to do a pull request for #19 and #17 as well ...

@dicook
Copy link
Owner

dicook commented Jul 6, 2022

I interpreted these suggestions as that you already had fixes, and could do the pull requests easily. That not being the case, then we can leave them as suggestions, and I will get to them as I can manage.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants