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

Description Usage Arguments Value Examples

View source: R/hmi_smallfunctions_2018-01-21.R View source: R/hmi_smallfunctions_2017-12-28.R View source: R/hmi_smallfunctions_2017-12-20.R View source: R/hmi_smallfunctions_2017-11-14.R View source: R/hmi_smallfunctions_2017-09-14.R View source: R/hmi_smallfunctions_2017-09-01.R View source: R/hmi_smallfunctions_2017-02-21.R View source: R/hmi_smallfunctions_2017-02-05.R View source: R/hmi_smallfunctions_2017-01-13.R View source: R/hmi_smallfunctions_2017-01-05.R View source: R/hmi_smallfunctions_2016-12-22_01.R View source: R/hmi_smallfunctions_2016-12-14_04.R View source: R/hmi_smallfunctions_2016-12-14_03.R View source: R/hmi_smallfunctions_2016-12-09_01.R View source: R/hmi_smallfunctions_2016-12-08_01.R View source: R/hmi_smallfunctions_2016-08-02.R View source: R/hmi_smallfunctions_2016-07-21.R View source: R/hmi_smallfunctions_2016-07-14.R

Description

This function applies the analysis the user is interested in, on all different imputed dataset. Then the results are pooled by simply averaging the results. So the user has to make sure that his analysis produces results with a meaningful average. And furthermore has to accept that no variance is calculated for these parameters.

Usage

1
hmi_pool(mids, analysis_function)

Arguments

mids

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

analysis_function

A user generated function that he is interested in. See examples.

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
my.formula <- Reaction ~ Days + (1 + Days|Subject)
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 <- lmer(my.formula, data = complete_data)

 parameters_of_interest[[1]] <- fixef(my_model)[1]
 parameters_of_interest[[2]] <- fixef(my_model)[2]
 parameters_of_interest[[3]] <- VarCorr(my_model)[[1]][1, 1]
 parameters_of_interest[[4]] <- VarCorr(my_model)[[1]][1, 2]
 parameters_of_interest[[5]] <- VarCorr(my_model)[[1]][2, 2]
 names(parameters_of_interest) <- c("beta_intercept", "beta_Days", "sigma0", "sigma01", "sigma1")

 # ---- do change this function below this line.
 return(parameters_of_interest)
}
require("lme4")
require("mice")
data(sleepstudy, package = "lme4")
test <- sleepstudy
test$Intercept <- 1
test[sample(1:nrow(test), size = 20), "Reaction"] <- NA
hmi_imp <- hmi(data = test, model_formula = my.formula)
hmi_pool(mids = hmi_imp, analysis_function = my_analysis)
#if you are interested in fixed effects only, consider using \code{pool} from \code{mice}.
pool(with(data = hmi_imp, expr = lmer(Reaction ~ Days + (1 + Days | Subject))))

matthiasspeidel/hmi documentation built on Aug. 18, 2020, 4:37 p.m.