Dichotomous variables(YES/NO) in the gtsummary table.

Hello. I need some help reproducing a table using gtsummary. After doing the coding, dichotomous variables with Yes/No responses are represented in the table output with just one level, instead of the two levels(YES/NO). I need help with a code so that the two levels can show in the output. In the screenshot attached there variables are kidney disease, coronary artery disease, diabetes and smokeless tobacco.


2 Likes

A reprex would be good as your code via screenshot is somewhat a challenge for us forum fellows to retype in full, and also the attempt may be somewhat in vain as we lack your key input brfssdsgn...

I present a simple example of a dichotomous variable, both values it takes are shown by default. perhaps add your options until they disappear ? unless your starting data is very different and the explanation is from that difference rather than the code per say...

(some_made_up_data <- data.frame(SEX=c(rep("M",4),rep("F",8)),
                                kidney_disease=c(rep(c("y","n"),5),"y","y")))

(tbl_svysummary_ex1 <-
  survey::svydesign(~1, data = some_made_up_data) %>%
  tbl_svysummary(by = SEX)) %>% add_p() %>% bold_labels()

image

Thanks very much for your response. My starting data is from BRFSS. From there I selected my variables, recoded and then created a weighted survey design(brfssdsgn).
I finally figured it out. Gtsummary by default considers Yes/No, True/False variables as dichotomous and therefore presents only one row (Yes or No) in the output table. To have both levels show in the output, one needs to modify the type argument so that the variables are considered as categorical and not dichotomous....
Below is the argument code that finally fixed the problem..

type =list(ckd ~ 'categorical',
cad ~ 'categorical',
diab ~ 'categorical',
smokeless.use ~ 'categorical')

1 Like

Modifying the type= argument is exactly what you need to do. There is a shortcut, if you'd like to use it. You can use type = all_dichotomous() ~ "categorical"

2 Likes

Thank you very much. you've made it clearer for me

1 Like

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.