I need some guidance in using survey weights in RStudio using the survey package.
table_1015 consists of survey data from the years 2010 to 2015 where each row is one response from a participant including information such as age, race, sex, and education level/grade (all are categorical variables). It also includes responses to questions in the survey labeled as q1, q2, q3, etc. where 1 = Yes and 0 = No and 'Missing' = NA/No Response.
I used the below code to calculate the unweighted frequencies and proportion by year and age.
age_1015 <- table_1015 %>%
group_by(year, age) %>%
summarise(count = n()) %>%
mutate(proportion = count / sum(count))
Example of part of the output for age_1015:
| year | age | count | proportion |
|---|---|---|---|
| 2010 | 12yo | 5 | 0.185 |
| 2010 | 13yo | 8 | 0.296 |
| 2010 | 14yo | 14 | 0.519 |
| 2011 | 12yo | 3 | 0.115 |
| 2011 | 13yo | 7 | 0.269 |
| 2011 | 14yo | 16 | 0.615 |
| 2012 | 12yo | 2 | 0.118 |
| 2012 | 13yo | 4 | 0.235 |
| 2012 | 14yo | 11 | 0.647 |
How would I go about applying the following survey design object to the above? I want to calculate the weighted frequency (weighted_count) and the weighted proportion (weighted_prop).
srvy_des_1015 <- <- svydesign(ids = ~PSU, data = table_1015, weights = ~weight, strata = ~stratum, nest = TRUE)