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

Feature request: Support for checkbox questions #79

Closed
svenhalvorson opened this issue Jan 12, 2022 · 8 comments · Fixed by #81
Closed

Feature request: Support for checkbox questions #79

svenhalvorson opened this issue Jan 12, 2022 · 8 comments · Fixed by #81

Comments

@svenhalvorson
Copy link

I'm frequently using data sets that have 'checkbox' style questions in which the respondent selects any number of some set of discrete options. The resulting data is then spread across multiple columns, one for each option, and will just have a 1 or NA for possible values.

The function gtsummary::tbl_summary treats these each as their own variable instead of listing a common heading for them. Here is my question from stackoverflow along with @ddsjoberg 's solution. This solution is okay but it's a bit tedious, especially if you have a lot of other variables in the data set.

Ideally, gtsummary::tbl_summary could be given a list of columns to treat as one question or a pattern to find them, and then apply this similar formatting.

Thank you! Love the library

@kwakuduahc1

This comment has been minimized.

@ddsjoberg ddsjoberg transferred this issue from ddsjoberg/gtsummary Jan 13, 2022
@ddsjoberg
Copy link
Collaborator

@svenhalvorson thank you for the post! I've transferred this issue to our bstfun package, which (among other purposes) serves as a sandbox for gtsummary features.

I was thinking the interface to the function will be similar to tbl_summary(), but the include argument controls the grouping of the variables.

df <-
  tibble::tibble(
    race_white = sample(c(T, F), 10, replace = TRUE),
    race_black = sample(c(T, F), 10, replace = TRUE),
    race_asian = sample(c(T, F), 10, replace = TRUE),
    
    
  )

tbl_check_all_that_apply(
  data = df, 
  include = list("Race" = c(race_white, race_black, race_asian))
)

We would require that the variables included be logical (to ensure they can be summarized on a single row).

Do you have any suggestions for the function name?

@ddsjoberg

This comment has been minimized.

@kwakuduahc1
Copy link

Do you have any suggestions for the function name?

tbl_checks

@svenhalvorson
Copy link
Author

@ddsjoberg thanks for continuing with this.

As far as name goes, I think these kinds of variables are widely referred to as 'checkbox' questions and that is shorter than check_all_that_apply

A couple other thoughts:

  1. I have only minor experience with package development but would like to learn from ya'll
  2. I formatted the example with 1 and NA as the values because if respondents fill out none of the boxes, you can't infer whether none of the choices apply or that they just skipped it. I generally replace missing values with 0 in the case that at least one other box was checked. I think it would be reasonable to have the user pre-process it to binary or logical. If possible, the missing summary should report the proportion of observations for which no box was checked.
  3. The task that prompted this question is I'm trying to make a cohort description of a data set with many data types. Ideally, we would be able to pipe the output of gtsummary::tbl_summary into this function instead of having to stack the checkbox questions with the rest of the variables.

@ddsjoberg
Copy link
Collaborator

  1. I formatted the example with 1 and NA as the values because if respondents fill out none of the boxes, you can't infer whether none of the choices apply or that they just skipped it. I generally replace missing values with 0 in the case that at least one other box was checked. I think it would be reasonable to have the user pre-process it to binary or logical. If possible, the missing summary should report the proportion of observations for which no box was checked.

Great, we'll leave it up to the user to differentiate between uncheck and missing, by requiring logical class variables.

  1. The task that prompted this question is I'm trying to make a cohort description of a data set with many data types. Ideally, we would be able to pipe the output of gtsummary::tbl_summary into this function instead of having to stack the checkbox questions with the rest of the variables.

Unfortunately, I think you're going to be left with stacking the tbl_summary() results with the tbl_checkbox() results. Incorporating this special case into tbl_summary() would be tricky!

@ddsjoberg
Copy link
Collaborator

Hey hey @svenhalvorson

I added a draft of the function in this pull request #81

How familiar are you with GitHub and Pull Requests? Are you able to install the branch with the tbl_checkbox() function and test?

@ddsjoberg
Copy link
Collaborator

Pinging @svenhalvorson @kwakuduahc1 , can either of you review this pull request with the added function? #81

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

Successfully merging a pull request may close this issue.

3 participants