combine_estimates {verdata} | R Documentation |
Combine MSE estimation results for a given stratum calculated using multiple replicate files created using multiple imputation. Combination is done using the standard approach that makes use of the laws of total expectation and total variance.
Description
Combine MSE estimation results for a given stratum calculated using multiple replicate files created using multiple imputation. Combination is done using the standard approach that makes use of the laws of total expectation and total variance.
Usage
combine_estimates(stratum_estimates)
Arguments
stratum_estimates |
A data frame of estimates for a stratum of interest
calculated using |
Value
A data frame row with the point estimate (N_mean
) and the
associated 95% uncertainty interval (lower bound is N_025
, upper bound is
N_975
).
References
Gelman A, Carlin JB, Stern HS, Dunson DB, Vehtari A, Rubin DB (2013). Bayesian Data Analysis, 0 edition. Chapman and Hall/CRC. ISBN 978-0-429-11307-9, doi:10.1201/b16018.
Examples
set.seed(19481210)
library(dplyr)
library(purrr)
library(glue)
simulate_estimates <- function(stratum_data, replicate_num) {
# simulate an imputed stratification variable to determine whether a record
# should be considered part of the stratum for estimation
stratification_var <- sample(c(0, 1), size = 100,
replace = TRUE, prob = c(0.1, 0.9))
my_stratum <- bind_cols(my_stratum, tibble::tibble(stratification_var)) %>%
filter(stratification_var == 1)
results <- mse(my_stratum, "my_stratum", K = 4) %>%
mutate(replicate = replicate_num)
return(results)
}
in_A <- sample(c(0, 1), size = 100, replace = TRUE, prob = c(0.45, 0.65))
in_B <- sample(c(0, 1), size = 100, replace = TRUE, prob = c(0.5, 0.5))
in_C <- sample(c(0, 1), size = 100, replace = TRUE, prob = c(0.75, 0.25))
my_stratum <- tibble::tibble(in_A, in_B, in_C)
replicate_nums <- glue("R{1:20}")
estimates <- map_dfr(.x = replicate_nums,
.f = ~simulate_estimates(stratum_data = my_stratum, replicate_num = .x))
combine_estimates(estimates)