Hi,
It's my first post here, hopefully I'm not asking something super stupid. I'm rather new with R and having some trouble applying weights for my analysis. I'm using National Survey on Drug Use and Health 2019 dataset.
I want to create tables which include the weighted proportions for variables in wdata (risktaking, martialstatus, gender, education, agegroups, ethnicity, income, sort by MDMA use).
I tried tbl_svysummary, but obviously I'm doing something really wrong because the n in this dataset after excluding minors is around 40 000 but now in the table I'm getting from this the n goes up to hundreds of millions, makes no sense.
Is there anyone who could help me? I've been trying to figure this out by myself but ugh, I just seem to bump into more problems every time I try something.
Code:
wdata <- NSDUH_adults %>%
select(risktaking,
maritalstatus,
gender,
education,
agegroups,
ethnicity,
income,
MDMA_use,
ANALWT_C,
VESTR,
VEREP)
options(survey.lonely.psu="adjust")
wdata2 <- svydesign(ids = ~VEREP,
strata = ~VESTR,
data = wdata,
weights = ~ANALWT_C,
nest=TRUE)
wdata2 %>%
tbl_svysummary(
by = MDMA_use,
include = c(gender, risktaking, MDMA_use),
label = list(gender ~ "Gender",
risktaking ~ "Risktaking")
) %>%
add_p() %>% # comparing values by "both" column
add_overall() %>%
adding spanning header
modify_spanning_header(c("stat_1", "stat_2") ~ "MDMA")