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
How should logical covariates be treated? #125
Comments
Dear @ddsjoberg Thank you for your feedback. I see here two different issues:
I will explore it
library(broom.helpers)
lm(age ~ response + marker,
data = gtsummary::trial %>% dplyr::mutate(response = factor(response))) %>%
tidy_plus_plus(add_header_rows = TRUE) %>%
dplyr::select(term, variable, var_type, var_label, header_row, label, estimate, p.value)
#> # A tibble: 4 x 8
#> term variable var_type var_label header_row label estimate p.value
#> <chr> <chr> <chr> <chr> <lgl> <chr> <dbl> <dbl>
#> 1 <NA> response dichotomous response TRUE respon~ NA NA
#> 2 response0 response dichotomous response FALSE 0 0 NA
#> 3 response1 response dichotomous response FALSE 1 3.85 0.111
#> 4 marker marker continuous Marker Lev~ NA Marker~ 0.0339 0.979
lm(age ~ response + marker,
data = gtsummary::trial %>% dplyr::mutate(response = factor(response))) %>%
tidy_plus_plus(add_reference_rows = FALSE, add_header_rows = TRUE) %>%
dplyr::select(term, variable, var_type, var_label, header_row, label, estimate, p.value)
#> # A tibble: 3 x 8
#> term variable var_type var_label header_row label estimate p.value
#> <chr> <chr> <chr> <chr> <lgl> <chr> <dbl> <dbl>
#> 1 <NA> response dichotomous response TRUE respon~ NA NA
#> 2 response1 response dichotomous response FALSE 1 3.85 0.111
#> 3 marker marker continuous Marker Lev~ NA Marker~ 0.0339 0.979 Created on 2021-10-25 by the reprex package (v2.0.1) |
#127 should do the first fix. A logical variable will be handled as a factor with two levels. lm(age ~ response + marker,
data = gtsummary::trial |> dplyr::mutate(response = as.logical(response))) |>
broom.helpers::tidy_plus_plus(add_header_rows = TRUE) |>
dplyr::select(term, variable, var_type, var_label, header_row, label, estimate, p.value)
#> # A tibble: 4 x 8
#> term variable var_type var_label header_row label estimate p.value
#> <chr> <chr> <chr> <chr> <lgl> <chr> <dbl> <dbl>
#> 1 <NA> response dichotom~ response TRUE respo~ NA NA
#> 2 responseFALSE response dichotom~ response FALSE FALSE 0 NA
#> 3 responseTRUE response dichotom~ response FALSE TRUE 3.85 0.111
#> 4 marker marker continuo~ Marker Le~ NA Marke~ 0.0339 0.979 Created on 2021-10-25 by the reprex package (v2.0.1) |
Regarding the second point, we already have an option library(broom.helpers)
lm(age ~ response + marker,
data = gtsummary::trial |> dplyr::mutate(response = as.logical(response))) |>
tidy_plus_plus(add_header_rows = TRUE, show_single_row = all_dichotomous()) |>
dplyr::select(term, variable, var_type, var_label, header_row, label, estimate, p.value)
#> # A tibble: 2 x 8
#> term variable var_type var_label header_row label estimate p.value
#> <chr> <chr> <chr> <chr> <lgl> <chr> <dbl> <dbl>
#> 1 responseTRUE response dichotomous response NA resp~ 3.85 0.111
#> 2 marker marker continuous Marker Le~ NA Mark~ 0.0339 0.979 Created on 2021-10-25 by the reprex package (v2.0.1) |
Beautiful ! Thanks |
Hello!
It seems that model covariates of class 'logical' are treated as a hybrid between a continuous variable and a categorical. When a header row is added, they are only added to categorical variables (including logicals). But for logical covariates, we don't add the reference row, like we do for the rest of categorical covariates. To be consistent, do you think the reference group should be added?
Created on 2021-10-24 by the reprex package (v2.0.1)
The text was updated successfully, but these errors were encountered: