Corey Sparks R blog

I post regularly on various R topics, mostly involving data on people

DEM 7283 - Example 1 - Survey Statistics using BRFSS data

Written on February 1, 2021

What is a survey?

A systematic method for gathering information from a sample of entities for the purposes of constructing quantitative descriptors of the attributes of the larger population of which the entities are members

Questions when identifying a survey data source:

  1. What is the target population?
  2. What is the sampling frame
  • how do we know who could be included?
  1. What is the sample design?
  2. What is the mode of data collection?
  3. Is the survey ongoing or a one-time collection?

Core Concepts

Sampling units - where information will be collected from Sampling frame - the set of sampling units containing distinct sets of population members

Weights and weighting

Surveys with complex sample designs will often have:

  • Unequal probabilities of selection
  • Variation in response rates across groups
  • Differences in distributions of characteristics compared to the population

Weights are used to compensate for these features

What is a weight?

  • A weight is used to indicate the relative strength of an observation.

  • In the simplest case, each observation is counted equally.

  • For example, if we have five observations, and wish to calculate the mean, we just add up the values and divide by 5.

Dataset with 5 cases

library(htmlTable)
y<-c(4,2,1,5,2)
wt<-c(1,2,4,1,2)
dat<-data.frame(y=y, weight=wt)
htmlTable(dat)
y weight
1 4 1
2 2 2
3 1 4
4 5 1
5 2 2

Unweighted sample mean

mean(dat$y)
## [1] 2.8

Weighted sample mean

library(questionr)
wtd.mean(x=dat$y, weights=dat$weight)
## [1] 2.1

Difference between unweighted and weighted data

  • With unweighted data, each case is counted equally.

  • Unweighted data represent only those in the sample who provide data.

  • With weighted data, each case is counted relative to its representation in the population.

  • Weights allow analyses that represent the target population.

Weights compensate for collecting data from a sample rather than the entire population and for using a complex sample design.

Weights adjust for differential selection probabilities and reduce bias associated with non-response by adjusting for differential nonresponse. Weights are used when estimating characteristics of the population.

Sample variance estimation in complex designs

Standard errors are produced for estimates from sample surveys. They are a measure of the variance in the estimates associated with the selected sample being one of many possible samples.

Standard errors are used to test hypotheses and to study group differences.

Using inaccurate standard errors can lead to identification of statistically significant results where none are present and vice versa

Complex survey designs and standard errors

  • The usual standard error formula assumes a simple random sample.

  • Software packages designed for simple random samples tend to underestimate the standard errors for complex sample designs.

  • Standard errors for estimates from a complex sample must account for the within cluster/ across cluster variation.

  • Special software can make the adjustment, or this adjustment can be approximated using the design effect.

Methods for sample variance estimation

There are basically 3 ways in which software estimates variances: 1) Naive method 2) Taylor series approximation 3) Balanced or Jackknife replication

Data Example

This example will cover the use of R functions for analyzing complex survey data. Most social and health surveys are not simple random samples of the population, but instead consist of respondents from a complex survey design.

These designs often stratify the population based on one or more characteristics, including geography, race, age, etc. In addition the designs can be multi-stage, meaning that initial strata are created, then respondents are sampled from smaller units within those strata.

An example would be if a school district was chosen as a sample strata, and then schools were then chosen as the primary sampling units (PSUs) within the district. From this 2 stage design, we could further sample classrooms within the school (3 stage design) or simply sample students (or whatever our unit of interest is).

Multi-stage sampling

  • Non-random sampling
  • Population consists of known sub-groups called clusters
  • A 2 -stage sample might be households within neighborhoods, or children within schools
    • We may choose a random sample of schools/neighborhoods at the first stage, and a random sample of people within each school/neighborhood as the second stage
    • We need to be careful because the observations in the second stage are not independent of one another
    • Increased probability of selection for children in a selected school
  • This type of sampling leads to dependent observations

Here’s a picture of this:

Multistage Sampling - From Kawachi and Berkman, 2003

A second feature of survey data we often want to account for is differential respondent weighting. This means that each respondent is given a weight to represent how common that particular respondent is within the population. This reflects the differenital probability of sampling based on respondent characteristics.

