View source: R/combine_estimates.R
combine_estimates | 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.
combine_estimates(stratum_estimates)
stratum_estimates |
A data frame of estimates for a stratum of interest
calculated using |
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
).
BDA3verdata
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)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.