File: mice.impute.2l.pan.Rd

package info (click to toggle)
r-cran-mice 3.17.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 2,380 kB
  • sloc: cpp: 121; sh: 25; makefile: 2
file content (146 lines) | stat: -rw-r--r-- 4,532 bytes parent folder | download | duplicates (2)
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
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/mice.impute.2l.pan.R
\name{mice.impute.2l.pan}
\alias{mice.impute.2l.pan}
\alias{2l.pan}
\title{Imputation by a two-level normal model using \code{pan}}
\usage{
mice.impute.2l.pan(
  y,
  ry,
  x,
  type,
  intercept = TRUE,
  paniter = 500,
  groupcenter.slope = FALSE,
  ...
)
}
\arguments{
\item{y}{Incomplete data vector of length \code{n}}

\item{ry}{Vector of missing data pattern (\code{FALSE}=missing,
\code{TRUE}=observed)}

\item{x}{Matrix (\code{n} x \code{p}) of complete covariates.}

\item{type}{Vector of length \code{ncol(x)} identifying random and class
variables.  Random effects are identified by a '2'. The group variable (only
one is allowed) is coded as '-2'. Random effects also include the fixed
effect. If for a covariates X1 group means shall be calculated and included
as further fixed effects choose '3'. In addition to the effects in '3',
specification '4' also includes random effects of X1.}

\item{intercept}{Logical determining whether the intercept is automatically
added.}

\item{paniter}{Number of iterations in \code{pan}. Default is 500.}

\item{groupcenter.slope}{If \code{TRUE}, in case of group means (\code{type}
is '3' or'4') group mean centering for these predictors are conducted before
doing imputations. Default is \code{FALSE}.}

\item{...}{Other named arguments.}
}
\value{
A vector of length \code{nmis} with imputations.
}
\description{
Imputes univariate missing data using a two-level normal model with
homogeneous within group variances. Aggregated group effects (i.e. group
means) can be automatically created and included as predictors in the
two-level regression (see argument \code{type}). This function needs the
\code{pan} package.
}
\details{
Implements the Gibbs sampler for the linear two-level model with homogeneous
within group variances which is a special case of a multivariate linear mixed
effects model (Schafer & Yucel, 2002).  For a two-level imputation with
heterogeneous within-group variances see \code{\link{mice.impute.2l.norm}}. %
The random intercept is automatically added in %
\code{mice.impute.2l.norm()}.
}
\note{
This function does not implement the \code{where} functionality. It
always produces \code{nmis} imputation, irrespective of the \code{where}
argument of the \code{mice} function.
}
\examples{
# simulate some data
# two-level regression model with fixed slope

# number of groups
G <- 250
# number of persons
n <- 20
# regression parameter
beta <- .3
# intraclass correlation
rho <- .30
# correlation with missing response
rho.miss <- .10
# missing proportion
missrate <- .50
y1 <- rep(rnorm(G, sd = sqrt(rho)), each = n) + rnorm(G * n, sd = sqrt(1 - rho))
x <- rnorm(G * n)
y <- y1 + beta * x
dfr0 <- dfr <- data.frame("group" = rep(1:G, each = n), "x" = x, "y" = y)
dfr[rho.miss * x + rnorm(G * n, sd = sqrt(1 - rho.miss)) < qnorm(missrate), "y"] <- NA

# empty imputation in mice
imp0 <- mice(as.matrix(dfr), maxit = 0)
predM <- imp0$predictorMatrix
impM <- imp0$method

# specify predictor matrix and method
predM1 <- predM
predM1["y", "group"] <- -2
predM1["y", "x"] <- 1 # fixed x effects imputation
impM1 <- impM
impM1["y"] <- "2l.pan"

# multilevel imputation
imp1 <- mice(as.matrix(dfr),
  m = 1, predictorMatrix = predM1,
  method = impM1, maxit = 1
)

# multilevel analysis
library(lme4)
mod <- lmer(y ~ (1 + x | group) + x, data = complete(imp1))
summary(mod)

# Examples of predictorMatrix specification

# random x effects
# predM1["y","x"] <- 2

# fixed x effects and group mean of x
# predM1["y","x"] <- 3

# random x effects and group mean of x
# predM1["y","x"] <- 4
}
\references{
Schafer J L, Yucel RM (2002). Computational strategies for multivariate
linear mixed-effects models with missing values.  \emph{Journal of
Computational and Graphical Statistics}. \bold{11}, 437-457.

Van Buuren, S., Groothuis-Oudshoorn, K. (2011). \code{mice}: Multivariate
Imputation by Chained Equations in \code{R}. \emph{Journal of Statistical
Software}, \bold{45}(3), 1-67. \doi{10.18637/jss.v045.i03}
}
\seealso{
Other univariate-2l: 
\code{\link{mice.impute.2l.bin}()},
\code{\link{mice.impute.2l.lmer}()},
\code{\link{mice.impute.2l.norm}()}
}
\author{
Alexander Robitzsch (IPN - Leibniz Institute for Science and
Mathematics Education, Kiel, Germany), \email{robitzsch@ipn.uni-kiel.de}

Alexander Robitzsch (IPN - Leibniz Institute for Science and
Mathematics Education, Kiel, Germany), \email{robitzsch@ipn.uni-kiel.de}.
}
\concept{univariate-2l}