I'm using the R
survey package and trying to run the
calibrate function. My setup:
For each individual I have age, gender, income and education plus the U.S. county they live in. Age and income are continuous and education (0=has high school diploma, 1=bachelor's degree) and gender (0=male, 1=female) are binary.
For each U.S. county I have multiple statistics: median income, percentage of population different bins, etc.
Question: I'm having trouble figuring out how to specify the population statistics. The binary variables are straightforward: use the total population for each U.S. county for each bin. For the continuous variables I see two options:
- Bin each individual and treat as a categorical variable, specifying the population size for each category.
- Use the continuous variables and do X for the population data.
I'm not sure what X is. The one example I've seen does something like: average income per person in a population is
y and there are
z individuals in the population so set the population variable as
y*z. I guess I could substitute median income instead of average income but I'm seeing two issues
- I feel like the point of using a continuous variable is because you lose information when converting into a category. It seems like you also lose information when using only a mean value for the population instead of some full distribution.
- Is the real benefit from using calibration of raking is that you can specify the (1) optimization function and (2) bounds on the weights (which can be trimmed post-hoc anyway)? I've seen references that say this function doesn't matter much when using large sample.
What is the standard approach here? I actually have continuous gender and continuous education (i.e. probability of being in each class) so it would be nice to use continuous version for all of my variables.
Here is an example from the
survey package documentation:
library(survey) data(api) dclus1<-svydesign(id=~dnum, weights=~pw, data=apiclus1, fpc=~fpc) # here you break down stype by the categories H and M pop.totals<-c(`(Intercept)`=6194, stypeH=755, stypeM=1018) cal_names(~stype+api99, dclus1) # here we set the population total for api99 as 3914069 # this choice isn't documented anywhere (dclus1g3 <- calibrate(dclus1, ~stype+api99, c(pop.totals, api99=3914069)))
It's unclear what 3914069 means but I assume average
N is the population of the group.