calculating SE and MOE in R package srvyr for a proportion using replicate weights and PUMS data

Using the srvyr package and replicate weights REPWT, I would like to calculate the standard error and margin of error of the proportion (p) of households (HHWT) in the dataframe "data" that are paying over housing tax credit level rents, this is denoted in the dataframe by a "1" in the field OVERLIHTC. I'm able to get as far as shown below, but I don't know how to finish the code and print the results. Ideas?

p <- sum(data$HHWT[data$OVERLIHTC == 1]) / sum(data$HHWT)

svy <- as_survey(data, weight = HHWT , repweights = matches("REPWT[0-9]+"), type = "JK1", scale = 4/ 80 , rscales = rep(1, 80 ), mse = TRUE)

sub_design <- subset(svy, OverLIHTC == 1 )

Parents
  • Here is an example using the R survey package and the variable SEX

    Download PUMS data (using API)
    with variable SEX PWGTP and paste0("PWGTP",seq(1,80)) and save in data.frame pums
    (SEX 1=male 2=female)

    Create an indicator variable for the category "male"
    pums$male<-as.numeric(pums$SEX==1);
    require(survey)

    design<-svrepdesign(ids=~1,data=pums$male,weights=pums$PWGTP,repweights=pums[,paste0("PWGTP",seq(1,80))])

    sm<-svymean(~male,design);
               mean    SE
    male 0.45799 0.0094

    For an indicator (0/1) variable the mean is just the proportion.
    MoE<-sqrt(as.numeric(attr(sm,"var")))*qnorm(0.95);

    print(MoE)

    0.01200602

Reply
  • Here is an example using the R survey package and the variable SEX

    Download PUMS data (using API)
    with variable SEX PWGTP and paste0("PWGTP",seq(1,80)) and save in data.frame pums
    (SEX 1=male 2=female)

    Create an indicator variable for the category "male"
    pums$male<-as.numeric(pums$SEX==1);
    require(survey)

    design<-svrepdesign(ids=~1,data=pums$male,weights=pums$PWGTP,repweights=pums[,paste0("PWGTP",seq(1,80))])

    sm<-svymean(~male,design);
               mean    SE
    male 0.45799 0.0094

    For an indicator (0/1) variable the mean is just the proportion.
    MoE<-sqrt(as.numeric(attr(sm,"var")))*qnorm(0.95);

    print(MoE)

    0.01200602

Children
No Data