As demographers, we are also often interested in making inference for the population, not just the sample, so our results must be generalizable to the population at large. Sample weights are used in the process as well.

When such data are analyzed, we must take into account this nesting structure (sample design) as well as the respondent sample weight in order to make valid estimates of ANY statistical parameter. If we do not account for design, the parameter standard errors will be incorrect, and if we do not account for weighting, the parameters themselves will be incorrect and biased.

In general there are typically three things we need to find in our survey data codebooks: The sample strata identifier, the sample primary sampling unit identifier (often called a cluster identifier) and the respondent survey weight. These will typically have one of these names and should be easily identifiable in the codebook.

Statistical software will have special routines for analyzing these types of data and you must be aware that the diversity of statistical routines that generally exists will be lower for analyzing complex survey data, and some forms of analysis may not be available!

See Thomas Lumley’s Book on this!

Below I illustrate the use of survey characteristics when conducting descriptive analysis of a survey data set and a linear regression model estimated from that data. For this example I am using 2016 CDC Behavioral Risk Factor Surveillance System (BRFSS) SMART metro area survey data. Link

#load brfss
library(car)
## Loading required package: carData
library(stargazer)
## 
## Please cite as:
##  Hlavac, Marek (2018). stargazer: Well-Formatted Regression and Summary Statistics Tables.
##  R package version 5.2.2. https://CRAN.R-project.org/package=stargazer
library(survey)
## Loading required package: grid
## Loading required package: Matrix
## Loading required package: survival
## 
## Attaching package: 'survey'
## The following object is masked from 'package:graphics':
## 
##     dotchart
library(questionr)
library(dplyr)
## 
## Attaching package: 'dplyr'
## The following object is masked from 'package:car':
## 
##     recode
## The following objects are masked from 'package:stats':
## 
##     filter, lag
## The following objects are masked from 'package:base':
## 
##     intersect, setdiff, setequal, union
load(url("https://github.com/coreysparks/data/blob/master/brfss_2017.Rdata?raw=true"))

Fix variable names

#The names in the data are very ugly, so I make them less ugly
nams<-names(brfss_17)
head(nams, n=10)
##  [1] "dispcode" "statere1" "safetime" "hhadult"  "genhlth"  "physhlth"
##  [7] "menthlth" "poorhlth" "hlthpln1" "persdoc2"
#we see some names are lower case, some are upper and some have a little _ in the first position. This is a nightmare.
newnames<-tolower(gsub(pattern = "_",replacement =  "",x =  nams))
names(brfss_17)<-newnames

Recoding of variables

Be sure to always check your codebooks!

#Poor or fair self rated health
brfss_17$badhealth<-Recode(brfss_17$genhlth, recodes="4:5=1; 1:3=0; else=NA")

#sex
brfss_17$male<-as.factor(ifelse(brfss_17$sex==1, "Male", "Female"))

#race/ethnicity
brfss_17$black<-Recode(brfss_17$racegr3, recodes="2=1; 9=NA; else=0")
brfss_17$white<-Recode(brfss_17$racegr3, recodes="1=1; 9=NA; else=0")
brfss_17$other<-Recode(brfss_17$racegr3, recodes="3:4=1; 9=NA; else=0")
brfss_17$hispanic<-Recode(brfss_17$racegr3, recodes="5=1; 9=NA; else=0")

#insurance
brfss_17$ins<-Recode(brfss_17$hlthpln1, recodes ="7:9=NA; 1=1;2=0")

#income grouping
brfss_17$inc<-ifelse(brfss_17$incomg==9, NA, brfss_17$incomg)

#education level
brfss_17$educ<-Recode(brfss_17$educa, recodes="1:2='0Prim'; 3='1somehs'; 4='2hsgrad'; 5='3somecol'; 6='4colgrad';9=NA", as.factor=T)
brfss_17$educ<-relevel(brfss_17$educ, ref='2hsgrad')

#employment
brfss_17$employ<-Recode(brfss_17$employ1, recodes="1:2='Employed'; 2:6='nilf'; 7='retired'; 8='unable'; else=NA", as.factor=T)
brfss_17$employ<-relevel(brfss_17$employ, ref='Employed')

#marital status
brfss_17$marst<-Recode(brfss_17$marital, recodes="1='married'; 2='divorced'; 3='widowed'; 4='separated'; 5='nm';6='cohab'; else=NA", as.factor=T)
brfss_17$marst<-relevel(brfss_17$marst, ref='married')

