MultImpute: Multiple Imputation.

Description Usage Arguments Examples

Description

Multiple imputation of missing data as per the expectation maximization algorithm.

Usage

1
MultImpute(d, Type = c("Train", "Test"))

Arguments

d
Type

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
36
37
38
39
##---- Should be DIRECTLY executable !! ----
##-- ==>  Define data, use random,
##--	or do  help(data=index)  for the standard data sets.

## The function is currently defined as
function (d, Type = c("Train", "Test")) 
{
    library(Amelia)
    if (Type == "Train") {
        d2 <- d[, -c(1, dim(d)[2])]
    }
    else {
        d2 <- d[, -1]
    }
    k <- dim(d2)[2]
    for (i in 3:k) {
        dt <- d2[(i - 2):i]
        dtp <- na.omit(dt)
        if ((dim(dt)[1] - dim(dtp)[1]) > 0) {
            aout <- amelia(dt, m = 100)
            for (j in 1:100) {
                if (j == 1) 
                  dtimp <- aout$imputations[[j]]
                if (j > 1) 
                  dtimp <- dtimp + aout$imputations[[j]]
            }
            dtimp1 <- dtimp/100
            d2[(i - 2):i] <- dtimp1
        }
    }
    if (Type == "Train") {
        d3 <- as.data.frame(cbind(d[, 1], d2, d[, dim(d)[2]]))
    }
    else {
        d3 <- as.data.frame(cbind(d[, 1], d2))
    }
    colnames(d3) <- colnames(d)
    return(d3)
  }

bvnlab/SCATTome documentation built on May 13, 2019, 9:05 a.m.