I'm dealing with some survey data and using dplyr, gtsummary, and the survey package to do my analysis.
One area of the survey goes like this:
- A question about whether the respondent would consider using the service
- For those who would not, they are presented with a list of potential reasons and asked to select the reasons why.
I've used a filter and select to focus my analysis only on this subset of questions (columns) among the people (rows) who said they are not likely. This reduces my initial N from 150 to 41 (41 non-considerers). So far so good, the code works.
The problem I'm having is that when I use tbl_svysummary(), the % displayed next to each question says 100% instead of X/41. I've tried using %>% add_n(statistic="{p_nonmiss}")
on the tbl_svysummary, but it gives me the same result.
If it's helpful to know, I'm using tbl_svysummary instead of tbl_summary because I need to use the survey package to calibrate the data.
Here's what the output looks like: https://i.stack.imgur.com/6FLu7.png
And here is my code:
barriers <- df %>% filter(QCONSIDERATION == "Not likely" | QCONSIDERATION == "Not at all likely") %>%
select(QCONSIDERATIONSBAR_1, QCONSIDERATIONSBAR_6, QCONSIDERATIONSBAR_7, QCONSIDERATIONSBAR_8, QCONSIDERATIONSBAR_9, QCONSIDERATIONSBAR_10, QCONSIDERATIONSBAR_11, QCONSIDERATIONSBAR_12, QCONSIDERATIONSBAR_13, QCONSIDERATIONSBAR_14, QCONSIDERATIONSBAR_15, QCONSIDERATIONSBAR_16, QCONSIDERATIONSBAR_17, QCONSIDERATIONSBAR_18, QCONSIDERATIONSBAR_19, QCONSIDERATIONSBAR_20, QCONSIDERATIONSBAR_21,QCONSIDERATIONSBAR_22)
barrierssvy <- svydesign(id=~1, data=barriers)
tbl_svysummary(barrierssvy) %>% add_n(statistic="{p_nonmiss}")