#Age cut into intervals
brfss_17$agec<-cut(brfss_17$age80, breaks=c(0,24,39,59,79,99))

#BMI, in the brfss_17a the bmi variable has 2 implied decimal places, so we must divide by 100 to get real bmi's

brfss_17$bmi<-brfss_17$bmi5/100
brfss_17$obese<-ifelse(brfss_17$bmi>=30, 1, 0)

Filter cases

brfss_17<-brfss_17%>%
  filter(sex!=9, is.na(educ)==F)

Analysis

First, we will do some descriptive analysis, such as means and cross tabulations.

#First we will do some tables
#Raw frequencies
table(brfss_17$badhealth, brfss_17$educ)
##    
##     2hsgrad 0Prim 1somehs 3somecol 4colgrad
##   0   42204  2657    5581    50592    87642
##   1   13533  2412    3843    11544     9177
#column percentages
prop.table(table(brfss_17$badhealth, brfss_17$educ), margin=2)
##    
##        2hsgrad      0Prim    1somehs   3somecol   4colgrad
##   0 0.75719899 0.52416650 0.59221138 0.81421398 0.90521489
##   1 0.24280101 0.47583350 0.40778862 0.18578602 0.09478511
#basic chi square test of independence
chisq.test(table(brfss_17$badhealth, brfss_17$educ))
## 
##  Pearson's Chi-squared test
## 
## data:  table(brfss_17$badhealth, brfss_17$educ)
## X-squared = 12749, df = 4, p-value < 2.2e-16

So basically all of these numbers are incorrect, since they all assume random sampling. Now, we must tell R what the survey design is and what the weight variable is, then we can re-do these so they are correct.

Create a survey design object

Now we identify the survey design. ids = PSU identifers, strata=strata identifiers, weights=sampling weights, data= the data frame where these variables are located. Lastly, I only include respondents with NON-MISSING case weights.

I first try to get only cities in the state of Texas by looking for “TX” in the MSA’s name field in the data.

brfss_17$tx<-NA
brfss_17$tx[grep(pattern = "TX", brfss_17$mmsaname)]<-1

Now I make the survey design object. You may be required to specify two options here:

  1. survey.lonely.psu This means that some of the strata only have 1 PSU within them. This does not allow for within strata variance to be calculated. So we often have to tell the computer to do something here. Two valid options are “adjust”, to center the stratum at the population mean rather than the stratum mean, and “average” to replace the variance contribution of the stratum by the average variance contribution across strata. (from ?surveyoptions)

  2. Nesting of PSU within strata. By default, PSUs have numeric identifiers that can overlap between strata. By specifying nest=T, we tell R to re-lable the PSUs so they are unique across strata. If your survey requires this, it will throw a warning message.

brfss_17<-brfss_17%>%
  filter(tx==1, is.na(mmsawt)==F, is.na(badhealth)==F)

#
options(survey.lonely.psu = "adjust")

des<-svydesign(ids=~1, strata=~ststr, weights=~mmsawt, data = brfss_17 )

###Simple weighted analysis Now , we re-do the analysis from above using only weights:

#counts
cat<-wtd.table(brfss_17$badhealth, brfss_17$educ, weights = brfss_17$mmsawt)

#proportions
prop.table(wtd.table(brfss_17$badhealth, brfss_17$educ, weights = brfss_17$mmsawt), margin=2)
##      2hsgrad      0Prim    1somehs   3somecol   4colgrad
## 0 0.75785067 0.60034582 0.66897765 0.83478907 0.91149676
## 1 0.24214933 0.39965418 0.33102235 0.16521093 0.08850324
#compare that with the original, unweighted proportions
prop.table(table(brfss_17$badhealth, brfss_17$educ), margin=2)
##    
##       2hsgrad     0Prim   1somehs  3somecol  4colgrad
##   0 0.7090336 0.5686813 0.6226013 0.7797297 0.8837339
##   1 0.2909664 0.4313187 0.3773987 0.2202703 0.1162661

There are differences, notably that the prevalence of poor SRH is higher in the sample than the population. This is important!

