hmi: hmi: Hierarchical Multilevel Imputation.

Description Usage Arguments Value Examples

View source: R/hmi_wrapper_2018-05-23.R View source: R/hmi_wrapper_2018-05-02.R View source: R/hmi_wrapper_2018-02-27.R View source: R/hmi_wrapper_2018-01-31.R View source: R/hmi_wrapper_2018-01-22.R View source: R/hmi_wrapper_2018-01-21.R View source: R/hmi_wrapper_2017-12-20.R View source: R/hmi_wrapper_2017-10-12.R View source: R/hmi_wrapper_2017-08-24.R View source: R/hmi_wrapper_2017-02-05.R View source: R/hmi_wrapper_2017-01-15.R View source: R/hmi_wrapper_2017-01-05.R View source: R/hmi_wrapper_2017-01-04.R View source: R/hmi_wrapper_2016-12-21_01.R View source: R/hmi_wrapper_2016-12-20_03.R View source: R/hmi_wrapper.R

Description

The user has to pass his data to the function. Optionally he passes his analysis model formula so that hmi runs the imputation model in line with his analysis model formula.
And of course he can specify some parameters for the imputation routine (like the number of imputations and iterations) including Gibbs-sampler parameters (number of iterations, burnin and thinning.

Usage

1
2
hmi(data, model_formula = NULL, M = 10, maxit = 5, nitt = 3000,
  thin = 100, burnin = 1000)

Arguments

data

A data.frame with all variables appearing in model_formula.

model_formula

A formula used for the analysis model. Currently the package is designed to handle formula used in lm, glm and lmer.

M

An integer defining the number of imputations that should be made.

maxit

An integer defining the number of times the imputation cycle (imputing x_1|x_{-1} then x_2|x_{-2}, ... x_p|x_{-p}) shall be repeated. The task of checking convergence is left to the user, by evaluating the chainMean and chainVar!

nitt

An integer defining number of MCMC iterations (see MCMCglmm).

thin

An integer defining the thinning interval (see MCMCglmm).

burnin

An integer defining the percentage of draws from the gibbs sampler that should be discarded as burn in (see MCMCglmm).

Value

The function returns a mids object. See mice for further information.

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 pool from 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.