# How does the rake() from survey package calculates the weights? [closed]

I run rake function from the survey package of R in my data and got the weights by calling the weights() function. Sample code

small.svy.unweighted <- svydesign(ids=~1, strata = ~HZIP ,data=HHdata, weights=~Weights_1)

small.svy.rake <- rake(design = small.svy.unweighted,
sample.margins = list(~agecats, ~zip),
population.margins = list(age.dist, zip.dist))


Questions:

1. Are the weights return by weights(small.svy.rake) function become the new samplings weights? That is, if i run the analysis in the eg. SPSS, the weights will be my input weights?

2. How does the algorithm manually computes the weights? I tried to manually compute it but I could not get the same weights return by weights().

• What is survey package, what language? Language specific questions can be off-topic. – ttnphns Jan 15 '17 at 18:58
• Rim or raking weighting is a way to compute frequency weights for 2+ categorical features, i.e. for multiway frequency table. It is based on proportional fitting algorithm which is quite simple. Iteratively bring marginal profiles to the wanted (target) ones by multiplying by coefficient target freqs / currently observed freqs. The method is called "rim" because it goes though marginals (sides) of the table on each iteration. – ttnphns Jan 15 '17 at 18:59
• (cont.) Rim weighting assumes that "disproportions" in the cells of the input table were due to affected main effects only, and it aims to recover the situation "going same way back". In SPSS, you can use advanced (with options) rim-weighting macro found on my web-page (package called "weighting groups"). There is also an extension command Rake written by Jon Peck and included right with SPSS. – ttnphns Jan 15 '17 at 18:59
• Did you read the help file...? It says it operates by repeated calls to postStratify(); if you look there there is an associated paper (Valliant R (1993) Post-stratification and conditional variance estimation. JASA 88: 89-96) that could quell some of your confusion. – gammer Jan 15 '17 at 19:32
• hi, if you don't find the answer you are looking for in the documentation, you will need to either view the code by typing survey:::rake or step through the function with debug(rake). you can also type debug(weights) to view what happens inside of that function – Anthony Damico Jan 16 '17 at 10:43