Let’s say we also want the standard errors of these percentages. This can be found for a proportion by: \(s.e. (p)={\sqrt {p(1-p)} \over {n}}\)

So we need to get n and p, that’s easy:

n<-table(is.na(brfss_17$badhealth)==F)
n

TRUE 8535

p<-prop.table(wtd.table(brfss_17$badhealth, brfss_17$educ, weights = brfss_17$mmsawt), margin=2)
t(p)
              0          1

2hsgrad 0.75785067 0.24214933 0Prim 0.60034582 0.39965418 1somehs 0.66897765 0.33102235 3somecol 0.83478907 0.16521093 4colgrad 0.91149676 0.08850324

p<-prop.table(wtd.table(brfss_17$badhealth, brfss_17$male, weights = brfss_17$mmsawt), margin=2)
t(p)
           0         1

Female 0.7913522 0.2086478 Male 0.8189935 0.1810065

se<-(p*(1-p))/n[2]

p<-

knitr::kable(data.frame(proportion=p, se=sqrt(se))[, c(1,2,3,6)], format = "html", caption = "Frequencies assuming random sampling")

Which shows us the errors in the estimates based on the weighted proportions. That’s nice, but since we basically inflated the n to be the population of the US, these standard errors are too small. This is another example of using survey statistical methods, to get the right standard error for a statistic.

Proper survey design analysis

#Now consider the full sample design + weights
cat<-svyby(formula = ~badhealth, by=~male, design = des, FUN=svymean)

svychisq(~badhealth+male, design = des)
Pearson's X^2: Rao & Scott adjustment

data: svychisq(~badhealth + male, design = des) F = 2.2685, ndf = 1, ddf = 8486, p-value = 0.1321

knitr::kable(cat,
      caption = "Survey Estimates of Poor SRH by Sex",
      align = 'c',  
      format = "html")
Survey Estimates of Poor SRH by Sex
male badhealth se
Female Female 0.2086478 0.0129755
Male Male 0.1810065 0.0128833

Which gives the same %’s as the weighted table above, but we also want the correct standard errors for our bad health prevalence.

The svyby() function will calculate statistics by groups, in this case we want the % in bad health by each level of education. The %’s can be gotten using the svymean() function, which finds means of variables using survey design:

sv.table<-svyby(formula = ~badhealth, by = ~educ, design = des, FUN = svymean, na.rm=T)


knitr::kable(sv.table,
      caption = "Survey Estimates of Poor SRH by Education",
      align = 'c',  
      format = "html")
Survey Estimates of Poor SRH by Education
educ badhealth se
2hsgrad 2hsgrad 0.2421493 0.0193807
0Prim 0Prim 0.3996542 0.0483989
1somehs 1somehs 0.3310224 0.0425548
3somecol 3somecol 0.1652109 0.0147720
4colgrad 4colgrad 0.0885032 0.0094730
#Make a survey design that is random sampling - no survey information
nodes<-svydesign(ids = ~1,  weights = ~1, data = brfss_17)

sv.table<-svyby(formula = ~badhealth, by = ~educ, design = nodes, FUN = svymean, na.rm=T)


knitr::kable(sv.table,
      caption = "Estimates of Poor SRH by Education - No survey design",
      align = 'c',  
      format = "html")
Estimates of Poor SRH by Education - No survey design
educ badhealth se
2hsgrad 2hsgrad 0.2909664 0.0104099
0Prim 0Prim 0.4313187 0.0259602
1somehs 1somehs 0.3773987 0.0223843
3somecol 3somecol 0.2202703 0.0087963
4colgrad 4colgrad 0.1162661 0.0053591

And we see the same point estimates of our prevalences as in the simple weighted table, but the standard errors have now been adjusted for survey design as well, so they are also correct. You also see they are much larger than the ones we computed above, which assumed random sampling.

Another way

There’s this great R package, tableone that does this stuff very nicely and incorporates survey design too. Here’s an example of using it to generate your bi-variate tests like above:

