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

Example for sdc_model() when called in a loop / within *apply() #106

Open
matthiasgomolka opened this issue Mar 2, 2023 · 0 comments
Open
Labels
documentation Improvements or additions to documentation

Comments

@matthiasgomolka
Copy link
Owner

Use Case:
Users run a range of regressions using different dependent variables within a loop across a character vector containing the names of the dependent variables.
In order for sdc_model() to work properly, the model formula must be constructed using as.formula() beforehand in. As this is not straight forward, it should be documented in the FAQs.

library(sdcLog)
mtcars[["model"]] <- rownames(mtcars)

lapply(c("mpg", "hp"), FUN = function(dep_var) {
  fml <- as.formula(paste(dep_var, " ~ cyl"))
  model <- lm(fml, data = mtcars)
  sdc_model(mtcars, model, id_var = "model")
})
#> [[1]]
#> ───────────────────────────────────────────────────────── SDC results (model) ──
#> OPTIONS: sdc.n_ids: 5 | sdc.n_ids_dominance: 2 | sdc.share_dominance: 0.85
#> SETTINGS: id_var: model
#> ✔ Output complies to RDC rules.
#> ────────────────────────────────────────────────────────────────────────────────
#> 
#> [[2]]
#> ───────────────────────────────────────────────────────── SDC results (model) ──
#> OPTIONS: sdc.n_ids: 5 | sdc.n_ids_dominance: 2 | sdc.share_dominance: 0.85
#> SETTINGS: id_var: model
#> ✔ Output complies to RDC rules.
#> ────────────────────────────────────────────────────────────────────────────────

Created on 2023-03-02 with reprex v2.0.2

Session info
sessioninfo::session_info()
#> ─ Session info ───────────────────────────────────────────────────────────────
#>  setting  value
#>  version  R version 4.2.2 (2022-10-31 ucrt)
#>  os       Windows 10 x64 (build 19044)
#>  system   x86_64, mingw32
#>  ui       RTerm
#>  language en
#>  collate  German_Germany.utf8
#>  ctype    German_Germany.utf8
#>  tz       Europe/Berlin
#>  date     2023-03-02
#>  pandoc   2.19.2 @ C:/Program Files/R/RStudio-2022.07/bin/quarto/bin/tools/ (via rmarkdown)
#> 
#> ─ Packages ───────────────────────────────────────────────────────────────────
#>  package     * version date (UTC) lib source
#>  assertthat    0.2.1   2019-03-21 [1] CRAN (R 4.2.2)
#>  backports     1.4.1   2021-12-13 [1] CRAN (R 4.2.0)
#>  broom         1.0.1   2022-08-29 [1] CRAN (R 4.2.2)
#>  checkmate     2.1.0   2022-04-21 [1] CRAN (R 4.2.2)
#>  cli           3.4.1   2022-09-23 [1] CRAN (R 4.2.2)
#>  data.table    1.14.6  2022-11-16 [1] CRAN (R 4.2.2)
#>  DBI           1.1.3   2022-06-18 [1] CRAN (R 4.2.2)
#>  digest        0.6.31  2022-12-11 [1] CRAN (R 4.2.2)
#>  dplyr         1.0.10  2022-09-01 [1] CRAN (R 4.2.2)
#>  evaluate      0.18    2022-11-07 [1] CRAN (R 4.2.2)
#>  fansi         1.0.3   2022-03-24 [1] CRAN (R 4.2.2)
#>  fastmap       1.1.0   2021-01-25 [1] CRAN (R 4.2.2)
#>  fs            1.5.2   2021-12-08 [1] CRAN (R 4.2.2)
#>  generics      0.1.3   2022-07-05 [1] CRAN (R 4.2.2)
#>  glue          1.6.2   2022-02-24 [1] CRAN (R 4.2.2)
#>  highr         0.9     2021-04-16 [1] CRAN (R 4.2.2)
#>  htmltools     0.5.4   2022-12-07 [1] CRAN (R 4.2.2)
#>  knitr         1.41    2022-11-18 [1] CRAN (R 4.2.2)
#>  lifecycle     1.0.3   2022-10-07 [1] CRAN (R 4.2.2)
#>  magrittr      2.0.3   2022-03-30 [1] CRAN (R 4.2.2)
#>  mathjaxr      1.6-0   2022-02-28 [1] CRAN (R 4.2.2)
#>  pillar        1.8.1   2022-08-19 [1] CRAN (R 4.2.2)
#>  pkgconfig     2.0.3   2019-09-22 [1] CRAN (R 4.2.2)
#>  purrr         0.3.5   2022-10-06 [1] CRAN (R 4.2.2)
#>  R.cache       0.16.0  2022-07-21 [1] CRAN (R 4.2.2)
#>  R.methodsS3   1.8.2   2022-06-13 [1] CRAN (R 4.2.0)
#>  R.oo          1.25.0  2022-06-12 [1] CRAN (R 4.2.0)
#>  R.utils       2.12.2  2023-01-11 [1] local
#>  R6            2.5.1   2021-08-19 [1] CRAN (R 4.2.2)
#>  reprex        2.0.2   2022-08-17 [1] CRAN (R 4.2.2)
#>  rlang         1.0.6   2022-09-24 [1] CRAN (R 4.2.2)
#>  rmarkdown     2.18    2022-11-09 [1] CRAN (R 4.2.2)
#>  rstudioapi    0.14    2022-08-22 [1] CRAN (R 4.2.2)
#>  sdcLog      * 0.5.0   2022-03-19 [1] CRAN (R 4.2.2)
#>  sessioninfo   1.2.2   2021-12-06 [1] CRAN (R 4.2.2)
#>  stringi       1.7.8   2022-07-11 [1] CRAN (R 4.2.1)
#>  stringr       1.5.0   2022-12-02 [1] CRAN (R 4.2.2)
#>  styler        1.8.1   2022-11-07 [1] CRAN (R 4.2.2)
#>  tibble        3.1.8   2022-07-22 [1] CRAN (R 4.2.2)
#>  tidyr         1.2.1   2022-09-08 [1] CRAN (R 4.2.2)
#>  tidyselect    1.2.0   2022-10-10 [1] CRAN (R 4.2.2)
#>  utf8          1.2.2   2021-07-24 [1] CRAN (R 4.2.2)
#>  vctrs         0.5.1   2022-11-16 [1] CRAN (R 4.2.2)
#>  withr         2.5.0   2022-03-03 [1] CRAN (R 4.2.2)
#>  xfun          0.35    2022-11-16 [1] CRAN (R 4.2.2)
#>  yaml          2.3.6   2022-10-18 [1] CRAN (R 4.2.2)
#> 
#>  [1] C:/Users/s1504gl/AppData/Local/R/win-library/4.2
#>  [2] C:/Program Files/R/R-4.2.2/library
#> 
#> ──────────────────────────────────────────────────────────────────────────────
@matthiasgomolka matthiasgomolka added the documentation Improvements or additions to documentation label Mar 2, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
documentation Improvements or additions to documentation
Projects
None yet
Development

No branches or pull requests

1 participant