0

I am trying to analyse a multiple response question. I am using a weighted dataset. Something using survey, srvey or the tidyverse would be great.

ID <- c(1,2,3,4,5,6,7,8,9,10)
rent_income <- c(1, 1, 0, 1, 0, 1, 0, 1, 0, 0)
salary_income <- c( 0, 1, 0, 1, 0, 1, 1, 0, 1, 0)
other_income <- c( 0, 1, 0, 0, 0, 0, 1, 0, 0, 0)
survey_weights <- c(0.8, 0.8 , 0.8 , 0.8 , 0.8 , 1.2 , 1.2 , 1.2 , 1.2 , 1.2)
df<-data.frame(ID, rent_income, salary_income, other_income, survey_weights)

Weighted dataset:

weighted_dataset <- data %>% as_survey_design(ids=ID, weights=survey_weights)

I am aware that this question is similar to this previous one (Multiple response analysis in weighted survey data using srvyr), but that response did not in any way answer the question. I would think that this is a pretty common issue in survey analysis so hopefully someone has an answer.

Expected answer: Some sort of code that will allow me to produce a table with weighted frequencies and weighted case proportions.

Thanks

william3031
  • 1,653
  • 1
  • 18
  • 39
  • I'm having a hard time figuring out what you're after. Here's how to calculate weighted frequency/proportion for a single variable: `weighted_dataset %>% summarize(rent_freq = survey_total(rent_income), rent_mn = survey_mean(rent_income))` and here's how you could use dplyr's scoped functions to calculate on all the "income" ones: `weighted_dataset %>% summarize_at(vars(ends_with("income")), survey_mean)` – GregF Aug 02 '18 at 17:23
  • Thanks for your help. I have figured it out. Hmisc does the job. See: https://stackoverflow.com/questions/10049402/calculating-weighted-mean-and-standard-deviation – william3031 Aug 03 '18 at 00:12

0 Answers0