library(tableone)
#not using survey design
t1<-CreateTableOne(vars = c("educ", "marst", "male"), strata = "badhealth", test = T, data = brfss_17)
#t1<-print(t1, format="p")
print(t1,format="p")
##                  Stratified by badhealth
##                   0    1    p      test
##   n               6742 1793            
##   educ (%)                  <0.001     
##      2hsgrad      20.0 30.9            
##      0Prim         3.1  8.8            
##      1somehs       4.3  9.9            
##      3somecol     25.7 27.3            
##      4colgrad     46.9 23.2            
##   marst (%)                 <0.001     
##      married      53.4 41.1            
##      cohab         3.4  2.5            
##      divorced     11.9 16.7            
##      nm           16.1 13.8            
##      separated     2.0  5.1            
##      widowed      13.2 20.7            
##   male = Male (%) 43.0 36.9 <0.001
#using survey design
st1<-svyCreateTableOne(vars = c("educ", "marst", "male"), strata = "badhealth", test = T, data = des)
#st1<-print(st1, format="p")
print(st1, format="p")
##                  Stratified by badhealth
##                   0          1         p      test
##   n               12270182.9 2975288.5            
##   educ (%)                             <0.001     
##      2hsgrad            23.3      30.8            
##      0Prim               6.1      16.7            
##      1somehs             6.6      13.4            
##      3somecol           32.3      26.4            
##      4colgrad           31.6      12.7            
##   marst (%)                            <0.001     
##      married            52.9      46.8            
##      cohab               5.7       3.3            
##      divorced            9.5      14.4            
##      nm                 24.9      21.1            
##      separated           2.1       7.1            
##      widowed             4.9       7.3            
##   male = Male (%)       49.7      45.3  0.132

Regression example

Next we apply this logic to a regression case. First we fit the OLS model for our BMI outcome using education and age as predictors:

fit1<-lm(bmi~educ+agec, data=brfss_17)

Next we incorporate case weights

fit2<-lm(bmi~educ+agec, data=brfss_17, weights = mmsawt)

Now we will incorporate design effects as well:

fit3<-svyglm(bmi~educ+agec,des, family=gaussian)

Now I make a table to show the results of the three models:

stargazer(fit1, fit2, fit3, style="demography", type="html",
          column.labels = c("OLS", "Weights Only", "Survey Design"),
          title = "Regression models for BMI using survey data - BRFSS 2016", 
          covariate.labels=c("PrimarySchool", "SomeHS", "SomeColl", "CollGrad", "Age 24-39","Age 39-59" ,"Age 59-79", "Age 80+"), 
          keep.stat="n", model.names=F, align=T, ci=T)
Regression models for BMI using survey data - BRFSS 2016
bmi
OLS Weights Only Survey Design
Model 1 Model 2 Model 3
PrimarySchool 0.114 -0.521 -0.521
(-0.671, 0.899) (-1.088, 0.046) (-1.798, 0.756)
SomeHS -0.006 -0.699* -0.699
(-0.687, 0.674) (-1.266, -0.132) (-2.080, 0.682)
SomeColl -0.456* -1.255*** -1.255**
(-0.860, -0.052) (-1.619, -0.892) (-2.094, -0.417)
CollGrad -1.972*** -2.463*** -2.463***
(-2.342, -1.602) (-2.839, -2.086) (-3.228, -1.697)
Age 24-39 2.943*** 3.221*** 3.221***
(2.263, 3.624) (2.771, 3.672) (2.345, 4.097)
Age 39-59 4.388*** 4.745*** 4.745***
(3.742, 5.034) (4.306, 5.183) (3.868, 5.621)
Age 59-79 3.476*** 4.005*** 4.005***
(2.846, 4.107) (3.529, 4.481) (3.039, 4.971)
Age 80+ 0.810* 0.819 0.819
(0.076, 1.543) (-0.051, 1.688) (-0.496, 2.133)
Constant 26.045*** 26.179*** 26.179***
(25.423, 26.667) (25.761, 26.597) (25.338, 27.019)
N 7,840 7,840 7,840
</sup>p < .05; </sup>p < .01; </strong></em>p < .001 </td> </tr> </table>

Notice, the results for the education levels are much less significant than the were with either of the other two analysis. This is because those models had standard errors for the parameters that were too small. You see all the standard errors are larger and the T statistics are smaller.

Which shows the same \(\beta\)’s between the survey design model and the weighted model but the standard errors are larger in the survey model, so the test statistics are more conservative (smaller t statistics).

