2

I'm keen to learn how to correctly apply survey weights in R. I tried to multiply the variable to create a new one but I didn't get anything intelligible out e.g.:

data2019$income_weighted <- data2019$income*data2019$population_weight

Here is the code in SPSS that I would usually run:

FREQUENCIES income.

WEIGHT BY population_weight.

FREQUENCIES income.

Grateful for any suggestions.

Thanks!

  • 2
    It's easier to help you if you include a simple [reproducible example](https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example) with sample input and desired output that can be used to test and verify possible solutions. – MrFlick Mar 30 '20 at 20:28

1 Answers1

2

You can have a look at the survey package in R. This is probably the most complete package regarding survey designs. You can find some elements in questionr package.

You can find some functions to compute summary statistics with weighted data in Hmisc package, e.g. Hmisc::wtd.quantile. If your survey design is complex, I would strongly encourage you to favor the survey package. Otherwise, the functions from Hmisc might be enough to start with

Regarding your example Hmisc does the job:

data2019$income_weighted <- Hmisc::wtd.mean(data2019$income, weights = data2019$population_weight)
linog
  • 5,786
  • 3
  • 14
  • 28