Skip to content

Instantly share code, notes, and snippets.

@bschneidr
Last active August 27, 2022 15:18
Show Gist options
  • Save bschneidr/129f3b04b22f13c0d89bd37068a15ac5 to your computer and use it in GitHub Desktop.
Save bschneidr/129f3b04b22f13c0d89bd37068a15ac5 to your computer and use it in GitHub Desktop.
Analysis of plausible values with the survey package
# https://nces.ed.gov/surveys/piaac/datafiles.asp
# Load the survey data and prepare it for analysis ----
piaac17_puf <- file.path(
"C:\\Users\\benja\\Downloads\\spss\\prgusap1_puf.sav"
) |> haven::read_sav()
piaac17_rep_svy <- svrepdesign(
data = piaac17_puf,
repweights = "SPFWT[1-9]{1}0{0,1}",
weights = ~ SPFWT0,
type = "JK2"
)
# Repeat the analysis separately for each plausible value ----
separate_pv_results <- withPV(
data = piaac17_rep_svy,
# Use 'PVLITi' as shorthand for one of the i=1,...,10
# literacy plausible value variables
mapping = PVLITi ~ PVLIT1 + PVLIT2 + PVLIT3 + PVLIT4 + PVLIT5 +
PVLIT6 + PVLIT7 + PVLIT8 + PVLIT9 + PVLIT10,
# Within `quote()`, specify how to analyze the data with PVLITi
action = quote(
svymean(x = ~ PVLITi, design = piaac17_rep_svy, na.rm = TRUE)
)
)
# Combine the analysis results using Rubin's Rules ----
combined_pv_results <- MIcombine(mi_results)
coef(combined_pv_results) # Point estimate(s)
SE(combined_pv_results) # Std. error(s)
vcov(combined_pv_results) # Variance-covariance matrix
confint(combined_pv_results) # Confidence interval(s)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment