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!