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
  • I would personally use dplyr (https://dplyr.tidyverse.org/index.html) to summarize this (since srvyr is designed to work with the dplyr syntax) and do something like this. (I can't see your actual dataset, so you may need to tweak this.) NOTE: You'll need to convert OVERLIHTC to a character vector if it's not one already for this to work correctly. 

    svy |>

    group_by(OVERLIHTC) |>
    summarise(Percent = survey_mean())

    That should provide a df with the percentage and SE for each percentage. 

Reply
  • I would personally use dplyr (https://dplyr.tidyverse.org/index.html) to summarize this (since srvyr is designed to work with the dplyr syntax) and do something like this. (I can't see your actual dataset, so you may need to tweak this.) NOTE: You'll need to convert OVERLIHTC to a character vector if it's not one already for this to work correctly. 

    svy |>

    group_by(OVERLIHTC) |>
    summarise(Percent = survey_mean())

    That should provide a df with the percentage and SE for each percentage. 

Children
No Data