combine_estimates: Combine MSE estimation results for a given stratum calculated...

View source: R/combine_estimates.R

combine_estimatesR 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 mse for all replicates being used for the analysis. The data frame should have columns N and n_obs from the mse function and an additional column replicate indicating which replicate the estimates were calculated on.

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

\insertRef

BDA3verdata

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)



verdata documentation built on June 8, 2025, 11:46 a.m.