While in this simple model, our overall interpretation of the effects do not change (positive effects of education, negative effects of age), it is entirely possible that they could once we include our survey design effects.

It may be informative to plot the results of the models to see how different the coefficients are from one another:

library(ggplot2)
library(dplyr)
coefs<-data.frame(coefs=c(coef(fit1)[-1], coef(fit3)[-1]),
                  mod=c(rep("Non Survey Model", 8),rep("Survey Model", 8)),
                  effect=rep(names(coef(fit1)[-1]), 2))

coefs%>%
  ggplot()+
  geom_point(aes( x=effect, y=coefs, group=effect,color=effect, shape=mod),
             position=position_jitterdodge(jitter.width = 1),
             size=2)+
  ylab("Regression Coefficient")+
  xlab("Beta")+
  geom_abline(intercept = 0, slope=0)+
  theme(axis.text.x = element_text(angle = 45, hjust = 1))+
  ggtitle(label = "Comparison of Survey and Non-Survey Regression effects")

Which shows us that the betas are similar but have some differences between the two models.

</div>

Creating Survey estimates for places

One of the coolest ways to use the BRFSS is to calculate estimates for places, and by demographic characteristics withing places. Again, we use svyby() to do this, but now we calculate obesity rates by sex within cities.

citytab<-svyby(~obese, ~mmsaname, design=des,FUN = svymean, na.rm=T )
knitr::kable(citytab, type="html", digits=3,caption = "Obesity Estimats for TX MSAs")
Obesity Estimats for TX MSAs
mmsaname obese se
Austin-Round Rock, TX, Metropolitan Statistical Area Austin-Round Rock, TX, Metropolitan Statistical Area 0.294 0.021
College Station-Bryan, TX, Metropolitan Statistical Area College Station-Bryan, TX, Metropolitan Statistical Area 0.308 0.052
Corpus Christi, TX, Metropolitan Statistical Area Corpus Christi, TX, Metropolitan Statistical Area 0.362 0.034
Dallas-Plano-Irving, TX, Metropolitan Division Dallas-Plano-Irving, TX, Metropolitan Division 0.286 0.025
El Paso, TX, Metropolitan Statistical Area El Paso, TX, Metropolitan Statistical Area 0.347 0.029
Fort Worth-Arlington, TX, Metropolitan Division Fort Worth-Arlington, TX, Metropolitan Division 0.367 0.028
Houston-The Woodlands-Sugar Land, TX, Metropolitan Statistical Area Houston-The Woodlands-Sugar Land, TX, Metropolitan Statistical Area 0.307 0.022
San Antonio-New Braunfels, TX, Metropolitan Statistical Area San Antonio-New Braunfels, TX, Metropolitan Statistical Area 0.308 0.033
Wichita Falls, TX, Metropolitan Statistical Area Wichita Falls, TX, Metropolitan Statistical Area 0.425 0.055

Using srvyr

There’s a new package called srvyr that incorporates the survey analysis stuff into the dplyr universe:

library(srvyr)
brfsurv<-brfss_17%>%
  as_survey_design(1,strata=ststr,weights=mmsawt )


brfsurv%>%
  group_by(mmsaname)%>%
    summarise(obprev = survey_mean(obese, na.rm=T))

Replicate Weights

If your dataset comes with replicate weights, you have to specify the survey design slightly differently. Here is an example using the IPUMS CPS data. For this data, you can get information here, but you must consult your specific data source for the appropriate information for your data.

