Learn R Programming

micd (version 1.1.1)

makeResiduals: Generate residuals based on variables in imputed data sets

Description

Generate residuals based on variables in imputed data sets

Usage

makeResiduals(data, v, confounder, method = c("res", "cc", "pd"))

Value

A data matrix of residuals.

Arguments

data

A data.frame.

v

Vector of integers referring to the location of the variable(s) in the data set

confounder

Vector of integers referring to the location of the variable(s) in the data set (confounders are not included in the network!)

method

Default method 'res' uses residuals, 'cc' uses complete cases and 'pd' uses pairwise deletion

Examples

Run this code
data(windspeed)
daten <- mice::ampute(windspeed)$amp

# Impute missing values
imp <- mice(daten, m = 5)

# Build residuals
knoten <- 1:4
confounder <- 5:6

# Residuals based on dataset with missing values
res.pd <- makeResiduals(daten, v = knoten, confounder = confounder, method = "pd")

# Residuals based in multiple imputed data
residuals <- list(data = list(), m = 5)
imp_c <- mice::complete(imp, "all")
for (i in 1:imp$m){
   residuals$data[[i]] <- makeResiduals(imp_c[[i]],
                          v = knoten, confounder = confounder)
 }

pc.res <- pcMI(data = residuals, p = length(knoten), alpha = 0.05)
fci.res <- fciMI(data = imp, p = length(knoten), alpha = 0.05)

if (requireNamespace("Rgraphviz", quietly = TRUE)){
oldpar <- par(mfrow = c(1,2)) 
  plot(pc.res)
  plot(fci.res)
par(oldpar)
}

Run the code above in your browser using DataLab