Description Usage Arguments Details Value References Examples
‘MI.inference’ applies Rubin's combining rules to estimated quantities of interest that are based on multiply imputed data sets. The function requires as input two vectors of length M for the estimate and its variance.
1 | MI.inference(thetahat, varhat.thetahat, alpha=0.05)
|
thetahat |
A vector of length M containing estimates of the quantity of interest based on multiply imputed data sets. |
varhat.thetahat |
A vector of length M containing the
corresponding variances of |
alpha |
The significance level at which lower and upper bound are calculated. DEFAULT=0.05 |
Multiple Imputation (Rubin, 1987) of missing data is a
generally accepted way to get correct variance estimates for a
particular quantity of interest in the presence of missing
data. MI.inference
estimates the within variance W and
between variance B, and combines them to the total
variance T. Based on the output, further analysis figures, such as
the fraction of missing information can be calculated.
MI.Est |
A scalar containing the MI estimate of the quantity of interest (i.e. an estimator averaged over all M data sets). |
MI.Var |
The Multiple Imputation variance. |
CI.low |
The lower bound of the MI confidence interval. |
CI.up |
The upper bound of the MI confidence interval. |
BVar |
The estimated between variance. |
WVar |
The estimated within variance. |
Rubin, D.B. (1987) Multiple Imputation for Non-Response in Surveys. New York: John Wiley & Sons, Inc.
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 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 | ## Not run:
### example 1
n <- 100
x1 <- round(runif(n,0.5,3.5))
x2 <- round(runif(n,0.5,4.5))
x3 <- runif(n,1,6)
y1 <- round(x1-0.25*x2+0.5*x3+rnorm(n,0,1))
y1 <- ifelse(y1<2,2,y1)
y1 <- as.factor(ifelse(y1>4,5,y1))
y2 <- x3+rnorm(n,0,2)
y3 <- as.factor(ifelse(x2+rnorm(n,0,2)>2,1,0))
mis1 <- sample(100,20)
mis2 <- sample(100,30)
mis3 <- sample(100,25)
data1 <- data.frame("x1"=x1,"x2"=x2,"x3"=x3,
"y1"=y1,"y2"=y2,"y3"=y3)
is.na(data1$y1[mis1]) <- TRUE
is.na(data1$y2[mis2]) <- TRUE
is.na(data1$y3[mis3]) <- TRUE
imputed.data <- BBPMM(data1, M=5, nIter=5)
MI.m.meany2.hat <- sapply(imputed.data$impdata,
FUN=function(x) mean(x$y2))
MI.v.meany2.hat <- sapply(imputed.data$impdata,
FUN=function(x) var(x$y2)/length(x$y2))
### MI inference
MI.y2 <- MI.inference(MI.m.meany2.hat,
MI.v.meany2.hat, alpha=0.05)
MI.y2$MI.Est
MI.y2$MI.Var
################################################################
### example 2: a small simulation example
### simple additional function to calculate coverages: #
coverage <- function(value, bounds) {
ifelse(min(bounds) <= value && max(bounds) >= value, 1, 0)
}
### value : true value #
### bounds : vector with two elements (upper and #
### lower bound of the CI) #
### sample size
n <- 100
### true value for the mean of y2
m.y2 <- 3.5
y2.cover <- vector(length=n)
set.seed(1000)
### 100 data generations
time1 <- Sys.time()
for (i in 1:100) {
x1 <- round(runif(n,0.5,3.5))
x2 <- round(runif(n,0.5,4.5))
x3 <- runif(n,1,6)
y1 <- round(x1-0.25*x2+0.5*x3+rnorm(n,0,1))
y1 <- ifelse(y1<2,2,y1)
y1 <- as.factor(ifelse(y1>4,5,y1))
y2 <- x3+rnorm(n,0,2)
y3 <- as.factor(ifelse(x2+rnorm(n,0,2)>2,1,0))
mis1 <- sample(n,20)
mis2 <- sample(n,30)
mis3 <- sample(n,25)
data1 <- data.frame("x1"=x1,"x2"=x2,"x3"=x3,
"y1"=y1,"y2"=y2,"y3"=y3)
is.na(data1$y1[mis1]) <- TRUE
is.na(data1$y2[mis2]) <- TRUE
is.na(data1$y3[mis3]) <- TRUE
sim.imp <- BBPMM(data1, M=3, nIter=2,
stepmod="", verbose=FALSE)
MI.m.meany2.hat <- sapply(sim.imp$impdata,
FUN=function(x) mean(x$y2))
MI.v.meany2.hat <- sapply(sim.imp$impdata,
FUN=function(x)
var(x$y2)/length(x$y2))
### MI inference
MI.y2 <- MI.inference(MI.m.meany2.hat, MI.v.meany2.hat,
alpha=0.05)
y2.cover[i] <- coverage(m.y2, c(MI.y2$CI.low,MI.y2$CI.up))
}
time2 <- Sys.time()
difftime(time2, time1, unit="secs")
### coverage estimator (alpha=0.05):
mean(y2.cover)
## End(Not run)
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.