8
$\begingroup$

I just got my hands on the ANES (American National Election Studies) 2008 data set, and would like to do some simple analysis in R. However, I've never worked with this complex of a data set before and I've run into an issue.

The survey uses oversampling and has a variable for post stratification weights. I had only the vaguest idea of what that meant, so I read the wikipedia page on it, which I understand conceptually. Unfortunately, I don't know how to manipulate R such that the post stratification weights are reflected when I do my analysis.

While conceptually, the idea of oversampling didn't confuse me, the following documentation for the R "survey" package is completely unintelligible to me. I'll show what I've found so far, and I would really appreciate either an explanation of what's going on with these methods, or, if anyone knows a simpler way to apply a post-stratification weight to a data frame of variables, I'd love to here that too.

So, I found the "survey" package from CRAN, and I have the manual, and, after looking through it, it seems that the most promising method is:

postStratify(design, strata, population, partial = FALSE, ...)

However, when I look at the documentation for what needs to be passed for each of these arguments, I'm completely lost. They are as follows:

design           A survey design with replicate weights

strata           A formula or data frame of post-stratifying variables

population       A table, xtabs or data.frame with population frequencies

partial          if TRUE, ignore population strata not present in the sample

None of these make a lot of sense to me, but I'm pretty sure that the design argument is supposed to be of a class also defined in this package:

svydesign(ids, probs=NULL, strata = NULL, variables = NULL, fpc=NULL, 
    data = NULL, nest = FALSE, 
    check.strata = !nest, weights=NULL,pps=FALSE,...)

If you notice, there are a ton of optional arguments here, which all seem to do similar types of things (at least to me, after reading the docs...).

I'm basically at a loss for why this is so complicated in R. Am I misunderstanding things? Is there a simpler way to do this? Any help would be appreciated.

$\endgroup$
1

3 Answers 3

4
$\begingroup$

Looking at the example for postStratify in the manual, you are correct: you seem to be required to give a svydesign object (though you can if needed use svrepdesign to specify it instead).

The svydesign object must have ids; all the others are optional, though you will almost certainly want data to have something to work with, and you will probably want some of the others. At this stage I would suggest you ignore all those appearing after data.

postStratify also needs strata, the variable to post-stratify on: the example uses apiclus1$stype which simply specifies the school type (E, M or H). It also needs population which you can either specify yourself or take from some other source: the example gives data.frame(stype=c("E","H","M"), Freq=c(4421,755,1018)) though, as you say, table or xtabs can be used instead.

Again, you can then ignore all the other options unless you know you need them, so you can end up with something as simple as the example's dclus1p<-postStratify(dclus1, ~stype, pop.types).

$\endgroup$
4
$\begingroup$

If the weights already exist it's really simple. You'd have something like:

ANESData <- read.spss("C:/Data/ANESSurvey.spss ... bla bla bla)

# Fix id and weights for your data. 
ANESDesign <- svydesign(id = ~SAMPID, data = ANESData , weights = ~expwgt)    

I'm assuming you have the foreign and survey packages loaded....

$\endgroup$
0
$\begingroup$

I'd recommend taking a look at this Github repo:

On analyzing ANES in R

You'll want to do something like this:

anes.design <- 
    svydesign( 
        ~psu_full , 
        strata = ~strata_full , 
        data = y , 
        weights = ~weight_full , 
        nest = TRUE 
    )

Where y is your loaded dta file.

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.