Applying a population total variable in R?

172 Views Asked by At

I have a weighting variable that I'd like to apply to my dataset so that I have weighted totals. In SPSS, this is straightforward enough. However, in R, I've been multiplying the variable by the weight variable to create a new variable as shown in the following example:

https://stats.stackexchange.com/questions/210697/weighting-variable-based-on-another-variable

Is there a more sophisticated way of applying weights in R?

Thanks.

1

There are 1 best solutions below

1
On

If you need to work with a weighted dataset and define a complex survey sample, you can use the survey package : https://cran.r-project.org/web/packages/survey/survey.pdf. You can therefore use all sorts of summary statistics once you have defined the weights to be applied. However, I would advise this for complex weighted analysis.

Otherwise, there are several other packages dealing with weights such as questionr for instance.

It all depends on if you have to do a simple weighted sum or go on to do other types of analysis that require using more sophisticated methods.