0

I am looking to replicate a program in SAS (rake_and_trim) that uses raking to produce weights for an aggregated sample dataset (i.e. I only have the marginal totals for each raking variable in the sample data). From what I can tell, the existing raking procedures in R require individual-level data. I've looked at "rake" and "calibrate" and "anesrake" options but can't figure out how to only input marginal totals for the sample.

Here's an example of how my aggregate sample data would be structured:

Age_Group   Gender  n   Prev_Obesity
15 - 19      F    1623  22
15 - 19      M    924   24
20 - 24      F    4321  29
20 - 24      M    1776  28
25 - 29      F    4833  33
25 - 29      M    1922  29

Here's an example using "rake" from the survey package:

library(survey)

I'm assuming equal probability sampling with no sampling design

data.svy.unweighted <- svydesign(ids=~1, data=data)

This is where I specify the marginal totals for the population (also called target, control, or reference)

gender.dist <- data.frame(gender = c("1", "2"),
                      Freq = nrow(data) * c(0.45, 0.55)) 

Here is the procedure to rake, and the sample.margins calculate ~gender from an individual-level data frame only. What I would like is to be able to input the sample gender marginals similar to how the population.margins are created.

data.svy.rake <- rake(design = data.svy.unweighted,
                  sample.margins = list(~gender),
                  population.margins = list(gender.dist))

Thanks for any advice on how to do this!

Emily B
  • 1
  • 1
  • 1
    Hi and welcome to StackOverflow! Please edit your question and emphasise on what exactly your problem is: what have you tried, where is it failing, ... For R questions, [this community wiki](https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example) lists some approaches for asking great R questions :) – Oliver Baumann Oct 21 '18 at 16:10
  • Welcome to SO! Please read [ask] and give a [mcve] in your question! – jogo Oct 21 '18 at 16:10
  • hi, how does your output look like – Kiran Oct 21 '18 at 18:06
  • how does intial data and output should look like, – Kiran Oct 21 '18 at 18:26

0 Answers0