hmi_pool: Averages the results of the imputation function 'hmi'.

Description Usage Arguments Value Examples

Description

This function applies the analysis the user wants to run on every imputed dataset. The results from every dataset are pooled by simply averaging. So the user has to make sure that averaging the analysis produces results is meaningful. Currently variance estimates for the averaged results are not implemented.

Usage

1
hmi_pool(mids, analysis_function)

Arguments

mids

A mids (multiply imputed data set) object. Either from the hmi imputation function or mice.

analysis_function

A user generated function that gets a completed data set, runs the model and returns all model parameters he or she is interested in in a vector. See examples below.

Value

A vector with all averaged results.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
## Not run: 
 data(Gcsemv, package = "hmi")

 model_formula <- written ~ 1 + gender + coursework + (1 + gender|school)

 set.seed(123)
 dat_imputed <- hmi(data = Gcsemv, model_formula = model_formula, m = 2, maxit = 2)

 my_analysis <- function(complete_data){
  # In this list, you can write all the parameters you are interested in.
  # Those will be averaged.
  # So make sure that averaging makes sense and that you only put in single numeric values.
  parameters_of_interest <- list()

  # ---- write in the following lines, what you are interetest in to do with your complete_data
  # the following lines are an example where the analyst is interested in the fixed intercept
  # and fixed slope and the random intercepts variance,
  # the random slopes variance and their covariance
  my_model <- lme4::lmer(model_formula, data = complete_data)

  parameters_of_interest[[1]] <- lme4::fixef(my_model)
  parameters_of_interest[[2]] <- lme4::VarCorr(my_model)[[1]][,]
  ret <- unlist(parameters_of_interest)# This line is essential if the elements of interest
  #should be labeled in the following line.
  names(ret) <-
    c("beta_intercept", "beta_gender", "beta_coursework", "sigma0", "sigma01", "sigma10", "sigma1")

  return(ret)
}
hmi_pool(mids = dat_imputed, analysis_function = my_analysis)
#if you are interested in fixed effects only, consider pool from mice:
mice::pool(with(data = dat_imputed,
  expr = lme4::lmer(written ~ 1 + gender + coursework + (1 + gender|school))))

## End(Not run)

hmi documentation built on Oct. 23, 2020, 7:31 p.m.