How are BRR weights used in the survey package for R?
Asked Answered
P

2

6

Does anyone know how to use BRR weights in Lumley's survey package for estimating variance if your dataset already has BRR weights it in?

I am working with PISA data, and they already include 80 BRR replicates in their dataset. How can I get as.svrepdesign to use these, instead of trying to create its own? I tried the following and got the subsequent error:

dstrat <- svydesign(id=~uniqueID,strata=~strataVar, weights=~studentWeight, 
                data=data, nest=TRUE)
dstrat <- as.svrepdesign(dstrat, type="BRR")

Error in brrweights(design$strata[, 1], design$cluster[, 1], ..., 
    fay.rho = fay.rho,  : Can't split with odd numbers of PSUs in a stratum

Any help would be greatly appreciated, thanks.

Prolocutor answered 16/10, 2012 at 0:31 Comment(2)
to work with pisa in R, this will do the correct setup for you :) you'll need to incorporate the multiple imputation in your analysis, which those scripts automate.Diskin
You could also try the RALSA package which has a graphical user interface: cran.r-project.org/package=RALSA For guides on how to use it, see here: ralsa.ineri.org/user-guideJurel
D
4

no need to use as.svrepdesign() if you have a data frame with the replicate weights already :) you can create the replicate weighted design directly from your data frame.

say you have data with a main weight column called mainwgt and 80 replicate weight columns called repwgt1 through repwgt80 you could use this --

yoursurvey <-
    svrepdesign( 
    weights = ~mainwgt , 
    repweights = "repwgt[0-9]+" , 
    type = "BRR", 
    data = yourdata ,
    combined.weights = TRUE
)

-- this way, you don't have to identify the exact column numbers. then you can run normal survey commands like --

svymean( ~variable , design = yoursurvey )

if you'd like another example, here's some example code and an explanatory blog post using the current population survey.

Diskin answered 25/10, 2012 at 16:33 Comment(4)
is it not necessary to specify type and rho arguments? I suppose one needs to know the specific design of the replicate weights to know?Tippets
i think type defaults to "BRR" but not 100%. rho is only needed for type = "Fay" example. :)Diskin
this answer is not sufficient if you use any of the "plausible values" variables (which are probably central to any analysis). to use those correctly, use this setup instead.Diskin
@AnthonyDamico would you please have a look at this link to provide ur suggestion for my question there please #77491183Photozincography
T
3

I haven't used the PISA data, I used the svprepdesign method last year with the Public Use Microsample from the American Community Survey (US Census Bureau) which also shipped with 80 replicate weights. They state to use the Fay method for that specific survey, so here is how one can construct the svyrep object using that data:

pums_p.rep<-svrepdesign(variables=pums_p[,2:7],
    repweights=pums_p[8:87],
    weights=pums_p[,1],combined.weights=TRUE,
    type="Fay",rho=(1-1/sqrt(4)),scale=1,rscales=1)

attach(pums_p.rep)
#CROSS - TABS
#unweighted
xtabs(~ is5to17youth + withinAMILimit) 
table(is5to17youth + withinAMILimit)

#weighted, mean income by sex by race for select age groups
svyby(~PINCP,~RAC1P+SEX,subset(
   pums_p.rep,AGEP > 25 & AGEP <35),na.rm = TRUE,svymean,vartype="se","cv")

In getting this to work, I found the article from A. Damico helpful: Damico, A. (2009). Transitioning to R: Replicating SAS, Stata, and SUDAAN Analysis Techniques in Health Policy Data. The R Journal, 1(2), 37–44.

Tippets answered 16/10, 2012 at 3:5 Comment(1)
ako would you please have a look at this link to provide ur suggestion for my question there please #77491183Photozincography

© 2022 - 2024 — McMap. All rights reserved.