load(url("https://github.com/coreysparks/data/blob/master/cpsmar10tx.Rdata?raw=true"))
names(cpsmar10tx)
##   [1] "year"     "serial"   "hwtsupp"  "repwt"    "statefip" "metarea" 
##   [7] "foodstmp" "REPWT1"   "REPWT2"   "REPWT3"   "REPWT4"   "REPWT5"  
##  [13] "REPWT6"   "REPWT7"   "REPWT8"   "REPWT9"   "REPWT10"  "REPWT11" 
##  [19] "REPWT12"  "REPWT13"  "REPWT14"  "REPWT15"  "REPWT16"  "REPWT17" 
##  [25] "REPWT18"  "REPWT19"  "REPWT20"  "REPWT21"  "REPWT22"  "REPWT23" 
##  [31] "REPWT24"  "REPWT25"  "REPWT26"  "REPWT27"  "REPWT28"  "REPWT29" 
##  [37] "REPWT30"  "REPWT31"  "REPWT32"  "REPWT33"  "REPWT34"  "REPWT35" 
##  [43] "REPWT36"  "REPWT37"  "REPWT38"  "REPWT39"  "REPWT40"  "REPWT41" 
##  [49] "REPWT42"  "REPWT43"  "REPWT44"  "REPWT45"  "REPWT46"  "REPWT47" 
##  [55] "REPWT48"  "REPWT49"  "REPWT50"  "REPWT51"  "REPWT52"  "REPWT53" 
##  [61] "REPWT54"  "REPWT55"  "REPWT56"  "REPWT57"  "REPWT58"  "REPWT59" 
##  [67] "REPWT60"  "REPWT61"  "REPWT62"  "REPWT63"  "REPWT64"  "REPWT65" 
##  [73] "REPWT66"  "REPWT67"  "REPWT68"  "REPWT69"  "REPWT70"  "REPWT71" 
##  [79] "REPWT72"  "REPWT73"  "REPWT74"  "REPWT75"  "REPWT76"  "REPWT77" 
##  [85] "REPWT78"  "REPWT79"  "REPWT80"  "REPWT81"  "REPWT82"  "REPWT83" 
##  [91] "REPWT84"  "REPWT85"  "REPWT86"  "REPWT87"  "REPWT88"  "REPWT89" 
##  [97] "REPWT90"  "REPWT91"  "REPWT92"  "REPWT93"  "REPWT94"  "REPWT95" 
## [103] "REPWT96"  "REPWT97"  "REPWT98"  "REPWT99"  "REPWT100" "REPWT101"
## [109] "REPWT102" "REPWT103" "REPWT104" "REPWT105" "REPWT106" "REPWT107"
## [115] "REPWT108" "REPWT109" "REPWT110" "REPWT111" "REPWT112" "REPWT113"
## [121] "REPWT114" "REPWT115" "REPWT116" "REPWT117" "REPWT118" "REPWT119"
## [127] "REPWT120" "REPWT121" "REPWT122" "REPWT123" "REPWT124" "REPWT125"
## [133] "REPWT126" "REPWT127" "REPWT128" "REPWT129" "REPWT130" "REPWT131"
## [139] "REPWT132" "REPWT133" "REPWT134" "REPWT135" "REPWT136" "REPWT137"
## [145] "REPWT138" "REPWT139" "REPWT140" "REPWT141" "REPWT142" "REPWT143"
## [151] "REPWT144" "REPWT145" "REPWT146" "REPWT147" "REPWT148" "REPWT149"
## [157] "REPWT150" "REPWT151" "REPWT152" "REPWT153" "REPWT154" "REPWT155"
## [163] "REPWT156" "REPWT157" "REPWT158" "REPWT159" "REPWT160" "month"   
## [169] "pernum"   "wtsupp"   "relate"   "age"      "sex"      "race"    
## [175] "marst"    "offpov"   "MIGRATE1"

So we see the replicate weights are in columns 8 through 167 in the data

#simple binary outcome
cpsmar10tx$poverty<-ifelse(cpsmar10tx$offpov==1,1,0)

# Replicate weight design - I got these details from the data source, you should too
des2<-svrepdesign( data = cpsmar10tx,repweights = cpsmar10tx[, c(8:167)]  ,
                   weights = ~wtsupp ,
                   type="JK1",
                   scale=.025)
des2
## Call: svrepdesign.default(data = cpsmar10tx, repweights = cpsmar10tx[, 
##     c(8:167)], weights = ~wtsupp, type = "JK1", scale = 0.025)
## Unstratified cluster jacknife (JK1) with 160 replicates.
#Without design
prop.table(table(cpsmar10tx$poverty))
## 
##         0         1 
## 0.8374617 0.1625383
#with design
prop.table(svytable(~poverty, design = des2))
## poverty
##         0         1 
## 0.8481106 0.1518894
#Again, using the mean
mean(cpsmar10tx$poverty)
## [1] 0.1625383
#Using the design. This would be an official estimate of poverty in TX in 2010:
svymean(~poverty, design=des2)
##            mean    SE
## poverty 0.15189 0.007
</div> </section>