-
Notifications
You must be signed in to change notification settings - Fork 13
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
Using variable labels instead of variable names when available #24
Comments
This package is not in active development, if you are interested in this feature, please implement it, then keep a fork or create a pull request to https://github.com/ShixiangWang/forestmodel |
@ShixiangWang is it an official fork? @NikNakk could you clarify if you still plan to maintain and develop |
@larmarange Nope, I don't say that. The author is nice, but he may be not active in GitHub, from my view. |
Hi @larmarange, @ShixiangWang, I've not been very active in maintaining this package for a while because of being busy with other things, but I'm still aiming to get to the outstanding queries that have been raised including yours. There's also now a more pressing reason to attend to the package because it's erroring on CRAN so will be delisted if I don't fix that. I'll at least fix the current issue that would lead to delisting in the next few days, but if I can I'll try to fix any other outstanding issues and improvements. |
Thanks @NikNakk for your feedback. Regarding the proposed improvement, it should not be very difficult to implement once identified where variable names are taken into account. I didn't have time to get into your code in details so I do not know yet how your code was organized. But as you are familiar with your package, you should have an idea on where to look at. Best regards |
@larmarange I've made a new branch that has a simple implementation of this at https://github.com/NikNakk/forestmodel/tree/labels. You can test it using |
Thanks a lot |
@larmarange please let me know when you've had a chance to test this out. |
@NikNakk I have done some quick tests. It works well with simple models. Thanks. When I add interaction terms, labels are not taken into account for interaction terms, but it was already the case before (it seems that library(questionr)
library(forestmodel)
library(labelled)
data(fertility)
women <- unlabelled(women)
mod <- glm(employed ~ age + residency * instruction, data = women, family = binomial())
forest_model(mod, exponentiate = TRUE) Here a quick example with
|
But I know that managing interaction terms could be tricky and beyond the current issue. Otherwise, it's perfect. Thanks a lot |
I’ll have a look at interaction terms when I get a chance. |
Thanks |
FYI, this version is now on CRAN. |
Variable labels still not showing up |
Same here, it works fine with |
Sorry for the delayed response, @proshano and @corneliushennch. Could you please give me some example code that doesn't work as expected? I'm still planning to work on interaction terms since they're not currently properly supported with or without labels. |
In case it could be useful for you, |
EDIT: The problem occurs with factor and character variables when using library(survival)
library(dplyr)
library(forestmodel)
surv_data <- tibble(
time = abs(rnorm(300, 50, 30)),
event = sample(c(0,1), 300, prob = c(0.8, 0.2), replace = TRUE),
gender = sample(c(0,1), 300, prob = c(0.6, 0.4), replace = TRUE),
rx = sample(c("no","yes"), 300, prob = c(0.5, 0.5), replace = TRUE),
gene = sample(c(0,1), 300, prob = c(0.9, 0.1), replace = TRUE)
)
surv_data <- surv_data %>%
mutate(gender = factor(gender, levels = c(0,1), labels = c("female", "male")))
labelled::var_label(surv_data) <- list(
gender = "Gender (f/m)", #this variable is a factor -> doesn't work!
rx = "Irradiation", # character -> label doesn't work!
gene = "Gene of Interest" # numeric -> label works...
)
labelled::var_label(surv_data) # checking that labels are assigned
#> $time
#> NULL
#>
#> $event
#> NULL
#>
#> $gender
#> [1] "Gender (f/m)"
#>
#> $rx
#> [1] "Irradiation"
#>
#> $gene
#> [1] "Gene of Interest"
lapply(surv_data, class) # showing variable classes
#> $time
#> [1] "numeric"
#>
#> $event
#> [1] "numeric"
#>
#> $gender
#> [1] "factor"
#>
#> $rx
#> [1] "character"
#>
#> $gene
#> [1] "numeric"
# printing the coxph model -> only label of numeric variable works
print(forest_model(coxph(formula = Surv(time, event) ~ gender + rx +
gene, data = surv_data))) # ok it seems to be a specific problem of the coxph object -> labels get printed correctly
# with glm...
mod <- glm(gender ~ gene + rx, data = surv_data, family = binomial())
forest_model(mod, exponentiate = TRUE) Created on 2021-04-23 by the reprex package (v0.3.0) |
I would also love to have the coxph factor label bug fixed as it would save a lot of time in my work. |
Thanks a lot for all your efforts. Please let us know if the label bug got fixed for |
Variable labels, stored as a
label
attributes and easily accessible withlabelled::var_label()
, are becoming quite common. Many packages (likegtsummary
) producing graphs or tables are now adopting the following rule: if defined, use variable labels instead of variable names.Such addition to
forestmodel
would allow to easily customize the names of variables displayed on forest plots.The text was updated successfully, but these errors were encountered: