Jomo
Jomo
Jomo
R topics documented:
cldata . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3
ExamScores . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3
jomo . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4
jomo.clmm . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7
jomo.clmm.MCMCchain . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10
jomo.coxph . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12
jomo.coxph.MCMCchain . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 14
jomo.glm . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15
jomo.glm.MCMCchain . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 17
jomo.glmer . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 19
1
2 R topics documented:
jomo.glmer.MCMCchain . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 21
jomo.lm . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 24
jomo.lm.MCMCchain . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 26
jomo.lmer . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 28
jomo.lmer.MCMCchain . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 30
jomo.MCMCchain . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 33
jomo.polr . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 36
jomo.polr.MCMCchain . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 38
jomo.smc . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 39
jomo.smc.MCMCchain . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 42
jomo1 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 45
jomo1.MCMCchain . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 47
jomo1cat . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 48
jomo1cat.MCMCchain . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 50
jomo1con . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 52
jomo1con.MCMCchain . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 54
jomo1mix . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 55
jomo1mix.MCMCchain . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 57
jomo1ran . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 59
jomo1ran.MCMCchain . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 61
jomo1rancat . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 63
jomo1rancat.MCMCchain . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 65
jomo1rancathr . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 68
jomo1rancathr.MCMCchain . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 70
jomo1rancon . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 73
jomo1rancon.MCMCchain . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 75
jomo1ranconhr . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 77
jomo1ranconhr.MCMCchain . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 80
jomo1ranmix . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 82
jomo1ranmix.MCMCchain . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 84
jomo1ranmixhr . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 87
jomo1ranmixhr.MCMCchain . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 90
jomo2 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 92
jomo2.MCMCchain . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 95
jomo2com . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 97
jomo2com.MCMCchain . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 100
jomo2hr . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 102
jomo2hr.MCMCchain . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 105
JSPmiss . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 108
sldata . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 109
surdata . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 109
tldata . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 110
Index 111
cldata 3
Description
Usage
data(cldata)
Format
Details
These are not real data, they are simulated to illustrate the use of the main functions of the package.
Description
A partially observed version of the tutorial dataset in package R2MLwiN.It includes examination
results from six inner London Education Authorities (school boards).
Usage
data(cldata)
4 jomo
Format
A data frame with 4059 observations on the following 6 variables.
school A school identifier.
student A student ID.
normexam Students’ exam score at age 16, normalised and partially observed.
sex Sex of pupil; a factor with levels boy, girl.
cons A column of 1s. Useful to add an intercept to th eimputation model.
standlrt Students’ score at age 11 on the London Reading Test (LRT), standardised.
schgend Schools’ gender; a factor with levels corresponding to mixed school (mixedsch), boys’
school (boysch), and girls’ school (girlsch).
avslrt Average LRT score in school.
schav Average LRT score in school, coded into 3 categories: low = bottom 25%, mid = middle
50%, high = top 25%.
vrband Students’ score in test of verbal reasoning at age 11, a factor with 3 levels: vb1 = top 25%,
vb2 = middle 50%, vb3 = bottom 25%.
Details
These fully observed verison of the data is available with package R2MLwiN.
Source
Browne, W. J. (2012) MCMC Estimation in MLwiN Version 2.26. University of Bristol: Centre for
Multilevel Modelling.
Goldstein, H., Rasbash, J., Yang, M., Woodhouse, G., Pan, H., Nuttall, D., Thomas, S. (1993) A
multilevel analysis of school examination results. Oxford Review of Education, 19, 425-433.
Rasbash, J., Charlton, C., Browne, W.J., Healy, M. and Cameron, B. (2009) MLwiN Version 2.1.
Centre for Multilevel Modelling, University of Bristol.
Description
A wrapper function linking all the functions for JM imputation. The matrix of responses Y, must be
a data.frame where continuous variables are numeric and binary/categorical variables are factors.
Usage
jomo(Y, Y2=NULL, X=NULL, X2=NULL, Z=NULL, clus=NULL, beta.start=NULL,
l2.beta.start=NULL, u.start=NULL, l1cov.start=NULL, l2cov.start=NULL,
l1cov.prior=NULL, l2cov.prior=NULL, nburn=1000, nbetween=1000, nimp=5,
a=NULL, a.prior=NULL, meth="common", output=1, out.iter=10)
jomo 5
Arguments
Y A data.frame containing the (level-1) outcomes of the imputation model. Columns
related to continuous variables have to be numeric and columns related to bi-
nary/categorical variables have to be factors.
Y2 A data.frame containing the level-2 outcomes of the imputation model. Columns
related to continuous variables have to be numeric and columns related to bi-
nary/categorical variables have to be factors.
X A data frame, or matrix, with covariates of the joint imputation model. Rows
correspond to different observations, while columns are different variables. Miss-
ing values are not allowed in these variables. In case we want an intercept, a
column of 1 is needed. The default is a column of 1.
X2 A data frame, or matrix, with level-2 covariates of the joint imputation model.
Rows correspond to different level-1 observations, while columns are different
variables. Missing values are not allowed in these variables. In case we want an
intercept, a column of 1 is needed. The default is a column of 1.
Z A data frame, or matrix, for covariates associated to random effects in the joint
imputation model. Rows correspond to different observations, while columns
are different variables. Missing values are not allowed in these variables. In
case we want an intercept, a column of 1 is needed. The default is a column of
1.
clus A data frame, or matrix, containing the cluster indicator for each observation. If
missing, functions for single level imputation are automatically used.
beta.start Starting value for beta, the vector(s) of level-1 fixed effects. Rows index dif-
ferent covariates and columns index different outcomes. For each n-category
variable we have a fixed effect parameter for each of the n-1 latent normals. The
default is a matrix of zeros.
l2.beta.start Starting value for beta2, the vector(s) of level-2 fixed effects. Rows index dif-
ferent covariates and columns index different level-2 outcomes. For each n-
category variable we have a fixed effect parameter for each of the n-1 latent
normals. The default is a matrix of zeros.
u.start A matrix where different rows are the starting values within each cluster for the
random effects estimates u. The default is a matrix of zeros.
l1cov.start Starting value for the covariance matrix. Dimension of this square matrix is
equal to the number of outcomes (continuous plus latent normals) in the impu-
tation model. The default is the identity matrix. Functions for imputation with
random cluster-specific covariance matrices are an exception, because we need
to pass the starting values for all of the matrices stacked one above the other.
l2cov.start Starting value for the level 2 covariance matrix. Dimension of this square matrix
is equal to the number of outcomes (continuous plus latent normals) in the im-
putation model times the number of random effects plus the number of level-2
outcomes. The default is an identity matrix.
l1cov.prior Scale matrix for the inverse-Wishart prior for the covariance matrix. The default
is the identity matrix.
l2cov.prior Scale matrix for the inverse-Wishart prior for the level 2 covariance matrix. The
default is the identity matrix.
6 jomo
Details
This is just a wrapper function to link all the functions in the package. Format of the columns of Y
is crucial in order for the function to be using the right sub-function.
Value
On screen, the posterior mean of the fixed and random effects estimates and of the covariance
matrices are shown. The only argument returned is the imputed dataset in long format. Column
"Imputation" indexes the imputations. Imputation number 0 are the original data.
References
Carpenter J.R., Kenward M.G., (2013), Multiple Imputation and its Application. Wiley, ISBN:
978-0-470-74052-1.
Examples
Y<-cldata[,c("measure","age")]
clus<-cldata[,c("city")]
nburn=as.integer(200);
nbetween=as.integer(200);
nimp=as.integer(5);
jomo.clmm 7
# Finally we show how to fit the model and combine estimate with Rubin's rules
# Here we use mitml, other options are available in mice, mitools, etc etc
#we could even run imputation with fixed or random cluster-specific covariance matrices:
#imp<-jomo(Y,clus=clus,nburn=nburn,nbetween=nbetween,nimp=nimp, meth="fixed")
#or:
#imp<-jomo(Y,clus=clus,nburn=nburn,nbetween=nbetween,nimp=nimp, meth="random")
#if we do not add clus as imput, functions for single level imputation are used:
#imp<-jomo(Y)
Description
A function for substantive model compatible JM imputation, when the substantive model of in-
terest is a cumulative link mixed model. Interactions and polynomial functions of the covariates
are allowed. Data must be passed as a data.frame where continuous variables are numeric and
binary/categorical variables are factors.
Usage
Arguments
formula an object of class formula: a symbolic description of the model to be fitted. It is
possible to include in this formula interactions (through symbols ’*’ and ’
data A data.frame containing all the variables to include in the imputation model.
Columns related to continuous variables have to be numeric and columns related
to binary/categorical variables have to be factors.
level A vector, indicating whether each variable is either a level 1 or a level 2 variable.
The value assigned to the cluster indicator is irrelevant.
beta.start Starting value for beta, the vector(s) of level-1 fixed effects for the joint model
for the covariates. For each n-category variable we have a fixed effect parameter
for each of the n-1 latent normals. The default is a matrix of zeros.
l2.beta.start Starting value for beta2, the vector(s) of level-2 fixed effects for the joint model
for the covariates. For each n-category variable we have a fixed effect parameter
for each of the n-1 latent normals. The default is a matrix of zeros.
u.start A matrix where different rows are the starting values within each cluster of the
random effects estimates u for the joint model for the covariates. The default is
a matrix of zeros.
l1cov.start Starting value of the level-1 covariance matrix of the joint model for the co-
variates. Dimension of this square matrix is equal to the number of covariates
(continuous plus latent normals) in the imputation model. The default is the
identity matrix. Functions for imputation with random cluster-specific covari-
ance matrices are an exception, because we need to pass the starting values for
all of the matrices stacked one above the other.
l2cov.start Starting value for the level 2 covariance matrix of the joint model for the covari-
ates. Dimension of this square matrix is equal to the number of level-1 covariates
(continuous plus latent normals) in the analysis model times the number of ran-
dom effects plus the number of level-2 covariates. The default is an identity
matrix.
l1cov.prior Scale matrix for the inverse-Wishart prior for the covariance matrix. The default
is the identity matrix.
l2cov.prior Scale matrix for the inverse-Wishart prior for the level 2 covariance matrix. The
default is the identity matrix.
a.start Starting value for the degrees of freedom of the inverse Wishart distribution
of the cluster-specific covariance matrices. Default is 50+D, with D being the
dimension of the covariance matrices. This is used only with clustered data and
when option meth is set to "random".
a.prior Hyperparameter (Degrees of freedom) of the chi square prior distribution for the
degrees of freedom of the inverse Wishart distribution for the cluster-specific
covariance matrices. Default is D, with D being the dimension of the covariance
matrices.
meth Method used to deal with level 1 covariance matrix. When set to "common",
a common matrix across clusters is used (functions jomo1rancon, jomo1rancat
and jomo1ranmix). When set to "fixed", fixed study-specific matrices are con-
sidered (jomo1ranconhr, jomo1rancathr and jomo1ranmixhr with coption meth="fixed").
jomo.clmm 9
Details
This function allows for substantive model compatible imputation when the substantive model is a
cumulative link mixed-effects model. It can deal with interactions and polynomial terms through
the usual lmer syntax in the formula argument. Format of the columns of data is crucial in order for
the function to deal with binary/categorical covariates appropriately in the imputation algorithm.
Value
On screen, the posterior mean of the fixed effect estimates and of the residual variance are shown.
The only argument returned is the imputed dataset in long format. Column "Imputation" indexes
the imputations. Imputation number 0 are the original data.
References
Carpenter J.R., Kenward M.G., (2013), Multiple Imputation and its Application. Wiley, ISBN:
978-0-470-74052-1.
Examples
cldata<-within(cldata, social<-factor(social))
formula<-as.formula(social~age+measure+(1|city))
Description
This function is similar to the jomo.clmm function, but it returns the values of all the parameters in
the model at each step of the MCMC instead of the imputations. It is useful to check the convergence
of the MCMC sampler.
Usage
jomo.clmm.MCMCchain(formula, data, level=rep(1,ncol(data)),
beta.start=NULL, l2.beta.start=NULL, u.start=NULL,
l1cov.start=NULL, l2cov.start=NULL, l1cov.prior=NULL,
l2cov.prior=NULL, a.start=NULL, a.prior=NULL,
betaY.start=NULL, covuY.start=NULL,
uY.start=NULL, nburn=1000, meth="common",
start.imp=NULL, start.imp.sub=NULL, l2.start.imp=NULL,
output=1, out.iter=10)
Arguments
formula an object of class formula: a symbolic description of the model to be fitted. It is
possible to include in this formula interactions (through symbols ’*’ and ’
data A data.frame containing all the variables to include in the imputation model.
Columns related to continuous variables have to be numeric and columns related
to binary/categorical variables have to be factors.
level A vector, indicating whether each variable is either a level 1 or a level 2 variable.
The value assigned to the cluster indicator is irrelevant.
beta.start Starting value for beta, the vector(s) of level-1 fixed effects for the joint model
for the covariates. For each n-category variable we have a fixed effect parameter
for each of the n-1 latent normals. The default is a matrix of zeros.
l2.beta.start Starting value for beta2, the vector(s) of level-2 fixed effects for the joint model
for the covariates. For each n-category variable we have a fixed effect parameter
for each of the n-1 latent normals. The default is a matrix of zeros.
u.start A matrix where different rows are the starting values within each cluster of the
random effects estimates u for the joint model for the covariates. The default is
a matrix of zeros.
jomo.clmm.MCMCchain 11
l1cov.start Starting value of the level-1 covariance matrix of the joint model for the co-
variates. Dimension of this square matrix is equal to the number of covariates
(continuous plus latent normals) in the imputation model. The default is the
identity matrix. Functions for imputation with random cluster-specific covari-
ance matrices are an exception, because we need to pass the starting values for
all of the matrices stacked one above the other.
l2cov.start Starting value for the level 2 covariance matrix of the joint model for the covari-
ates. Dimension of this square matrix is equal to the number of level-1 covariates
(continuous plus latent normals) in the analysis model times the number of ran-
dom effects plus the number of level-2 covariates. The default is an identity
matrix.
l1cov.prior Scale matrix for the inverse-Wishart prior for the covariance matrix. The default
is the identity matrix.
l2cov.prior Scale matrix for the inverse-Wishart prior for the level 2 covariance matrix. The
default is the identity matrix.
a.start Starting value for the degrees of freedom of the inverse Wishart distribution
of the cluster-specific covariance matrices. Default is 50+D, with D being the
dimension of the covariance matrices. This is used only with clustered data and
when option meth is set to "random".
a.prior Hyperparameter (Degrees of freedom) of the chi square prior distribution for the
degrees of freedom of the inverse Wishart distribution for the cluster-specific
covariance matrices. Default is D, with D being the dimension of the covariance
matrices.
meth Method used to deal with level 1 covariance matrix. When set to "common",
a common matrix across clusters is used (functions jomo1rancon, jomo1rancat
and jomo1ranmix). When set to "fixed", fixed study-specific matrices are con-
sidered (jomo1ranconhr, jomo1rancathr and jomo1ranmixhr with coption meth="fixed").
Finally, when set to "random", random study-specific matrices are considered
(jomo1ranconhr, jomo1rancathr and jomo1ranmixhr with option meth="random")
betaY.start Starting value for betaY, the vector of fixed effects for the substantive analysis
model. The default is the complete records estimate.
covuY.start Starting value for covuY, the random effects covariance matrix of the substantive
analysis model. The default is the complete records estimate.
uY.start Starting value for uY, the random effects matrix of the substantive analysis
model. The default is the complete records estimate.
nburn Number of burn in iterations. Default is 1000.
output When set to 0, no output is shown on screen at the end of the process. When
set to 1, only the parameter estimates related to the substantive model are shown
(default). When set to 2, all parameter estimates (posterior means) are displayed.
out.iter When set to K, every K iterations a dot is printed on screen. Default is 10.
start.imp Starting value for the missing data in the covariates of the substantive model.
n-level categorical variables are substituted by n-1 latent normals.
l2.start.imp Starting value for the missing data in the level-2 covariates of the substantive
model. n-level categorical variables are substituted by n-1 latent normals.
start.imp.sub Starting value for the missing data in the outcome of the substantive model. For
family="binomial", these are the values of the latent normals.
12 jomo.coxph
Value
A list is returned; this contains the final imputed dataset (finimp) and several 3-dimensional ma-
trices, containing all the values drawn for each parameter at each iteration: these are fixed effect
parameters of the covariates beta (collectbeta), level 1 covariance matrices (collectomega), fixed
effect estimates of the substantive model and associated residual variances. If there are some cate-
gorical outcomes, a further output is included in the list, finimp.latnorm, containing the final state
of the imputed dataset with the latent normal variables.
Examples
cldata<-within(cldata, social<-factor(social))
formula<-as.formula(social~age+measure+(1|city))
imp<-jomo.clmm.MCMCchain(formula,data, nburn=100)
# We can check, for example, the convergence of the first element of beta:
# plot(c(1:100),imp$collectbeta[1,1,1:100],type="l")
Description
A function for substantive model compatible JM imputation, when the substantive model of interest
is a Cox Proportional Hazards Model. Interactions and polynomial functions of the covariates
are allowed. Data must be passed as a data.frame where continuous variables are numeric and
binary/categorical variables are factors.
Usage
jomo.coxph(formula, data, beta.start=NULL, l1cov.start=NULL, l1cov.prior=NULL,
nburn=1000, nbetween=1000, nimp=5, output=1, out.iter=10)
jomo.coxph 13
Arguments
formula an object of class formula: a symbolic description of the model to be fitted. It is
possible to include in this formula interactions (through symbols ’*’ and ’
data A data.frame containing all the variables to include in the imputation model.
Columns related to continuous variables have to be numeric and columns related
to binary/categorical variables have to be factors.
beta.start Starting value for beta, the vector(s) of fixed effects for the joint model for the
covariates. For each n-category variable we have a fixed effect parameter for
each of the n-1 latent normals. The default is a matrix of zeros.
l1cov.start Starting value of the level-1 covariance matrix of the joint model for the co-
variates. Dimension of this square matrix is equal to the number of covariates
(continuous plus latent normals) in the imputation model. The default is the
identity matrix.
l1cov.prior Scale matrix for the inverse-Wishart prior for the covariance matrix. The default
is the identity matrix.
nburn Number of burn in iterations. Default is 1000.
nbetween Number of iterations between two successive imputations. Default is 1000.
nimp Number of Imputations. Default is 5.
output When set to 0, no output is shown on screen at the end of the process. When
set to 1, only the parameter estimates related to the substantive model are shown
(default). When set to 2, all parameter estimates (posterior means) are displayed.
out.iter When set to K, every K iterations a dot is printed on screen. Default is 10.
Details
This function allows for substantive model compatible imputation when the substantive model is a
Cox PH model. It can deal with interactions and polynomial terms through the usual lm syntax in
the formula argument. Format of the columns of data is crucial in order for the function to deal with
binary/categorical covariates appropriately in the imputation algorithm.
Value
On screen, the posterior mean of the fixed effect estimates and of the residual variance are shown.
The only argument returned is the imputed dataset in long format. Column "Imputation" indexes
the imputations. Imputation number 0 are the original data.
Examples
#define substantive model
formula<-as.formula(Surv(time, status) ~ measure + sex + I(measure^2))
#Run imputation
if (requireNamespace("survival", quietly = TRUE)) {
library(survival)
#imp<-jomo.coxph(formula,surdata, nburn = 100, nbetween = 100, nimp=5)
}
# Check help page for function jomo to see how to fit the model and
14 jomo.coxph.MCMCchain
Description
This function is similar to the jomo.coxph function, but it returns the values of all the parameters in
the model at each step of the MCMC instead of the imputations. It is useful to check the convergence
of the MCMC sampler.
Usage
jomo.coxph.MCMCchain(formula, data, beta.start = NULL, l1cov.start = NULL,
l1cov.prior = NULL, nburn = 1000, start.imp = NULL,
betaY.start = NULL, output = 1, out.iter = 10)
Arguments
formula an object of class formula: a symbolic description of the model to be fitted. It is
possible to include in this formula interactions (through symbols ’*’ and ’
data A data.frame containing all the variables to include in the imputation model.
Columns related to continuous variables have to be numeric and columns related
to binary/categorical variables have to be factors.
beta.start Starting value for beta, the vector(s) of fixed effects for the joint model for the
covariates. For each n-category variable we have a fixed effect parameter for
each of the n-1 latent normals. The default is a matrix of zeros.
l1cov.start Starting value of the level-1 covariance matrix of the joint model for the co-
variates. Dimension of this square matrix is equal to the number of covariates
(continuous plus latent normals) in the imputation model. The default is the
identity matrix.
l1cov.prior Scale matrix for the inverse-Wishart prior for the covariance matrix. The default
is the identity matrix.
betaY.start Starting value for betaY, the vector of fixed effects for the substantive analysis
model. The default is the complete records estimate.
nburn Number of burn in iterations. Default is 1000.
output When set to 0, no output is shown on screen at the end of the process. When
set to 1, only the parameter estimates related to the substantive model are shown
(default). When set to 2, all parameter estimates (posterior means) are displayed.
out.iter When set to K, every K iterations a dot is printed on screen. Default is 10.
start.imp Starting value for the missing data in the covariates of the substantive model.
n-level categorical variables are substituted by n-1 latent normals.
jomo.glm 15
Value
A list is returned; this contains the final imputed dataset (finimp) and several 3-dimensional ma-
trices, containing all the values drawn for each parameter at each iteration: these are fixed effect
parameters of the covariates beta (collectbeta), level 1 covariance matrices (collectomega), fixed
effect estimates of the substantive model. If there are some categorical outcomes, a further output is
included in the list, finimp.latnorm, containing the final state of the imputed dataset with the latent
normal variables.
Examples
# define substantive model
#Run imputation
Description
A function for substantive model compatible JM imputation, when the substantive model of interest
is a simple generalized linear regression model. Interactions and polynomial functions of the co-
variates are allowed. Data must be passed as a data.frame where continuous variables are numeric
and binary/categorical variables are factors.
Usage
jomo.glm(formula, data, beta.start=NULL, l1cov.start=NULL,
l1cov.prior=NULL,nburn=1000, nbetween=1000, nimp=5,
output=1, out.iter=10, family="binomial")
Arguments
formula an object of class formula: a symbolic description of the model to be fitted. It is
possible to include in this formula interactions (through symbols ’*’ and ’
data A data.frame containing all the variables to include in the imputation model.
Columns related to continuous variables have to be numeric and columns related
to binary/categorical variables have to be factors.
16 jomo.glm
beta.start Starting value for beta, the vector(s) of fixed effects for the joint model for the
covariates. For each n-category variable we have a fixed effect parameter for
each of the n-1 latent normals. The default is a matrix of zeros.
l1cov.start Starting value of the level-1 covariance matrix of the joint model for the co-
variates. Dimension of this square matrix is equal to the number of covariates
(continuous plus latent normals) in the imputation model. The default is the
identity matrix.
l1cov.prior Scale matrix for the inverse-Wishart prior for the covariance matrix. The default
is the identity matrix.
nburn Number of burn in iterations. Default is 1000.
nbetween Number of iterations between two successive imputations. Default is 1000.
nimp Number of Imputations. Default is 5.
output When set to 0, no output is shown on screen at the end of the process. When
set to 1, only the parameter estimates related to the substantive model are shown
(default). When set to 2, all parameter estimates (posterior means) are displayed.
out.iter When set to K, every K iterations a dot is printed on screen. Default is 10.
family One of either "gaussian"" or "binomial". For binomial family, a probit link is
assumed.
Details
This function allows for substantive model compatible imputation when the substantive model is
a simple linear regression model. It can deal with interactions and polynomial terms through the
usual lm syntax in the formula argument. Format of the columns of data is crucial in order for the
function to deal with binary/categorical covariates appropriately in the imputation algorithm.
Value
On screen, the posterior mean of the fixed effect estimates and of the residual variance are shown.
The only argument returned is the imputed dataset in long format. Column "Imputation" indexes
the imputations. Imputation number 0 are the original data.
References
Carpenter J.R., Kenward M.G., (2013), Multiple Imputation and its Application. Wiley, ISBN:
978-0-470-74052-1.
Examples
sldata<-within(sldata, sex<-factor(sex))
data<-sldata[,c("measure","age", "sex")]
jomo.glm.MCMCchain 17
formula<-as.formula(sex~age+measure)
Description
This function is similar to the jomo.glm function, but it returns the values of all the parameters in the
model at each step of the MCMC instead of the imputations. It is useful to check the convergence
of the MCMC sampler.
Usage
jomo.glm.MCMCchain(formula, data, beta.start=NULL, l1cov.start=NULL,
l1cov.prior=NULL, betaY.start=NULL, nburn=1000,
start.imp=NULL, start.imp.sub=NULL, output=1, out.iter=10,
family="binomial")
Arguments
formula an object of class formula: a symbolic description of the model to be fitted. It is
possible to include in this formula interactions (through symbols ’*’ and ’
data A data.frame containing all the variables to include in the imputation model.
Columns related to continuous variables have to be numeric and columns related
to binary/categorical variables have to be factors.
start.imp Starting value for the imputed covariates. n-level categorical variables are sub-
stituted by n-1 latent normals.
start.imp.sub Starting value for the imputations of the outcome. When using binomial family,
this is the value of the latent normal.
18 jomo.glm.MCMCchain
beta.start Starting value for beta, the vector(s) of fixed effects for the joint model for the
covariates. For each n-category variable we have a fixed effect parameter for
each of the n-1 latent normals. The default is a matrix of zeros.
l1cov.start Starting value of the level-1 covariance matrix of the joint model for the co-
variates. Dimension of this square matrix is equal to the number of covariates
(continuous plus latent normals) in the imputation model. The default is the
identity matrix.
l1cov.prior Scale matrix for the inverse-Wishart prior for the covariance matrix. The default
is the identity matrix.
betaY.start Starting value for betaY, the vector of fixed effects for the substantive analysis
model. The default is the complete records estimate.
nburn Number of burn in iterations. Default is 1000.
output When set to 0, no output is shown on screen at the end of the process. When
set to 1, only the parameter estimates related to the substantive model are shown
(default). When set to 2, all parameter estimates (posterior means) are displayed.
out.iter When set to K, every K iterations a dot is printed on screen. Default is 10.
family One of either "gaussian"" or "binomial". For binomial family, a probit link is
assumed.
Value
A list is returned; this contains the final imputed dataset (finimp) and several 3-dimensional ma-
trices, containing all the values drawn for each parameter at each iteration: these are fixed effect
parameters of the covariates beta (collectbeta), level 1 covariance matrices (collectomega), fixed
effect estimates of the substantive model and associated residual variances. If there are some cate-
gorical outcomes, a further output is included in the list, finimp.latnorm, containing the final state
of the imputed dataset with the latent normal variables.
Examples
sldata<-within(sldata, sex<-factor(sex))
data<-sldata[,c("measure","age", "sex")]
formula<-as.formula(sex~age+measure)
imp<-jomo.glm.MCMCchain(formula,data, nburn=10)
jomo.glmer 19
# We can check, for example, the convergence of the first element of beta:
plot(c(1:10),imp$collectbeta[1,1,1:10],type="l")
Description
A function for substantive model compatible JM imputation, when the substantive model of interest
is a generalized linear mixed-effects regression model. Interactions and polynomial functions of
the covariates are allowed. Data must be passed as a data.frame where continuous variables are
numeric and binary/categorical variables are factors.
Usage
jomo.glmer(formula, data, level=rep(1,ncol(data)), beta.start=NULL,
l2.beta.start=NULL, u.start=NULL, l1cov.start=NULL,
l2cov.start=NULL, l1cov.prior=NULL, l2cov.prior=NULL,
a.start=NULL, a.prior=NULL, nburn=1000, nbetween=1000,
nimp=5, meth="common", output=1, out.iter=10,
family="binomial")
Arguments
formula an object of class formula: a symbolic description of the model to be fitted. It is
possible to include in this formula interactions (through symbols ’*’ and ’
data A data.frame containing all the variables to include in the imputation model.
Columns related to continuous variables have to be numeric and columns related
to binary/categorical variables have to be factors.
level A vector, indicating whether each variable is either a level 1 or a level 2 variable.
The value assigned to the cluster indicator is irrelevant.
beta.start Starting value for beta, the vector(s) of level-1 fixed effects for the joint model
for the covariates. For each n-category variable we have a fixed effect parameter
for each of the n-1 latent normals. The default is a matrix of zeros.
l2.beta.start Starting value for beta2, the vector(s) of level-2 fixed effects for the joint model
for the covariates. For each n-category variable we have a fixed effect parameter
for each of the n-1 latent normals. The default is a matrix of zeros.
20 jomo.glmer
u.start A matrix where different rows are the starting values within each cluster of the
random effects estimates u for the joint model for the covariates. The default is
a matrix of zeros.
l1cov.start Starting value of the level-1 covariance matrix of the joint model for the co-
variates. Dimension of this square matrix is equal to the number of covariates
(continuous plus latent normals) in the imputation model. The default is the
identity matrix. Functions for imputation with random cluster-specific covari-
ance matrices are an exception, because we need to pass the starting values for
all of the matrices stacked one above the other.
l2cov.start Starting value for the level 2 covariance matrix of the joint model for the covari-
ates. Dimension of this square matrix is equal to the number of level-1 covariates
(continuous plus latent normals) in the analysis model times the number of ran-
dom effects plus the number of level-2 covariates. The default is an identity
matrix.
l1cov.prior Scale matrix for the inverse-Wishart prior for the covariance matrix. The default
is the identity matrix.
l2cov.prior Scale matrix for the inverse-Wishart prior for the level 2 covariance matrix. The
default is the identity matrix.
a.start Starting value for the degrees of freedom of the inverse Wishart distribution
of the cluster-specific covariance matrices. Default is 50+D, with D being the
dimension of the covariance matrices. This is used only with clustered data and
when option meth is set to "random".
a.prior Hyperparameter (Degrees of freedom) of the chi square prior distribution for the
degrees of freedom of the inverse Wishart distribution for the cluster-specific
covariance matrices. Default is D, with D being the dimension of the covariance
matrices.
meth Method used to deal with level 1 covariance matrix. When set to "common",
a common matrix across clusters is used (functions jomo1rancon, jomo1rancat
and jomo1ranmix). When set to "fixed", fixed study-specific matrices are con-
sidered (jomo1ranconhr, jomo1rancathr and jomo1ranmixhr with coption meth="fixed").
Finally, when set to "random", random study-specific matrices are considered
(jomo1ranconhr, jomo1rancathr and jomo1ranmixhr with option meth="random")
nburn Number of burn in iterations. Default is 1000.
nbetween Number of iterations between two successive imputations. Default is 1000.
nimp Number of Imputations. Default is 5.
output When set to 0, no output is shown on screen at the end of the process. When
set to 1, only the parameter estimates related to the substantive model are shown
(default). When set to 2, all parameter estimates (posterior means) are displayed.
out.iter When set to K, every K iterations a dot is printed on screen. Default is 10.
family One of either "gaussian"" or "binomial". For binomial family, a probit link is
assumed.
Details
This function allows for substantive model compatible imputation when the substantive model is a
linear mixed-effects model. It can deal with interactions and polynomial terms through the usual
jomo.glmer.MCMCchain 21
lmer syntax in the formula argument. Format of the columns of data is crucial in order for the
function to deal with binary/categorical covariates appropriately in the imputation algorithm.
Value
On screen, the posterior mean of the fixed effect estimates and of the residual variance are shown.
The only argument returned is the imputed dataset in long format. Column "Imputation" indexes
the imputations. Imputation number 0 are the original data.
References
Carpenter J.R., Kenward M.G., (2013), Multiple Imputation and its Application. Wiley, ISBN:
978-0-470-74052-1.
Examples
cldata<-within(cldata, sex<-factor(sex))
formula<-as.formula(sex~age+measure+(1|city))
Description
This function is similar to the jomo.glmer function, but it returns the values of all the parameters in
the model at each step of the MCMC instead of the imputations. It is useful to check the convergence
of the MCMC sampler.
Usage
jomo.glmer.MCMCchain(formula, data, level=rep(1,ncol(data)),
beta.start=NULL, l2.beta.start=NULL, u.start=NULL,
l1cov.start=NULL, l2cov.start=NULL, l1cov.prior=NULL,
l2cov.prior=NULL, a.start=NULL, a.prior=NULL,
betaY.start=NULL, covuY.start=NULL,
uY.start=NULL, nburn=1000, meth="common",
start.imp=NULL, start.imp.sub=NULL, l2.start.imp=NULL,
output=1, out.iter=10, family="binomial")
Arguments
formula an object of class formula: a symbolic description of the model to be fitted. It is
possible to include in this formula interactions (through symbols ’*’ and ’
data A data.frame containing all the variables to include in the imputation model.
Columns related to continuous variables have to be numeric and columns related
to binary/categorical variables have to be factors.
level A vector, indicating whether each variable is either a level 1 or a level 2 variable.
The value assigned to the cluster indicator is irrelevant.
beta.start Starting value for beta, the vector(s) of level-1 fixed effects for the joint model
for the covariates. For each n-category variable we have a fixed effect parameter
for each of the n-1 latent normals. The default is a matrix of zeros.
l2.beta.start Starting value for beta2, the vector(s) of level-2 fixed effects for the joint model
for the covariates. For each n-category variable we have a fixed effect parameter
for each of the n-1 latent normals. The default is a matrix of zeros.
u.start A matrix where different rows are the starting values within each cluster of the
random effects estimates u for the joint model for the covariates. The default is
a matrix of zeros.
l1cov.start Starting value of the level-1 covariance matrix of the joint model for the co-
variates. Dimension of this square matrix is equal to the number of covariates
(continuous plus latent normals) in the imputation model. The default is the
identity matrix. Functions for imputation with random cluster-specific covari-
ance matrices are an exception, because we need to pass the starting values for
all of the matrices stacked one above the other.
l2cov.start Starting value for the level 2 covariance matrix of the joint model for the covari-
ates. Dimension of this square matrix is equal to the number of level-1 covariates
(continuous plus latent normals) in the analysis model times the number of ran-
dom effects plus the number of level-2 covariates. The default is an identity
matrix.
jomo.glmer.MCMCchain 23
l1cov.prior Scale matrix for the inverse-Wishart prior for the covariance matrix. The default
is the identity matrix.
l2cov.prior Scale matrix for the inverse-Wishart prior for the level 2 covariance matrix. The
default is the identity matrix.
a.start Starting value for the degrees of freedom of the inverse Wishart distribution
of the cluster-specific covariance matrices. Default is 50+D, with D being the
dimension of the covariance matrices. This is used only with clustered data and
when option meth is set to "random".
a.prior Hyperparameter (Degrees of freedom) of the chi square prior distribution for the
degrees of freedom of the inverse Wishart distribution for the cluster-specific
covariance matrices. Default is D, with D being the dimension of the covariance
matrices.
meth Method used to deal with level 1 covariance matrix. When set to "common",
a common matrix across clusters is used (functions jomo1rancon, jomo1rancat
and jomo1ranmix). When set to "fixed", fixed study-specific matrices are con-
sidered (jomo1ranconhr, jomo1rancathr and jomo1ranmixhr with coption meth="fixed").
Finally, when set to "random", random study-specific matrices are considered
(jomo1ranconhr, jomo1rancathr and jomo1ranmixhr with option meth="random")
betaY.start Starting value for betaY, the vector of fixed effects for the substantive analysis
model. The default is the complete records estimate.
covuY.start Starting value for covuY, the random effects covariance matrix of the substantive
analysis model. The default is the complete records estimate.
uY.start Starting value for uY, the random effects matrix of the substantive analysis
model. The default is the complete records estimate.
nburn Number of burn in iterations. Default is 1000.
output When set to 0, no output is shown on screen at the end of the process. When
set to 1, only the parameter estimates related to the substantive model are shown
(default). When set to 2, all parameter estimates (posterior means) are displayed.
out.iter When set to K, every K iterations a dot is printed on screen. Default is 10.
start.imp Starting value for the missing data in the covariates of the substantive model.
n-level categorical variables are substituted by n-1 latent normals.
l2.start.imp Starting value for the missing data in the level-2 covariates of the substantive
model. n-level categorical variables are substituted by n-1 latent normals.
start.imp.sub Starting value for the missing data in the outcome of the substantive model. For
family="binomial", these are the values of the latent normals.
family One of either "gaussian"" or "binomial". For binomial family, a probit link is
assumed.
Value
A list is returned; this contains the final imputed dataset (finimp) and several 3-dimensional ma-
trices, containing all the values drawn for each parameter at each iteration: these are fixed effect
parameters of the covariates beta (collectbeta), level 1 covariance matrices (collectomega), fixed
effect estimates of the substantive model and associated residual variances. If there are some cate-
gorical outcomes, a further output is included in the list, finimp.latnorm, containing the final state
of the imputed dataset with the latent normal variables.
24 jomo.lm
Examples
cldata<-within(cldata, sex<-factor(sex))
formula<-as.formula(sex~age+measure+(1|city))
imp<-jomo.glmer.MCMCchain(formula,data, nburn=100)
# We can check, for example, the convergence of the first element of beta:
# plot(c(1:100),imp$collectbeta[1,1,1:100],type="l")
Description
A function for substantive model compatible JM imputation, when the substantive model of inter-
est is a simple linear regression model. Interactions and polynomial functions of the covariates
are allowed. Data must be passed as a data.frame where continuous variables are numeric and
binary/categorical variables are factors.
Usage
jomo.lm(formula, data, beta.start=NULL, l1cov.start=NULL,
l1cov.prior=NULL, nburn=1000, nbetween=1000, nimp=5,
output=1, out.iter=10)
Arguments
formula an object of class formula: a symbolic description of the model to be fitted. It is
possible to include in this formula interactions (through symbols ’*’ and ’
data A data.frame containing all the variables to include in the imputation model.
Columns related to continuous variables have to be numeric and columns related
to binary/categorical variables have to be factors.
jomo.lm 25
beta.start Starting value for beta, the vector(s) of fixed effects for the joint model for the
covariates. For each n-category variable we have a fixed effect parameter for
each of the n-1 latent normals. The default is a matrix of zeros.
l1cov.start Starting value of the level-1 covariance matrix of the joint model for the co-
variates. Dimension of this square matrix is equal to the number of covariates
(continuous plus latent normals) in the imputation model. The default is the
identity matrix.
l1cov.prior Scale matrix for the inverse-Wishart prior for the covariance matrix. The default
is the identity matrix.
nburn Number of burn in iterations. Default is 1000.
nbetween Number of iterations between two successive imputations. Default is 1000.
nimp Number of Imputations. Default is 5.
output When set to 0, no output is shown on screen at the end of the process. When
set to 1, only the parameter estimates related to the substantive model are shown
(default). When set to 2, all parameter estimates (posterior means) are displayed.
out.iter When set to K, every K iterations a dot is printed on screen. Default is 10.
Details
This function allows for substantive model compatible imputation when the substantive model is
a simple linear regression model. It can deal with interactions and polynomial terms through the
usual lm syntax in the formula argument. Format of the columns of data is crucial in order for the
function to deal with binary/categorical covariates appropriately in the imputation algorithm.
Value
On screen, the posterior mean of the fixed effect estimates and of the residual variance are shown.
The only argument returned is the imputed dataset in long format. Column "Imputation" indexes
the imputations. Imputation number 0 are the original data.
References
Carpenter J.R., Kenward M.G., (2013), Multiple Imputation and its Application. Wiley, ISBN:
978-0-470-74052-1.
Examples
sldata<-within(sldata, sex<-factor(sex))
data<-sldata[,c("measure","age", "sex")]
formula<-as.formula(measure~sex+age+I(age^2))
# Note we are using only 100 iterations to avoid time consuming examples,
# which go against CRAN policies.
# If we were interested in a model with interactions:
formula2<-as.formula(measure~sex*age)
imp2<-jomo.lm(formula2,data, nburn=100, nbetween=100)
# The analysis and combination steps are as for all the other functions
# (see e.g. help file for function jomo)
Description
This function is similar to the jomo.lm function, but it returns the values of all the parameters in the
model at each step of the MCMC instead of the imputations. It is useful to check the convergence
of the MCMC sampler.
Usage
jomo.lm.MCMCchain(formula, data, beta.start=NULL, l1cov.start=NULL,
l1cov.prior=NULL, betaY.start=NULL, varY.start=NULL, nburn=1000,
start.imp=NULL, start.imp.sub=NULL, output=1, out.iter=10)
Arguments
formula an object of class formula: a symbolic description of the model to be fitted. It is
possible to include in this formula interactions (through symbols ’*’ and ’
data A data.frame containing all the variables to include in the imputation model.
Columns related to continuous variables have to be numeric and columns related
to binary/categorical variables have to be factors.
beta.start Starting value for beta, the vector(s) of fixed effects for the joint model for the
covariates. For each n-category variable we have a fixed effect parameter for
each of the n-1 latent normals. The default is a matrix of zeros.
jomo.lm.MCMCchain 27
l1cov.start Starting value of the level-1 covariance matrix of the joint model for the co-
variates. Dimension of this square matrix is equal to the number of covariates
(continuous plus latent normals) in the imputation model. The default is the
identity matrix.
l1cov.prior Scale matrix for the inverse-Wishart prior for the covariance matrix. The default
is the identity matrix.
betaY.start Starting value for betaY, the vector of fixed effects for the substantive analysis
model. The default is the complete records estimate.
varY.start Starting value for varY, the residual variance of the substantive analysis model.
The default is the complete records estimate.
nburn Number of burn in iterations. Default is 1000.
output When set to 0, no output is shown on screen at the end of the process. When
set to 1, only the parameter estimates related to the substantive model are shown
(default). When set to 2, all parameter estimates (posterior means) are displayed.
out.iter When set to K, every K iterations a dot is printed on screen. Default is 10.
start.imp Starting value for the missing data in the covariates of the substantive model.
n-level categorical variables are substituted by n-1 latent normals.
start.imp.sub Starting value for the missing data in the outcome of the substantive model.
Value
A list is returned; this contains the final imputed dataset (finimp) and several 3-dimensional ma-
trices, containing all the values drawn for each parameter at each iteration: these are fixed effect
parameters of the covariates beta (collectbeta), level 1 covariance matrices (collectomega), fixed
effect estimates of the substantive model and associated residual variances. If there are some cate-
gorical outcomes, a further output is included in the list, finimp.latnorm, containing the final state
of the imputed dataset with the latent normal variables.
Examples
sldata<-within(sldata, sex<-factor(sex))
data<-sldata[,c("measure","age", "sex")]
formula<-as.formula(measure~sex+age+I(age^2))
imp<-jomo.lm.MCMCchain(formula,data, nburn=100)
28 jomo.lmer
# Note we are using only 100 iterations to avoid time consuming examples,
# which go against CRAN policies.
# We can check, for example, the convergence of the first element of beta:
plot(c(1:100),imp$collectbeta[1,1,1:100],type="l")
Description
A function for substantive model compatible JM imputation, when the substantive model of interest
is a linear mixed-effects regression model. Interactions and polynomial functions of the covariates
are allowed. Data must be passed as a data.frame where continuous variables are numeric and
binary/categorical variables are factors.
Usage
jomo.lmer(formula, data, level=rep(1,ncol(data)), beta.start=NULL,
l2.beta.start=NULL, u.start=NULL, l1cov.start=NULL, l2cov.start=NULL,
l1cov.prior=NULL, l2cov.prior=NULL, a.start=NULL, a.prior=NULL,
nburn=1000, nbetween=1000, nimp=5, meth="common", output=1, out.iter=10)
Arguments
formula an object of class formula: a symbolic description of the model to be fitted. It is
possible to include in this formula interactions (through symbols ’*’ and ’
data A data.frame containing all the variables to include in the imputation model.
Columns related to continuous variables have to be numeric and columns related
to binary/categorical variables have to be factors.
level A vector, indicating whether each variable is either a level 1 or a level 2 variable.
The value assigned to the cluster indicator is irrelevant.
beta.start Starting value for beta, the vector(s) of level-1 fixed effects for the joint model
for the covariates. For each n-category variable we have a fixed effect parameter
for each of the n-1 latent normals. The default is a matrix of zeros.
l2.beta.start Starting value for beta2, the vector(s) of level-2 fixed effects for the joint model
for the covariates. For each n-category variable we have a fixed effect parameter
for each of the n-1 latent normals. The default is a matrix of zeros.
u.start A matrix where different rows are the starting values within each cluster of the
random effects estimates u for the joint model for the covariates. The default is
a matrix of zeros.
jomo.lmer 29
l1cov.start Starting value of the level-1 covariance matrix of the joint model for the co-
variates. Dimension of this square matrix is equal to the number of covariates
(continuous plus latent normals) in the imputation model. The default is the
identity matrix. Functions for imputation with random cluster-specific covari-
ance matrices are an exception, because we need to pass the starting values for
all of the matrices stacked one above the other.
l2cov.start Starting value for the level 2 covariance matrix of the joint model for the covari-
ates. Dimension of this square matrix is equal to the number of level-1 covariates
(continuous plus latent normals) in the analysis model times the number of ran-
dom effects plus the number of level-2 covariates. The default is an identity
matrix.
l1cov.prior Scale matrix for the inverse-Wishart prior for the covariance matrix. The default
is the identity matrix.
l2cov.prior Scale matrix for the inverse-Wishart prior for the level 2 covariance matrix. The
default is the identity matrix.
a.start Starting value for the degrees of freedom of the inverse Wishart distribution
of the cluster-specific covariance matrices. Default is 50+D, with D being the
dimension of the covariance matrices. This is used only with clustered data and
when option meth is set to "random".
a.prior Hyperparameter (Degrees of freedom) of the chi square prior distribution for the
degrees of freedom of the inverse Wishart distribution for the cluster-specific
covariance matrices. Default is D, with D being the dimension of the covariance
matrices.
meth Method used to deal with level 1 covariance matrix. When set to "common",
a common matrix across clusters is used (functions jomo1rancon, jomo1rancat
and jomo1ranmix). When set to "fixed", fixed study-specific matrices are con-
sidered (jomo1ranconhr, jomo1rancathr and jomo1ranmixhr with coption meth="fixed").
Finally, when set to "random", random study-specific matrices are considered
(jomo1ranconhr, jomo1rancathr and jomo1ranmixhr with option meth="random")
nburn Number of burn in iterations. Default is 1000.
nbetween Number of iterations between two successive imputations. Default is 1000.
nimp Number of Imputations. Default is 5.
output When set to 0, no output is shown on screen at the end of the process. When
set to 1, only the parameter estimates related to the substantive model are shown
(default). When set to 2, all parameter estimates (posterior means) are displayed.
out.iter When set to K, every K iterations a dot is printed on screen. Default is 10.
Details
This function allows for substantive model compatible imputation when the substantive model is a
linear mixed-effects model. It can deal with interactions and polynomial terms through the usual
lmer syntax in the formula argument. Format of the columns of data is crucial in order for the
function to deal with binary/categorical covariates appropriately in the imputation algorithm.
30 jomo.lmer.MCMCchain
Value
On screen, the posterior mean of the fixed effect estimates and of the residual variance are shown.
The only argument returned is the imputed dataset in long format. Column "Imputation" indexes
the imputations. Imputation number 0 are the original data.
References
Carpenter J.R., Kenward M.G., (2013), Multiple Imputation and its Application. Wiley, ISBN:
978-0-470-74052-1.
Examples
cldata<-within(cldata, sex<-factor(sex))
formula<-as.formula(measure~sex+age+I(age^2)+(1|city))
# formula2<-as.formula(measure~sex*age+(1|city))
# imp2<-jomo.lmer(formula2,data, level=mylevel, nburn=10, nbetween=10)
# The analysis and combination steps are as for all the other functions
# (see e.g. help file for function jomo)
Description
This function is similar to the jomo.lmer function, but it returns the values of all the parameters in
the model at each step of the MCMC instead of the imputations. It is useful to check the convergence
of the MCMC sampler.
Usage
jomo.lmer.MCMCchain(formula, data, level=rep(1,ncol(data)), beta.start=NULL,
l2.beta.start=NULL, u.start=NULL, l1cov.start=NULL,
l2cov.start=NULL, l1cov.prior=NULL, l2cov.prior=NULL,
a.start=NULL, a.prior=NULL, betaY.start=NULL,
varY.start=NULL, covuY.start=NULL, uY.start=NULL,
nburn=1000, meth="common", start.imp=NULL,
start.imp.sub=NULL, l2.start.imp=NULL, output=1,
out.iter=10)
Arguments
formula an object of class formula: a symbolic description of the model to be fitted. It is
possible to include in this formula interactions (through symbols ’*’ and ’
data A data.frame containing all the variables to include in the imputation model.
Columns related to continuous variables have to be numeric and columns related
to binary/categorical variables have to be factors.
level A vector, indicating whether each variable is either a level 1 or a level 2 variable.
The value assigned to the cluster indicator is irrelevant.
beta.start Starting value for beta, the vector(s) of level-1 fixed effects for the joint model
for the covariates. For each n-category variable we have a fixed effect parameter
for each of the n-1 latent normals. The default is a matrix of zeros.
l2.beta.start Starting value for beta2, the vector(s) of level-2 fixed effects for the joint model
for the covariates. For each n-category variable we have a fixed effect parameter
for each of the n-1 latent normals. The default is a matrix of zeros.
u.start A matrix where different rows are the starting values within each cluster of the
random effects estimates u for the joint model for the covariates. The default is
a matrix of zeros.
l1cov.start Starting value of the level-1 covariance matrix of the joint model for the co-
variates. Dimension of this square matrix is equal to the number of covariates
(continuous plus latent normals) in the imputation model. The default is the
identity matrix. Functions for imputation with random cluster-specific covari-
ance matrices are an exception, because we need to pass the starting values for
all of the matrices stacked one above the other.
l2cov.start Starting value for the level 2 covariance matrix of the joint model for the covari-
ates. Dimension of this square matrix is equal to the number of level-1 covariates
(continuous plus latent normals) in the analysis model times the number of ran-
dom effects plus the number of level-2 covariates. The default is an identity
matrix.
32 jomo.lmer.MCMCchain
l1cov.prior Scale matrix for the inverse-Wishart prior for the covariance matrix. The default
is the identity matrix.
l2cov.prior Scale matrix for the inverse-Wishart prior for the level 2 covariance matrix. The
default is the identity matrix.
a.start Starting value for the degrees of freedom of the inverse Wishart distribution
of the cluster-specific covariance matrices. Default is 50+D, with D being the
dimension of the covariance matrices. This is used only with clustered data and
when option meth is set to "random".
a.prior Hyperparameter (Degrees of freedom) of the chi square prior distribution for the
degrees of freedom of the inverse Wishart distribution for the cluster-specific
covariance matrices. Default is D, with D being the dimension of the covariance
matrices.
meth Method used to deal with level 1 covariance matrix. When set to "common",
a common matrix across clusters is used (functions jomo1rancon, jomo1rancat
and jomo1ranmix). When set to "fixed", fixed study-specific matrices are con-
sidered (jomo1ranconhr, jomo1rancathr and jomo1ranmixhr with coption meth="fixed").
Finally, when set to "random", random study-specific matrices are considered
(jomo1ranconhr, jomo1rancathr and jomo1ranmixhr with option meth="random")
betaY.start Starting value for betaY, the vector of fixed effects for the substantive analysis
model. The default is the complete records estimate.
varY.start Starting value for varY, the residual variance of the substantive analysis model.
The default is the complete records estimate.
covuY.start Starting value for covuY, the random effects covariance matrix of the substantive
analysis model. The default is the complete records estimate.
uY.start Starting value for uY, the random effects matrix of the substantive analysis
model. The default is the complete records estimate.
nburn Number of burn in iterations. Default is 1000.
output When set to 0, no output is shown on screen at the end of the process. When
set to 1, only the parameter estimates related to the substantive model are shown
(default). When set to 2, all parameter estimates (posterior means) are displayed.
out.iter When set to K, every K iterations a dot is printed on screen. Default is 10.
start.imp Starting value for the missing data in the covariates of the substantive model.
n-level categorical variables are substituted by n-1 latent normals.
l2.start.imp Starting value for the missing data in the level-2 covariates of the substantive
model. n-level categorical variables are substituted by n-1 latent normals.
start.imp.sub Starting value for the missing data in the outcome of the substantive model.
Value
A list is returned; this contains the final imputed dataset (finimp) and several 3-dimensional ma-
trices, containing all the values drawn for each parameter at each iteration: these are fixed effect
parameters of the covariates beta (collectbeta), level 1 covariance matrices (collectomega), fixed
effect estimates of the substantive model and associated residual variances. If there are some cate-
gorical outcomes, a further output is included in the list, finimp.latnorm, containing the final state
of the imputed dataset with the latent normal variables.
jomo.MCMCchain 33
Examples
cldata<-within(cldata, sex<-factor(sex))
formula<-as.formula(measure~sex+age+I(age^2)+(1|city))
# Note we are using only 100 iterations to avoid time consuming examples,
# which go against CRAN policies.
# We can check, for example, the convergence of the first element of beta:
plot(c(1:100),imp$collectbeta[1,1,1:100],type="l")
Description
This function is similar to the jomo function, but it returns the values of all the parameters in the
model at each step of the MCMC instead of the imputations. It is useful to check the convergence
of the MCMC sampler.
Usage
Arguments
Y A data.frame containing the outcomes of the imputation model, i.e. the partially
observed level 1 variables. Columns related to continuous variables have to be
numeric and columns related to binary/categorical variables have to be factors.
Y2 A data.frame containing the level-2 outcomes of the imputation model, i.e. the
partially observed level-2 variables. Columns related to continuous variables
have to be numeric and columns related to binary/categorical variables have to
be factors.
X A data frame, or matrix, with covariates of the joint imputation model. Rows
correspond to different observations, while columns are different variables. Miss-
ing values are not allowed in these variables. In case we want an intercept, a
column of 1 is needed. The default is a column of 1.
X2 A data frame, or matrix, with level-2 covariates of the joint imputation model.
Rows correspond to different level-1 observations, while columns are different
variables. Missing values are not allowed in these variables. In case we want an
intercept, a column of 1 is needed. The default is a column of 1.
Z A data frame, or matrix, for covariates associated to random effects in the joint
imputation model. Rows correspond to different observations, while columns
are different variables. Missing values are not allowed in these variables. In
case we want an intercept, a column of 1 is needed. The default is a column of
1.
clus A data frame, or matrix, containing the cluster indicator for each observation. If
missing, functions for single level imputation are automatically used.
beta.start Starting value for beta, the vector(s) of level-1 fixed effects. Rows index dif-
ferent covariates and columns index different outcomes. For each n-category
variable we have a fixed effect parameter for each of the n-1 latent normals. The
default is a matrix of zeros.
l2.beta.start Starting value for beta2, the vector(s) of level-2 fixed effects. Rows index dif-
ferent covariates and columns index different level-2 outcomes. For each n-
category variable we have a fixed effect parameter for each of the n-1 latent
normals. The default is a matrix of zeros.
u.start A matrix where different rows are the starting values within each cluster for the
random effects estimates u. The default is a matrix of zeros.
l1cov.start Starting value for the covariance matrix. Dimension of this square matrix is
equal to the number of outcomes (continuous plus latent normals) in the impu-
tation model. The default is the identity matrix. Functions for imputation with
random cluster-specific covariance matrices are an exception, because we need
to pass the starting values for all of the matrices stacked one above the other.
l2cov.start Starting value for the level 2 covariance matrix. Dimension of this square matrix
is equal to the number of outcomes (continuous plus latent normals) in the im-
putation model times the number of random effects plus the number of level-2
outcomes. The default is an identity matrix.
l1cov.prior Scale matrix for the inverse-Wishart prior for the covariance matrix. The default
is the identity matrix.
jomo.MCMCchain 35
l2cov.prior Scale matrix for the inverse-Wishart prior for the level 2 covariance matrix. The
default is the identity matrix.
start.imp Starting value for the imputed dataset. n-level categorical variables are substi-
tuted by n-1 latent normals.
l2.start.imp Starting value for the level-2 imputed variables. n-level categorical variables are
substituted by n-1 latent normals.
nburn Number of iterations. Default is 1000.
a Starting value for the degrees of freedom of the inverse Wishart distribution
of the cluster-specific covariance matrices. Default is 50+D, with D being the
dimension of the covariance matrices. This is used only with clustered data and
when option meth is set to "random".
a.prior Hyperparameter (Degrees of freedom) of the chi square prior distribution for the
degrees of freedom of the inverse Wishart distribution for the cluster-specific
covariance matrices. Default is D, with D being the dimension of the covariance
matrices.
meth Method used to deal with level 1 covariance matrix. When set to "common",
a common matrix across clusters is used (functions jomo1rancon, jomo1rancat
and jomo1ranmix). When set to "fixed", fixed study-specific matrices are con-
sidered (jomo1ranconhr, jomo1rancathr and jomo1ranmixhr with coption meth="fixed").
Finally, when set to "random", random study-specific matrices are considered
(jomo1ranconhr, jomo1rancathr and jomo1ranmixhr with option meth="random")
output When set to any value different from 1 (default), no output is shown on screen
at the end of the process.
out.iter When set to K, every K iterations a dot is printed on screen. Default is 10.
Value
A list is returned; this contains the final imputed dataset (finimp) and several 3-dimensional matri-
ces, containing all the values drawn for each parameter at each iteration: these are, potentially, fixed
effect parameters beta (collectbeta), random effects (collectu), level 1 (collectomega) and level 2
covariance matrices (collectcovu) and level-2 fixed effect parameters. If there are some categorical
outcomes, a further output is included in the list, finimp.latnorm, containing the final state of the
imputed dataset with the latent normal variables.
Examples
Y<-cldata[,c("measure","age")]
clus<-cldata[,c("city")]
nburn=as.integer(200);
plot(c(1:nburn),imp$collectbeta[1,1,1:nburn],type="l")
#Or similarly we can check the convergence of any element of the level 2 covariance matrix:
plot(c(1:nburn),imp$collectcovu[1,2,1:nburn],type="l")
Description
A function for substantive model compatible JM imputation, when the substantive model of inter-
est is a simple ordinal regression model. Interactions and polynomial functions of the covariates
are allowed. Data must be passed as a data.frame where continuous variables are numeric and
binary/categorical variables are factors.
Usage
jomo.polr(formula, data, beta.start=NULL, l1cov.start=NULL,
l1cov.prior=NULL,nburn=1000, nbetween=1000, nimp=5,
output=1, out.iter=10)
Arguments
formula an object of class formula: a symbolic description of the model to be fitted. It is
possible to include in this formula interactions (through symbols ’*’ and ’
data A data.frame containing all the variables to include in the imputation model.
Columns related to continuous variables have to be numeric and columns related
to binary/categorical variables have to be factors.
beta.start Starting value for beta, the vector(s) of fixed effects for the joint model for the
covariates. For each n-category variable we have a fixed effect parameter for
each of the n-1 latent normals. The default is a matrix of zeros.
l1cov.start Starting value of the level-1 covariance matrix of the joint model for the co-
variates. Dimension of this square matrix is equal to the number of covariates
(continuous plus latent normals) in the imputation model. The default is the
identity matrix.
l1cov.prior Scale matrix for the inverse-Wishart prior for the covariance matrix. The default
is the identity matrix.
nburn Number of burn in iterations. Default is 1000.
nbetween Number of iterations between two successive imputations. Default is 1000.
nimp Number of Imputations. Default is 5.
output When set to 0, no output is shown on screen at the end of the process. When
set to 1, only the parameter estimates related to the substantive model are shown
(default). When set to 2, all parameter estimates (posterior means) are displayed.
out.iter When set to K, every K iterations a dot is printed on screen. Default is 10.
jomo.polr 37
Details
This function allows for substantive model compatible imputation when the substantive model is
a simple ordinal regression model. It can deal with interactions and polynomial terms through the
usual lm syntax in the formula argument. Format of the columns of data is crucial in order for the
function to deal with binary/categorical covariates appropriately in the imputation algorithm.
Value
On screen, the posterior mean of the fixed effect estimates and of the residual variance are shown.
The only argument returned is the imputed dataset in long format. Column "Imputation" indexes
the imputations. Imputation number 0 are the original data.
References
Carpenter J.R., Kenward M.G., (2013), Multiple Imputation and its Application. Wiley, ISBN:
978-0-470-74052-1.
Examples
sldata<-within(sldata, social<-factor(social))
data<-sldata[,c("measure","age", "social")]
formula<-as.formula(social~age+measure)
# Note we are using only 100 iterations to avoid time consuming examples,
# which go against CRAN policies. In real applications we would use
# much larger burn-ins (around 1000) and at least 5 imputations.
# Check help page for function jomo to see how to fit the model and
# combine estimates with Rubin's rules
38 jomo.polr.MCMCchain
Description
This function is similar to the jomo.polr function, but it returns the values of all the parameters in the
model at each step of the MCMC instead of the imputations. It is useful to check the convergence
of the MCMC sampler.
Usage
jomo.polr.MCMCchain(formula, data, beta.start=NULL, l1cov.start=NULL,
l1cov.prior=NULL, betaY.start=NULL, nburn=1000,
start.imp=NULL, start.imp.sub=NULL, output=1, out.iter=10)
Arguments
formula an object of class formula: a symbolic description of the model to be fitted. It is
possible to include in this formula interactions (through symbols ’*’ and ’
data A data.frame containing all the variables to include in the imputation model.
Columns related to continuous variables have to be numeric and columns related
to binary/categorical variables have to be factors.
start.imp Starting value for the imputed covariates. n-level categorical variables are sub-
stituted by n-1 latent normals.
start.imp.sub Starting value for the imputations of the outcome. When using binomial family,
this is the value of the latent normal.
beta.start Starting value for beta, the vector(s) of fixed effects for the joint model for the
covariates. For each n-category variable we have a fixed effect parameter for
each of the n-1 latent normals. The default is a matrix of zeros.
l1cov.start Starting value of the level-1 covariance matrix of the joint model for the co-
variates. Dimension of this square matrix is equal to the number of covariates
(continuous plus latent normals) in the imputation model. The default is the
identity matrix.
l1cov.prior Scale matrix for the inverse-Wishart prior for the covariance matrix. The default
is the identity matrix.
betaY.start Starting value for betaY, the vector of fixed effects for the substantive analysis
model. The default is the complete records estimate.
nburn Number of burn in iterations. Default is 1000.
output When set to 0, no output is shown on screen at the end of the process. When
set to 1, only the parameter estimates related to the substantive model are shown
(default). When set to 2, all parameter estimates (posterior means) are displayed.
out.iter When set to K, every K iterations a dot is printed on screen. Default is 10.
jomo.smc 39
Value
A list is returned; this contains the final imputed dataset (finimp) and several 3-dimensional ma-
trices, containing all the values drawn for each parameter at each iteration: these are fixed effect
parameters of the covariates beta (collectbeta), level 1 covariance matrices (collectomega), fixed
effect estimates of the substantive model and associated residual variances. If there are some cate-
gorical outcomes, a further output is included in the list, finimp.latnorm, containing the final state
of the imputed dataset with the latent normal variables.
Examples
sldata<-within(sldata, social<-factor(social))
data<-sldata[,c("measure","age", "social")]
formula<-as.formula(social~age+measure)
imp<-jomo.polr.MCMCchain(formula,data, nburn=100)
# Note we are using only 100 iterations to avoid time consuming examples,
# which go against CRAN policies. In real applications we would use
# much larger burn-ins (around 1000, to say the least).
# We can check, for example, the convergence of the first element of beta:
plot(c(1:100),imp$collectbeta[1,1,1:100],type="l")
Description
A wrapper function for all the substantive model compatible JM imputation functions. The sub-
stantive model of interest is either lm, glm, polr, lmer, clmm, glmer or coxph. Interactions and
polynomial functions of the covariates are allowed. Data must be passed as a data.frame where
continuous variables are numeric and binary/categorical variables are factors.
40 jomo.smc
Usage
jomo.smc(formula, data, level=rep(1,ncol(data)), beta.start=NULL,
l2.beta.start=NULL, u.start=NULL, l1cov.start=NULL, l2cov.start=NULL,
l1cov.prior=NULL, l2cov.prior=NULL, a.start=NULL, a.prior=NULL,
nburn=1000, nbetween=1000, nimp=5, meth="common", family="binomial",
output=1, out.iter=10, model)
Arguments
formula an object of class formula: a symbolic description of the model to be fitted. It is
possible to include in this formula interactions (through symbols ’*’ and ’
data A data.frame containing all the variables to include in the imputation model.
Columns related to continuous variables have to be numeric and columns related
to binary/categorical variables have to be factors.
level If the dataset is multilevel, this must be a vector indicating whether each variable
is either a level 1 or a level 2 variable. The value assigned to the cluster indicator
is irrelevant.
beta.start Starting value for beta, the vector(s) of level-1 fixed effects for the joint model
for the covariates. For each n-category variable we have a fixed effect parameter
for each of the n-1 latent normals. The default is a matrix of zeros.
l2.beta.start Starting value for beta2, the vector(s) of level-2 fixed effects for the joint model
for the covariates. For each n-category variable we have a fixed effect parameter
for each of the n-1 latent normals. The default is a matrix of zeros.
u.start A matrix where different rows are the starting values within each cluster of the
random effects estimates u for the joint model for the covariates. The default is
a matrix of zeros.
l1cov.start Starting value of the level-1 covariance matrix of the joint model for the co-
variates. Dimension of this square matrix is equal to the number of covariates
(continuous plus latent normals) in the imputation model. The default is the
identity matrix. Functions for imputation with random cluster-specific covari-
ance matrices are an exception, because we need to pass the starting values for
all of the matrices stacked one above the other.
l2cov.start Starting value for the level 2 covariance matrix of the joint model for the covari-
ates. Dimension of this square matrix is equal to the number of level-1 covariates
(continuous plus latent normals) in the analysis model times the number of ran-
dom effects plus the number of level-2 covariates. The default is an identity
matrix.
l1cov.prior Scale matrix for the inverse-Wishart prior for the covariance matrix. The default
is the identity matrix.
l2cov.prior Scale matrix for the inverse-Wishart prior for the level 2 covariance matrix. The
default is the identity matrix.
a.start Starting value for the degrees of freedom of the inverse Wishart distribution
of the cluster-specific covariance matrices. Default is 50+D, with D being the
dimension of the covariance matrices. This is used only with clustered data and
when option meth is set to "random".
jomo.smc 41
a.prior Hyperparameter (Degrees of freedom) of the chi square prior distribution for the
degrees of freedom of the inverse Wishart distribution for the cluster-specific
covariance matrices. Default is D, with D being the dimension of the covariance
matrices.
meth Method used to deal with level 1 covariance matrix. When set to "common",
a common matrix across clusters is used (functions jomo1rancon, jomo1rancat
and jomo1ranmix). When set to "fixed", fixed study-specific matrices are con-
sidered (jomo1ranconhr, jomo1rancathr and jomo1ranmixhr with coption meth="fixed").
Finally, when set to "random", random study-specific matrices are considered
(jomo1ranconhr, jomo1rancathr and jomo1ranmixhr with option meth="random")
nburn Number of burn in iterations. Default is 1000.
nbetween Number of iterations between two successive imputations. Default is 1000.
nimp Number of Imputations. Default is 5.
output When set to 0, no output is shown on screen at the end of the process. When
set to 1, only the parameter estimates related to the substantive model are shown
(default). When set to 2, all parameter estimates (posterior means) are displayed.
out.iter When set to K, every K iterations a dot is printed on screen. Default is 10.
model The type of model we want to impute compatibly with. It can currently be one
of lm, glm (binomial), polr, coxph, lmer, clmm or glmer (binomial).
family One of either "gaussian"" or "binomial". For binomial family, a probit link is
assumed.
Details
This function allows for substantive model compatible imputation. It can deal with interactions and
polynomial terms through the usual lmer syntax in the formula argument. Format of the columns
of data is crucial in order for the function to deal with binary/categorical covariates appropriately in
the imputation algorithm.
Value
On screen, the posterior mean of the fixed effect estimates and of the residual variance are shown.
The only argument returned is the imputed dataset in long format. Column "Imputation" indexes
the imputations. Imputation number 0 are the original data.
References
Carpenter J.R., Kenward M.G., (2013), Multiple Imputation and its Application. Wiley, ISBN:
978-0-470-74052-1.
Examples
cldata<-within(cldata, sex<-factor(sex))
42 jomo.smc.MCMCchain
formula<-as.formula(measure~sex+age+I(age^2)+(1|city))
# Note we are using only 100 iterations to avoid time consuming examples,
# which go against CRAN policies.
# If we were interested in a model with interactions:
# formula2<-as.formula(measure~sex*age+(1|city))
# imp2<-jomo.smc(formula2,data, level=mylevel, nburn=100, nbetween=100, model="lmer")
# The analysis and combination steps are as for all the other functions
# (see e.g. help file for function jomo)
Description
This function is similar to the jomo.smc function, but it returns the values of all the parameters in the
model at each step of the MCMC instead of the imputations. It is useful to check the convergence
of the MCMC sampler.
Usage
Arguments
formula an object of class formula: a symbolic description of the model to be fitted. It is
possible to include in this formula interactions (through symbols ’*’ and ’
data A data.frame containing all the variables to include in the imputation model.
Columns related to continuous variables have to be numeric and columns related
to binary/categorical variables have to be factors.
level If the dataset is multilevel, this must be a vector indicating whether each variable
is either a level 1 or a level 2 variable. The value assigned to the cluster indicator
is irrelevant.
beta.start Starting value for beta, the vector(s) of level-1 fixed effects for the joint model
for the covariates. For each n-category variable we have a fixed effect parameter
for each of the n-1 latent normals. The default is a matrix of zeros.
l2.beta.start Starting value for beta2, the vector(s) of level-2 fixed effects for the joint model
for the covariates. For each n-category variable we have a fixed effect parameter
for each of the n-1 latent normals. The default is a matrix of zeros.
u.start A matrix where different rows are the starting values within each cluster of the
random effects estimates u for the joint model for the covariates. The default is
a matrix of zeros.
l1cov.start Starting value of the level-1 covariance matrix of the joint model for the co-
variates. Dimension of this square matrix is equal to the number of covariates
(continuous plus latent normals) in the imputation model. The default is the
identity matrix. Functions for imputation with random cluster-specific covari-
ance matrices are an exception, because we need to pass the starting values for
all of the matrices stacked one above the other.
l2cov.start Starting value for the level 2 covariance matrix of the joint model for the covari-
ates. Dimension of this square matrix is equal to the number of level-1 covariates
(continuous plus latent normals) in the analysis model times the number of ran-
dom effects plus the number of level-2 covariates. The default is an identity
matrix.
l1cov.prior Scale matrix for the inverse-Wishart prior for the covariance matrix. The default
is the identity matrix.
l2cov.prior Scale matrix for the inverse-Wishart prior for the level 2 covariance matrix. The
default is the identity matrix.
a.start Starting value for the degrees of freedom of the inverse Wishart distribution
of the cluster-specific covariance matrices. Default is 50+D, with D being the
dimension of the covariance matrices. This is used only with clustered data and
when option meth is set to "random".
a.prior Hyperparameter (Degrees of freedom) of the chi square prior distribution for the
degrees of freedom of the inverse Wishart distribution for the cluster-specific
covariance matrices. Default is D, with D being the dimension of the covariance
matrices.
meth Method used to deal with level 1 covariance matrix. When set to "common",
a common matrix across clusters is used (functions jomo1rancon, jomo1rancat
and jomo1ranmix). When set to "fixed", fixed study-specific matrices are con-
sidered (jomo1ranconhr, jomo1rancathr and jomo1ranmixhr with coption meth="fixed").
44 jomo.smc.MCMCchain
Value
A list is returned; this contains the final imputed dataset (finimp) and several 3-dimensional ma-
trices, containing all the values drawn for each parameter at each iteration: these are fixed effect
parameters of the covariates beta (collectbeta), level 1 covariance matrices (collectomega), fixed
effect estimates of the substantive model and associated residual variances. If there are some cate-
gorical outcomes, a further output is included in the list, finimp.latnorm, containing the final state
of the imputed dataset with the latent normal variables.
Examples
cldata<-within(cldata, sex<-factor(sex))
formula<-as.formula(measure~sex+age+I(age^2)+(1|city))
# Note we are using only 100 iterations to avoid time consuming examples,
# which go against CRAN policies.
# We can check, for example, the convergence of the first element of beta:
plot(c(1:100),imp$collectbeta[1,1,1:100],type="l")
Description
A wrapper function linking the 3 single level JM Imputation functions. The matrix of responses Y,
must be a data.frame where continuous variables are numeric and binary/categorical variables are
factors.
Usage
jomo1 (Y, X=NULL, beta.start=NULL, l1cov.start=NULL, l1cov.prior=NULL,
nburn=100, nbetween=100, nimp=5, output=1, out.iter=10)
Arguments
Y A data.frame containing the outcomes of the imputation model. Columns re-
lated to continuous variables have to be numeric and columns related to bi-
nary/categorical variables have to be factors.
X A data frame, or matrix, with covariates of the joint imputation model. Rows
correspond to different observations, while columns are different variables. Miss-
ing values are not allowed in these variables. In case we want an intercept, a
column of 1 is needed. The default is a column of 1.
beta.start Starting value for beta, the vector(s) of fixed effects. Rows index different co-
variates and columns index different outcomes. For each n-category variable we
have a fixed effect parameter for each of the n-1 latent normals. The default is a
matrix of zeros.
l1cov.start Starting value for the covariance matrix. Dimension of this square matrix is
equal to the number of outcomes (continuous plus latent normals) in the impu-
tation model. The default is the identity matrix.
46 jomo1
l1cov.prior Scale matrix for the inverse-Wishart prior for the covariance matrix. The default
is the identity matrix.
nburn Number of burn in iterations. Default is 100.
nbetween Number of iterations between two successive imputations. Default is 100.
nimp Number of Imputations. Default is 5.
output When set to any value different from 1 (default), no output is shown on screen
at the end of the process.
out.iter When set to K, every K iterations a dot is printed on screen. Default is 10.
Details
This is just a wrapper function to link jomo1con, jomo1cat and jomo1mix. Format of the columns
of Y is crucial in order for the function to be using the right sub-function.
Value
On screen, the posterior mean of the fixed effects estimates and of the covariance matrix are shown.
The only argument returned is the imputed dataset in long format. Column "Imputation" indexes
the imputations. Imputation number 0 are the original data.
References
Carpenter J.R., Kenward M.G., (2013), Multiple Imputation and its Application. Chapter 3-5, Wi-
ley, ISBN: 978-0-470-74052-1.
Examples
Y<-sldata[,c("measure","age")]
nburn=as.integer(200);
nbetween=as.integer(200);
nimp=as.integer(5);
imp<-jomo1(Y,nburn=nburn,nbetween=nbetween,nimp=nimp)
# Check help page for function jomo to see how to fit the model and
# combine estimates with Rubin's rules
jomo1.MCMCchain 47
Description
This function is similar to jomo1, but it returns the values of all the parameters in the model at each
step of the MCMC instead of the imputations. It is useful to check the convergence of the MCMC
sampler.
Usage
jomo1.MCMCchain(Y, X=NULL, beta.start=NULL, l1cov.start=NULL, l1cov.prior=NULL,
start.imp=NULL, nburn=100, output=1, out.iter=10)
Arguments
Y A data.frame containing the outcomes of the imputation model. Columns re-
lated to continuous variables have to be numeric and columns related to bi-
nary/categorical variables have to be factors.
X A data frame, or matrix, with covariates of the joint imputation model. Rows
correspond to different observations, while columns are different variables. Miss-
ing values are not allowed in these variables. In case we want an intercept, a
column of 1 is needed. The default is a column of 1.
beta.start Starting value for beta, the vector(s) of fixed effects. Rows index different co-
variates and columns index different outcomes. For each n-category variable we
have a fixed effect parameter for each of the n-1 latent normals. The default is a
matrix of zeros.
l1cov.start Starting value for the covariance matrix. Dimension of this square matrix is
equal to the number of outcomes (continuous plus latent normals) in the impu-
tation model. The default is the identity matrix.
l1cov.prior Scale matrix for the inverse-Wishart prior for the covariance matrix. The default
is the identity matrix.
start.imp Starting value for the imputed dataset. n-level categorical variables are substi-
tuted by n-1 latent normals.
nburn Number of iterations. Default is 100.
output When set to any value different from 1 (default), no output is shown on screen
at the end of the process.
out.iter When set to K, every K iterations a dot is printed on screen. Default is 10.
Value
A list with three elements is returned: the final imputed dataset (finimp) and three 3-dimensional
matrices, containing all the values for beta (collectbeta) and omega (collectomega). If there are
some categorical outcomes, a further output is included in the list, finimp.latnorm, containing the
final state of the imputed dataset with the latent normal variables.
48 jomo1cat
Examples
Y<-sldata[,c("measure","age")]
nburn=as.integer(200);
imp<-jomo1.MCMCchain(Y,nburn=nburn)
plot(c(1:nburn),imp$collectbeta[1,1,1:nburn],type="l")
plot(c(1:nburn),imp$collectomega[1,2,1:nburn],type="l")
Description
Impute a single level dataset with categorical variables as outcomes. A joint multivariate model
for partially observed data is assumed and imputations are generated through the use of a Gibbs
sampler where the covariance matrix is updated with a Metropolis-Hastings step. Fully observed
categorical covariates can be included in the imputation model as covariates as well, but in that case
dummy variables have to be created first.
Usage
jomo1cat(Y.cat, Y.numcat, X=NULL, beta.start=NULL, l1cov.start=NULL,
l1cov.prior=NULL, nburn=100, nbetween=100, nimp=5,output=1, out.iter=10)
Arguments
Y.cat A data frame, or matrix, with categorical (or binary) responses of the joint im-
putation model. Rows correspond to different observations, while columns are
different variables. Missing values are coded as NA.
Y.numcat A vector with the number of categories in each categorical (or binary) variable.
X A data frame, or matrix, with covariates of the joint imputation model. Rows
correspond to different observations, while columns are different variables. Miss-
ing values are not allowed in these variables. In case we want an intercept, a
column of 1 is needed. The default is a column of 1.
jomo1cat 49
beta.start Starting value for beta, the vector(s) of fixed effects. Rows index different co-
variates and columns index different outcomes. For each n-category variable we
have a fixed effect parameter for each of the n-1 latent normals. The default is a
matrix of zeros.
l1cov.start Starting value for the covariance matrix. Dimension of this square matrix is
equal to the number of outcomes (continuous plus latent normals) in the impu-
tation model. The default is the identity matrix.
l1cov.prior Scale matrix for the inverse-Wishart prior for the covariance matrix. The default
is the identity matrix.
nburn Number of burn in iterations. Default is 100.
nbetween Number of iterations between two successive imputations. Default is 100.
nimp Number of Imputations. Default is 5.
output When set to any value different from 1 (default), no output is shown on screen
at the end of the process.
out.iter When set to K, every K iterations a dot is printed on screen. Default is 10.
Details
The Gibbs sampler algorithm used is described in detail in Chapter 5 of Carpenter and Kenward
(2013). Regarding the choice of the priors, a flat prior is considered for beta and for the covariance
matrix. A Metropolis Hastings step is implemented to update the covariance matrix, as described in
the book. Binary or continuous covariates in the imputation model may be considered without any
problem, but when considering a categorical covariate it has to be included with dummy variables
(binary indicators) only.
Value
On screen, the posterior mean of the fixed effects estimates and of the covariance matrix are shown.
The only argument returned is the imputed dataset in long format. Column "Imputation" indexes
the imputations. Imputation number 0 are the original data.
References
Carpenter J.R., Kenward M.G., (2013), Multiple Imputation and its Application. Chapter 5, Wiley,
ISBN: 978-0-470-74052-1.
Examples
# make sure sex is a factor:
sldata<-within(sldata, sex<-factor(sex))
Y.cat=sldata[,c("social"), drop=FALSE]
50 jomo1cat.MCMCchain
Y.numcat=matrix(4,1,1)
X=data.frame(rep(1,300),sldata[,c("sex")])
colnames(X)<-c("const", "sex")
beta.start<-matrix(0,2,3)
l1cov.start<-diag(1,3)
l1cov.prior=diag(1,3);
nburn=as.integer(100);
nbetween=as.integer(100);
nimp=as.integer(5);
imp<-jomo1cat(Y.cat,Y.numcat,X,beta.start,l1cov.start,l1cov.prior,nburn,nbetween,nimp)
# Check help page for function jomo to see how to fit the model and
# combine estimates with Rubin's rules
Description
This function is similar to jomo1cat, but it returns the values of all the parameters in the model at
each step of the MCMC instead of the imputations. It is useful to check the convergence of the
MCMC sampler.
Usage
Arguments
Y.cat A data frame, or matrix, with categorical (or binary) responses of the joint im-
putation model. Rows correspond to different observations, while columns are
different variables. Missing values are coded as NA.
Y.numcat A vector with the number of categories in each categorical (or binary) variable.
jomo1cat.MCMCchain 51
X A data frame, or matrix, with covariates of the joint imputation model. Rows
correspond to different observations, while columns are different variables. Miss-
ing values are not allowed in these variables. In case we want an intercept, a
column of 1 is needed. The default is a column of 1.
beta.start Starting value for beta, the vector(s) of fixed effects. Rows index different co-
variates and columns index different outcomes. For each n-category variable we
have a fixed effect parameter for each of the n-1 latent normals. The default is a
matrix of zeros.
l1cov.start Starting value for the covariance matrix. Dimension of this square matrix is
equal to the number of outcomes (continuous plus latent normals) in the impu-
tation model. The default is the identity matrix.
l1cov.prior Scale matrix for the inverse-Wishart prior for the covariance matrix. The default
is the identity matrix.
start.imp Starting value for the imputed dataset. n-level categorical variables are substi-
tuted by n-1 latent normals.
nburn Number of iterations. Default is 100.
output When set to any value different from 1 (default), no output is shown on screen
at the end of the process.
out.iter When set to K, every K iterations a dot is printed on screen. Default is 10.
Value
A list with four elements is returned: the final imputed dataset (finimp) and three 3-dimensional
matrices, containing all the values drawn at each iteration for fixed effect parameters beta (collect-
beta) and covariance matrix omega (collectomega). Finally, in finimp.latnorm, it is stored the final
state of the imputed dataset with the latent normals in place of the categorical variables.
Examples
# make sure sex is a factor:
sldata<-within(sldata, sex<-factor(sex))
Y.cat=sldata[,c("social"), drop=FALSE]
Y.numcat=matrix(4,1,1)
X=data.frame(rep(1,300),sldata[,c("sex")])
colnames(X)<-c("const", "sex")
beta.start<-matrix(0,2,3)
l1cov.start<-diag(1,3)
l1cov.prior=diag(1,3);
nburn=as.integer(100);
imp<-jomo1cat.MCMCchain(Y.cat,Y.numcat,X,beta.start,l1cov.start,l1cov.prior,nburn=nburn)
plot(c(1:nburn),imp$collectbeta[1,1,1:nburn],type="l")
Description
Impute a single level dataset with continuous outcomes only. A joint multivariate model for par-
tially observed data is assumed and imputations are generated through the use of a Gibbs sampler.
Categorical covariates may be considered, but they have to be included with dummy variables.
Usage
jomo1con(Y, X=NULL, beta.start=NULL, l1cov.start=NULL, l1cov.prior=NULL,
nburn=100, nbetween=100, nimp=5, output=1, out.iter=10)
Arguments
Y A data frame, or matrix, with responses of the joint imputation model. Rows cor-
respond to different observations, while columns are different variables. Missing
values are coded as NA.
X A data frame, or matrix, with covariates of the joint imputation model. Rows
correspond to different observations, while columns are different variables. Miss-
ing values are not allowed in these variables. In case we want an intercept, a
column of 1 is needed. The default is a column of 1.
beta.start Starting value for beta, the vector(s) of fixed effects. Rows index different co-
variates and columns index different outcomes. The default is a matrix of zeros.
l1cov.start Starting value for the covariance matrix. Dimension of this square matrix is
equal to the number of outcomes in the imputation model. The default is the
identity matrix.
l1cov.prior Scale matrix for the inverse-Wishart prior for the covariance matrix. The default
is the identity matrix.
nburn Number of burn in iterations. Default is 100.
nbetween Number of iterations between two successive imputations. Default is 100.
nimp Number of Imputations. Default is 5.
output When set to any value different from 1 (default), no output is shown on screen
at the end of the process.
out.iter When set to K, every K iterations a dot is printed on screen. Default is 10.
jomo1con 53
Details
The Gibbs sampler algorithm used is described in detail in Chapter 3 of Carpenter and Kenward
(2013). Regarding the choice of the priors, a flat prior is considered for beta, while an inverse-
Wishart prior is given to the covariance matrix, with p-1 degrees of freedom, aka the minimum
possible, to guarantee the greatest uncertainty. Binary or continuous covariates in the imputation
model may be considered without any problem, but when considering a categorical covariate it has
to be included through dummy variables (binary indicators) only.
Value
On screen, the posterior mean of the fixed effects estimates and of the covariance matrix are shown.
The only argument returned is the imputed dataset in long format. Column "Imputation" indexes
the imputations. Imputation number 0 are the original data.
References
Carpenter J.R., Kenward M.G., (2013), Multiple Imputation and its Application. Chapter 3, Wiley,
ISBN: 978-0-470-74052-1.
Examples
Y=sldata[,c("measure", "age")]
X=data.frame(rep(1,300),sldata[,c("sex")])
colnames(X)<-c("const", "sex")
beta.start<-matrix(0,2,2)
l1cov.start<-diag(1,2)
l1cov.prior=diag(1,2);
nburn=as.integer(200);
nbetween=as.integer(200);
nimp=as.integer(5);
imp<-jomo1con(Y,X,beta.start,l1cov.start,l1cov.prior,nburn,nbetween,nimp)
# Check help page for function jomo to see how to fit the model and
# combine estimates with Rubin's rules
54 jomo1con.MCMCchain
Description
This function is similar to jomo1con, but it returns the values of all the parameters in the model
at each step of the MCMC instead of the imputations. It is useful to check the convergence of the
MCMC sampler.
Usage
jomo1con.MCMCchain(Y, X=NULL, beta.start=NULL, l1cov.start=NULL,
l1cov.prior=NULL, start.imp=NULL, nburn=100, output=1, out.iter=10)
Arguments
Y A data frame, or matrix, with responses of the joint imputation model. Rows cor-
respond to different observations, while columns are different variables. Missing
values are coded as NA.
X A data frame, or matrix, with covariates of the joint imputation model. Rows
correspond to different observations, while columns are different variables. Miss-
ing values are not allowed in these variables. In case we want an intercept, a
column of 1 is needed. The default is a column of 1.
beta.start Starting value for beta, the vector(s) of fixed effects. Rows index different co-
variates and columns index different outcomes. The default is a matrix of zeros.
l1cov.start Starting value for the covariance matrix. Dimension of this square matrix is
equal to the number of outcomes in the imputation model. The default is the
identity matrix.
l1cov.prior Scale matrix for the inverse-Wishart prior for the covariance matrix. The default
is the identity matrix.
start.imp Starting value for the imputed dataset.
nburn Number of iterations. Default is 100.
output When set to any value different from 1 (default), no output is shown on screen
at the end of the process.
out.iter When set to K, every K iterations a dot is printed on screen. Default is 10.
Value
A list with three elements is returned: the final imputed dataset (finimp) and three 3-dimensional
matrices, containing all the values for the fixed effect parameters beta (collectbeta) and the covari-
ance matrix omega (collectomega).
jomo1mix 55
Examples
Y=sldata[,c("measure", "age")]
X=data.frame(rep(1,300),sldata[,c("sex")])
colnames(X)<-c("const", "sex")
beta.start<-matrix(0,2,2)
l1cov.start<-diag(1,2)
l1cov.prior=diag(1,2);
nburn=as.integer(200);
imp<-jomo1con.MCMCchain(Y,X,beta.start,l1cov.start,l1cov.prior,nburn=nburn)
plot(c(1:nburn),imp$collectbeta[1,1,1:nburn],type="l")
plot(c(1:nburn),imp$collectomega[1,2,1:nburn],type="l")
Description
Impute a single level dataset with mixed data types as outcome. A joint multivariate model for
partially observed data is assumed and imputations are generated through the use of a Gibbs sampler
where the covariance matrix is updated with a Metropolis-Hastings step. Fully observed categorical
variables may be considered as covariates as well, but they have to be included as dummy variables.
Usage
jomo1mix(Y.con, Y.cat, Y.numcat, X=NULL, beta.start=NULL, l1cov.start=NULL,
l1cov.prior=NULL, nburn=100, nbetween=100, nimp=5, output=1,out.iter=10)
Arguments
Y.con A data frame, or matrix, with continuous responses of the joint imputation
model. Rows correspond to different observations, while columns are differ-
ent variables. Missing values are coded as NA. If no continuous outcomes are
present in the model, jomo1cat should be used instead.
56 jomo1mix
Y.cat A data frame, or matrix, with categorical (or binary) responses of the joint im-
putation model. Rows correspond to different observations, while columns are
different variables. Missing values are coded as NA.
Y.numcat A vector with the number of categories in each categorical (or binary) variable.
X A data frame, or matrix, with covariates of the joint imputation model. Rows
correspond to different observations, while columns are different variables. Miss-
ing values are not allowed in these variables. In case we want an intercept, a
column of 1 is needed. The default is a column of 1.
beta.start Starting value for beta, the vector(s) of fixed effects. Rows index different co-
variates and columns index different outcomes. For each n-category variable we
define n-1 latent normals. The default is a matrix of zeros.
l1cov.start Starting value for the covariance matrix. Dimension of this square matrix is
equal to the number of outcomes (continuous plus latent normals) in the impu-
tation model. The default is the identity matrix.
l1cov.prior Scale matrix for the inverse-Wishart prior for the covariance matrix. The default
is the identity matrix.
nburn Number of burn in iterations. Default is 100.
nbetween Number of iterations between two successive imputations. Default is 100.
nimp Number of Imputations. Default is 5.
output When set to any value different from 1 (default), no output is shown on screen
at the end of the process.
out.iter When set to K, every K iterations a dot is printed on screen. Default is 10.
Details
Regarding the choice of the priors, a flat prior is considered for beta and for the covariance matrix.
A Metropolis Hastings step is implemented to update the covariance matrix, as described in the
book. Binary or continuous covariates in the imputation model may be considered without any
problem, but when considering a categorical covariate it has to be included with dummy variables
(binary indicators) only.
Value
On screen, the posterior mean of the fixed effects estimates and of the covariance matrix are shown.
The only argument returned is the imputed dataset in long format. Column "Imputation" indexes
the imputations. Imputation number 0 are the original data.
References
Carpenter J.R., Kenward M.G., (2013), Multiple Imputation and its Application. Chapter 5, Wiley,
ISBN: 978-0-470-74052-1.
Examples
Y.con=sldata[,c("measure","age")]
Y.cat=sldata[,c("social"), drop=FALSE]
Y.numcat=matrix(4,1,1)
X=data.frame(rep(1,300),sldata[,c("sex")])
colnames(X)<-c("const", "sex")
beta.start<-matrix(0,2,5)
l1cov.start<-diag(1,5)
l1cov.prior=diag(1,5);
nburn=as.integer(100);
nbetween=as.integer(100);
nimp=as.integer(5);
imp<-jomo1mix(Y.con,Y.cat,Y.numcat,X,beta.start,l1cov.start,
l1cov.prior,nburn,nbetween,nimp)
# Check help page for function jomo to see how to fit the model and
# combine estimates with Rubin's rules
Description
This function is similar to jomo1mix, but it returns the values of all the parameters in the model
at each step of the MCMC instead of the imputations. It is useful to check the convergence of the
MCMC sampler.
Usage
jomo1mix.MCMCchain(Y.con, Y.cat, Y.numcat, X=NULL, beta.start=NULL,
l1cov.start=NULL, l1cov.prior=NULL, start.imp=NULL, nburn=100,
output=1, out.iter=10)
Arguments
Y.con A data frame, or matrix, with continuous responses of the joint imputation
model. Rows correspond to different observations, while columns are differ-
ent variables. Missing values are coded as NA. If no continuous outcomes are
present in the model, jomo1cat should be used instead.
58 jomo1mix.MCMCchain
Y.cat A data frame, or matrix, with categorical (or binary) responses of the joint im-
putation model. Rows correspond to different observations, while columns are
different variables. Missing values are coded as NA.
Y.numcat A vector with the number of categories in each categorical (or binary) variable.
X A data frame, or matrix, with covariates of the joint imputation model. Rows
correspond to different observations, while columns are different variables. Miss-
ing values are not allowed in these variables. In case we want an intercept, a
column of 1 is needed. The default is a column of 1.
beta.start Starting value for beta, the vector(s) of fixed effects. Rows index different co-
variates and columns index different outcomes. For each n-category variable we
define n-1 latent normals. The default is a matrix of zeros.
l1cov.start Starting value for the covariance matrix. Dimension of this square matrix is
equal to the number of outcomes (continuous plus latent normals) in the impu-
tation model. The default is the identity matrix.
l1cov.prior Scale matrix for the inverse-Wishart prior for the covariance matrix. The default
is the identity matrix.
start.imp Starting value for the imputed dataset. n-level categorical variables are substi-
tuted by n-1 latent normals.
nburn Number of iterations. Default is 100.
output When set to any value different from 1 (default), no output is shown on screen
at the end of the process.
out.iter When set to K, every K iterations a dot is printed on screen. Default is 10.
Value
A list with four elements is returned: the final imputed dataset (finimp) and three 3-dimensional
matrices, containing all the values for beta (collectbeta) and omega (collectomega). Finally, in
finimp.latnorm it is stored the final state of the imputed dataset with the latent normals in place of
the categorical variables.
Examples
Y.con=sldata[,c("measure","age")]
Y.cat=sldata[,c("social"), drop=FALSE]
Y.numcat=matrix(4,1,1)
X=data.frame(rep(1,300),sldata[,c("sex")])
colnames(X)<-c("const", "sex")
beta.start<-matrix(0,2,5)
l1cov.start<-diag(1,5)
l1cov.prior=diag(1,5);
nburn=as.integer(100);
jomo1ran 59
imp<-jomo1mix.MCMCchain(Y.con,Y.cat,Y.numcat,X,beta.start,l1cov.start,l1cov.prior,nburn=nburn)
plot(c(1:nburn),imp$collectbeta[1,1,1:nburn],type="l")
plot(c(1:nburn),imp$collectomega[1,1,1:nburn],type="l")
Description
A wrapper function linking the six 2-level JM Imputation functions. The matrix of responses Y,
must be a data.frame where continuous variables are numeric and binary/categorical variables are
factors.
Usage
jomo1ran(Y, X=NULL, Z=NULL,clus,
beta.start=NULL, u.start=NULL, l1cov.start=NULL, l2cov.start=NULL,
l1cov.prior=NULL, l2cov.prior=NULL, nburn=1000, nbetween=1000, nimp=5,
a=NULL, a.prior=NULL, meth="common", output=1, out.iter=10)
Arguments
Y A data.frame containing the outcomes of the imputation model. Columns re-
lated to continuous variables have to be numeric and columns related to bi-
nary/categorical variables have to be factors.
X A data frame, or matrix, with covariates of the joint imputation model. Rows
correspond to different observations, while columns are different variables. Miss-
ing values are not allowed in these variables. In case we want an intercept, a
column of 1 is needed. The default is a column of 1.
Z A data frame, or matrix, for covariates associated to random effects in the joint
imputation model. Rows correspond to different observations, while columns
are different variables. Missing values are not allowed in these variables. In
case we want an intercept, a column of 1 is needed. The default is a column of
1.
clus A data frame, or matrix, containing the cluster indicator for each observation.
60 jomo1ran
beta.start Starting value for beta, the vector(s) of fixed effects. Rows index different co-
variates and columns index different outcomes. For each n-category variable we
define n-1 latent normals. The default is a matrix of zeros.
u.start A matrix where different rows are the starting values within each cluster for the
random effects estimates u. The default is a matrix of zeros.
l1cov.start Starting value for the covariance matrix. Dimension of this square matrix is
equal to the number of outcomes (continuous plus latent normals) in the impu-
tation model. The default is the identity matrix.
l2cov.start Starting value for the level 2 covariance matrix. Dimension of this square ma-
trix is equal to the number of outcomes (continuous plus latent normals) in the
imputation model times the number of random effects. The default is an identity
matrix.
l1cov.prior Scale matrix for the inverse-Wishart prior for the covariance matrix. The default
is the identity matrix.
l2cov.prior Scale matrix for the inverse-Wishart prior for the level 2 covariance matrix. The
default is the identity matrix.
nburn Number of burn in iterations. Default is 1000.
nbetween Number of iterations between two successive imputations. Default is 1000.
nimp Number of Imputations. Default is 5.
a Starting value for the degrees of freedom of the inverse Wishart distribution
of the cluster-specific covariance matrices. Default is 50+D, with D being the
dimension of the covariance matrices. This is used only when option meth is set
to "random".
a.prior Hyperparameter (Degrees of freedom) of the chi square prior distribution for the
degrees of freedom of the inverse Wishart distribution for the cluster-specific
covariance matrices. Default is the starting value for a.
meth Method used to deal with level 1 covariance matrix. When set to "common",
a common matrix across clusters is used (functions jomo1rancon, jomo1rancat
and jomo1ranmix). When set to "fixed", fixed study-specific matrices are con-
sidered (jomo1ranconhr, jomo1rancathr and jomo1ranmixhr with coption meth="fixed").
Finally, when set to "random", random study-specific matrices are considered
(jomo1ranconhr, jomo1rancathr and jomo1ranmixhr with coption meth="random")
output When set to any value different from 1 (default), no output is shown on screen
at the end of the process.
out.iter When set to K, every K iterations a dot is printed on screen. Default is 10.
Details
This is just a wrapper function to link jomo1rancon, jomo1rancat and jomo1ranmix and the respec-
tive "hr" (heterogeneity in covariance matrices) versions. Format of the columns of Y is crucial in
order for the function to be using the right sub-function.
Value
On screen, the posterior mean of the fixed effects estimates and of the covariance matrix are shown.
The only argument returned is the imputed dataset in long format. Column "Imputation" indexes
the imputations. Imputation number 0 are the original data.
jomo1ran.MCMCchain 61
References
Carpenter J.R., Kenward M.G., (2013), Multiple Imputation and its Application. Chapter 9, Wiley,
ISBN: 978-0-470-74052-1.
Examples
Y<-cldata[,c("measure","age")]
clus<-cldata[,c("city")]
nburn=as.integer(200);
nbetween=as.integer(200);
nimp=as.integer(5);
#we could even run it with fixed or random cluster-specific covariance matrices:
#imp<-jomo1ran(Y,clus=clus,nburn=nburn,nbetween=nbetween,nimp=nimp, meth="fixed")
#or:
#imp<-jomo1ran(Y,clus=clus,nburn=nburn,nbetween=nbetween,nimp=nimp, meth="random")
# Check help page for function jomo to see how to fit the model and
# combine estimates with Rubin's rules
Description
This function is similar to jomo1ran, but it returns the values of all the parameters in the model at
each step of the MCMC instead of the imputations. It is useful to check the convergence of the
MCMC sampler.
Usage
jomo1ran.MCMCchain(Y, X=NULL, Z=NULL,clus, beta.start=NULL, u.start=NULL,
l1cov.start=NULL,l2cov.start=NULL, l1cov.prior=NULL, l2cov.prior=NULL,
start.imp=NULL, nburn=1000, a=NULL,a.prior=NULL, meth="common", output=1,
out.iter=10)
62 jomo1ran.MCMCchain
Arguments
Y A data.frame containing the outcomes of the imputation model. Columns re-
lated to continuous variables have to be numeric and columns related to bi-
nary/categorical variables have to be factors.
X A data frame, or matrix, with covariates of the joint imputation model. Rows
correspond to different observations, while columns are different variables. Miss-
ing values are not allowed in these variables. In case we want an intercept, a
column of 1 is needed. The default is a column of 1.
Z A data frame, or matrix, for covariates associated to random effects in the joint
imputation model. Rows correspond to different observations, while columns
are different variables. Missing values are not allowed in these variables. In
case we want an intercept, a column of 1 is needed. The default is a column of
1.
clus A data frame, or matrix, containing the cluster indicator for each observation.
beta.start Starting value for beta, the vector(s) of fixed effects. Rows index different co-
variates and columns index different outcomes. For each n-category variable we
define n-1 latent normals. The default is a matrix of zeros.
u.start A matrix where different rows are the starting values within each cluster for the
random effects estimates u. The default is a matrix of zeros.
l1cov.start Starting value for the covariance matrix. Dimension of this square matrix is
equal to the number of outcomes (continuous plus latent normals) in the impu-
tation model. The default is the identity matrix.
l2cov.start Starting value for the level 2 covariance matrix. Dimension of this square ma-
trix is equal to the number of outcomes (continuous plus latent normals) in the
imputation model times the number of random effects. The default is an identity
matrix.
l1cov.prior Scale matrix for the inverse-Wishart prior for the covariance matrix. The default
is the identity matrix.
l2cov.prior Scale matrix for the inverse-Wishart prior for the level 2 covariance matrix. The
default is the identity matrix.
start.imp Starting value for the imputed dataset. n-level categorical variables are substi-
tuted by n-1 latent normals.
nburn Number of iterations. Default is 1000.
a Starting value for the degrees of freedom of the inverse Wishart distribution
of the cluster-specific covariance matrices. Default is 50+D, with D being the
dimension of the covariance matrices. This is used only when option meth is set
to "random".
a.prior Hyperparameter (Degrees of freedom) of the chi square prior distribution for the
degrees of freedom of the inverse Wishart distribution for the cluster-specific
covariance matrices. Default is the starting value for a.
meth Method used to deal with level 1 covariance matrix. When set to "common",
a common matrix across clusters is used (functions jomo1rancon, jomo1rancat
and jomo1ranmix). When set to "fixed", fixed study-specific matrices are con-
sidered (jomo1ranconhr, jomo1rancathr and jomo1ranmixhr with coption meth="fixed").
jomo1rancat 63
Value
A list with six elements is returned: the final imputed dataset (finimp) and four 3-dimensional
matrices, containing all the values for beta (collectbeta), the random effects (collectu) and the level
1 (collectomega) and level 2 covariance matrices (collectcovu). Finally, for cases where categorical
variabels are present, the final state of the imputed dataset with the latent normals in place of the
categorical variables is stored in finimp.latnorm.
Examples
Y<-cldata[,c("measure","age")]
clus<-cldata[,c("city")]
nburn=as.integer(200);
plot(c(1:nburn),imp$collectbeta[1,1,1:nburn],type="l")
#Or similarly we can check the convergence of any element of the level 2 covariance matrix:
plot(c(1:nburn),imp$collectcovu[1,2,1:nburn],type="l")
Description
Impute a clustered dataset with categorical variables as outcome. A joint multivariate model for
partially observed data is assumed and imputations are generated through the use of a Gibbs sampler
where the covariance matrix is updated with a Metropolis-Hastings step. Fully observed categorical
covariates may be considered as covariates as well, but they have to be included as dummy variables.
Usage
jomo1rancat( Y.cat, Y.numcat, X=NULL, Z=NULL, clus, beta.start=NULL,
u.start=NULL, l1cov.start=NULL, l2cov.start=NULL, l1cov.prior=NULL,
l2cov.prior=NULL, nburn=1000, nbetween=1000, nimp=5, output=1, out.iter=10)
64 jomo1rancat
Arguments
Y.cat A data frame, or matrix, with categorical (or binary) responses of the joint im-
putation model. Rows correspond to different observations, while columns are
different variables. Missing values are coded as NA.
Y.numcat A vector with the number of categories in each categorical (or binary) variable.
X A data frame, or matrix, with covariates of the joint imputation model. Rows
correspond to different observations, while columns are different variables. Miss-
ing values are not allowed in these variables. In case we want an intercept, a
column of 1 is needed. The default is a column of 1.
Z A data frame, or matrix, for covariates associated to random effects in the joint
imputation model. Rows correspond to different observations, while columns
are different variables. Missing values are not allowed in these variables. In
case we want an intercept, a column of 1 is needed. The default is a column of
1.
clus A data frame, or matrix, containing the cluster indicator for each observation.
beta.start Starting value for beta, the vector(s) of fixed effects. Rows index different co-
variates and columns index different outcomes. For each n-category variable we
define n-1 latent normals. The default is a matrix of zeros.
u.start A matrix where different rows are the starting values within each cluster for the
random effects estimates u. The default is a matrix of zeros.
l1cov.start Starting value for the covariance matrix. Dimension of this square matrix is
equal to the number of outcomes (continuous plus latent normals) in the impu-
tation model. The default is the identity matrix.
l2cov.start Starting value for the level 2 covariance matrix. Dimension of this square ma-
trix is equal to the number of outcomes (continuous plus latent normals) in the
imputation model times the number of random effects. The default is an identity
matrix.
l1cov.prior Scale matrix for the inverse-Wishart prior for the covariance matrix. The default
is the identity matrix.
l2cov.prior Scale matrix for the inverse-Wishart prior for the level 2 covariance matrix. The
default is the identity matrix.
nburn Number of burn in iterations. Default is 1000.
nbetween Number of iterations between two successive imputations. Default is 1000.
nimp Number of Imputations. Default is 5.
output When set to any value different from 1 (default), no output is shown on screen
at the end of the process.
out.iter When set to K, every K iterations a dot is printed on screen. Default is 10.
Details
The Gibbs sampler algorithm used is described in detail in Chapter 9 of Carpenter and Kenward
(2013). Regarding the choice of the priors, a flat prior is considered for beta and for the covariance
matrix. A Metropolis Hastings step is implemented to update the covariance matrix, as described in
the book. Binary or continuous covariates in the imputation model may be considered without any
problem, but when considering a categorical covariate it has to be included with dummy variables
(binary indicators) only.
jomo1rancat.MCMCchain 65
Value
On screen, the posterior mean of the fixed effects estimates and of the covariance matrix are shown.
The only argument returned is the imputed dataset in long format. Column "Imputation" indexes
the imputations. Imputation number 0 are the original data.
References
Carpenter J.R., Kenward M.G., (2013), Multiple Imputation and its Application. Chapter 9, Wiley,
ISBN: 978-0-470-74052-1.
Examples
Y.cat=cldata[,c("social"), drop=FALSE]
Y.numcat=matrix(4,1,1)
X=data.frame(rep(1,1000),cldata[,c("sex")])
colnames(X)<-c("const", "sex")
Z<-data.frame(rep(1,1000))
clus<-cldata[,c("city")]
beta.start<-matrix(0,2,3)
u.start<-matrix(0,10,3)
l1cov.start<-diag(1,3)
l2cov.start<-diag(1,3)
l1cov.prior=diag(1,3);
l2cov.prior=diag(1,3);
nburn=as.integer(100);
nbetween=as.integer(100);
nimp=as.integer(4);
# Check help page for function jomo to see how to fit the model and
# combine estimates with Rubin's rules
Description
This function is similar to jomo1rancat, but it returns the values of all the parameters in the model
at each step of the MCMC instead of the imputations. It is useful to check the convergence of the
MCMC sampler.
Usage
jomo1rancat.MCMCchain(Y.cat, Y.numcat, X=NULL, Z=NULL,clus, beta.start=NULL,
u.start=NULL, l1cov.start=NULL, l2cov.start=NULL, l1cov.prior=NULL,
l2cov.prior=NULL, start.imp=NULL,nburn=1000, output=1, out.iter=10)
Arguments
Y.cat A data frame, or matrix, with categorical (or binary) responses of the joint im-
putation model. Rows correspond to different observations, while columns are
different variables. Missing values are coded as NA.
Y.numcat A vector with the number of categories in each categorical (or binary) variable.
X A data frame, or matrix, with covariates of the joint imputation model. Rows
correspond to different observations, while columns are different variables. Miss-
ing values are not allowed in these variables. In case we want an intercept, a
column of 1 is needed. The default is a column of 1.
Z A data frame, or matrix, for covariates associated to random effects in the joint
imputation model. Rows correspond to different observations, while columns
are different variables. Missing values are not allowed in these variables. In
case we want an intercept, a column of 1 is needed. The default is a column of
1.
clus A data frame, or matrix, containing the cluster indicator for each observation.
beta.start Starting value for beta, the vector(s) of fixed effects. Rows index different co-
variates and columns index different outcomes. For each n-category variable we
define n-1 latent normals. The default is a matrix of zeros.
u.start A matrix where different rows are the starting values within each cluster for the
random effects estimates u. The default is a matrix of zeros.
l1cov.start Starting value for the covariance matrix. Dimension of this square matrix is
equal to the number of outcomes (continuous plus latent normals) in the impu-
tation model. The default is the identity matrix.
l2cov.start Starting value for the level 2 covariance matrix. Dimension of this square ma-
trix is equal to the number of outcomes (continuous plus latent normals) in the
imputation model times the number of random effects. The default is an identity
matrix.
l1cov.prior Scale matrix for the inverse-Wishart prior for the covariance matrix. The default
is the identity matrix.
l2cov.prior Scale matrix for the inverse-Wishart prior for the level 2 covariance matrix. The
default is the identity matrix.
jomo1rancat.MCMCchain 67
start.imp Starting value for the imputed dataset. n-level categorical variables are substi-
tuted by n-1 latent normals.
nburn Number of burn in iterations. Default is 1000.
output When set to any value different from 1 (default), no output is shown on screen
at the end of the process.
out.iter When set to K, every K iterations a dot is printed on screen. Default is 10.
Value
A list with six elements is returned: the final imputed dataset (finimp) and four 3-dimensional
matrices, containing all the values for beta (collectbeta), the random effects (collectu) and the level
1 (collectomega) and level 2 covariance matrices (collectcovu). Finally, the final state of the imputed
dataset with the latent normals in place of the categorical variables is stored in finimp.latnorm.
Examples
Y.cat=cldata[,c("social"), drop=FALSE]
Y.numcat=matrix(4,1,1)
X=data.frame(rep(1,1000),cldata[,c("sex")])
colnames(X)<-c("const", "sex")
Z<-data.frame(rep(1,1000))
clus<-cldata[,c("city")]
beta.start<-matrix(0,2,3)
u.start<-matrix(0,10,3)
l1cov.start<-diag(1,3)
l2cov.start<-diag(1,3)
l1cov.prior=diag(1,3);
l2cov.prior=diag(1,3);
nburn=as.integer(100);
plot(c(1:nburn),imp$collectbeta[1,1,1:nburn],type="l")
#Or similarly we can check the convergence of any element of the level 2 covariance matrix:
plot(c(1:nburn),imp$collectcovu[1,2,1:nburn],type="l")
68 jomo1rancathr
Description
Impute a clustered dataset with categorical variables as outcome. A joint multivariate model for
partially observed data is assumed and imputations are generated through the use of a Gibbs sampler
where a different covariance matrix is sampled within each cluster. Fully observed categorical
covariates may be considered as covariates as well, but they have to be included as dummy variables.
Usage
jomo1rancathr( Y.cat, Y.numcat, X=NULL, Z=NULL, clus, beta.start=NULL,
u.start=NULL, l1cov.start=NULL, l2cov.start=NULL, l1cov.prior=NULL,
l2cov.prior=NULL, nburn=1000, nbetween=1000, nimp=5, a=NULL,
a.prior=NULL, meth="random", output=1, out.iter=10)
Arguments
Y.cat A data frame, or matrix, with categorical (or binary) responses of the joint im-
putation model. Rows correspond to different observations, while columns are
different variables. Missing values are coded as NA.
Y.numcat A vector with the number of categories in each categorical (or binary) variable.
X A data frame, or matrix, with covariates of the joint imputation model. Rows
correspond to different observations, while columns are different variables. Miss-
ing values are not allowed in these variables. In case we want an intercept, a
column of 1 is needed. The default is a column of 1.
Z A data frame, or matrix, for covariates associated to random effects in the joint
imputation model. Rows correspond to different observations, while columns
are different variables. Missing values are not allowed in these variables. In
case we want an intercept, a column of 1 is needed. The default is a column of
1.
clus A data frame, or matrix, containing the cluster indicator for each observation.
beta.start Starting value for beta, the vector(s) of fixed effects. Rows index different co-
variates and columns index different outcomes. For each n-category variable we
define n-1 latent normals. The default is a matrix of zeros.
u.start A matrix where different rows are the starting values within each cluster for the
random effects estimates u. The default is a matrix of zeros.
l1cov.start Starting value for the covariance matrices, stacked one above the other. Dimen-
sion of each square matrix is equal to the number of outcomes (continuous plus
latent normals) in the imputation model. The default is the identity matrix for
each cluster.
jomo1rancathr 69
l2cov.start Starting value for the level 2 covariance matrix. Dimension of this square ma-
trix is equal to the number of outcomes (continuous plus latent normals) in the
imputation model times the number of random effects. The default is an identity
matrix.
l1cov.prior Scale matrix for the inverse-Wishart prior for the covariance matrices. The de-
fault is the identity matrix.
l2cov.prior Scale matrix for the inverse-Wishart prior for the level 2 covariance matrix. The
default is the identity matrix.
nburn Number of burn in iterations. Default is 1000.
nbetween Number of iterations between two successive imputations. Default is 1000.
nimp Number of Imputations. Default is 5.
a Starting value for the degrees of freedom of the inverse Wishart distribution
of the cluster-specific covariance matrices. Default is 50+D, with D being the
dimension of the covariance matrices.
a.prior Hyperparameter (Degrees of freedom) of the chi square prior distribution for the
degrees of freedom of the inverse Wishart distribution for the cluster-specific
covariance matrices. Default is D, with D being the dimension of the covariance
matrices.
meth When set to "fixed", a flat prior is put on the study-specific covariance matrices
and each matrix is updated separately with a different MH-step. When set to
"random", we are assuming that all the covariance matrices are draws from an
inverse-Wishart distribution, whose parameter values are updated with 2 steps
similar to the ones presented in the case of continuous data only for function
jomo1ranconhr.
output When set to any value different from 1 (default), no output is shown on screen
at the end of the process.
out.iter When set to K, every K iterations a dot is printed on screen. Default is 10.
Details
The Gibbs sampler algorithm used is obtained is a mixture of the ones described in chapter 5 and 9 of
Carpenter and Kenward (2013). We update the covariance matrices element-wise with a Metropolis-
Hastings step. When meth="fixed", we use a flat prior for rhe matrices, while with meth="random"
we use an inverse-Wishar tprior and we assume that all the covariance matrices are drawn from an
inverse Wishart distribution. We update values of a and A, degrees of freedom and scale matrix
of the inverse Wishart distribution from which all the covariance matrices are sampled, from the
proper conditional distributions. A flat prior is considered for beta. Binary or continuous covariates
in the imputation model may be considered without any problem, but when considering a categorical
covariate it has to be included with dummy variables (binary indicators) only.
Value
On screen, the posterior mean of the fixed effects estimates and of the covariance matrix are shown.
The only argument returned is the imputed dataset in long format. Column "Imputation" indexes
the imputations. Imputation number 0 are the original data.
70 jomo1rancathr.MCMCchain
References
Carpenter J.R., Kenward M.G., (2013), Multiple Imputation and its Application. Chapter 9, Wiley,
ISBN: 978-0-470-74052-1.
Yucel R.M., (2011), Random-covariances and mixed-effects models for imputing multivariate mul-
tilevel continuous data, Statistical Modelling, 11 (4), 351-370, DOI: 10.1177/1471082X100110040.
Examples
Y.cat=cldata[,c("social"), drop=FALSE]
Y.numcat=matrix(4,1,1)
X=data.frame(rep(1,1000),cldata[,c("sex")])
colnames(X)<-c("const", "sex")
Z<-data.frame(rep(1,1000))
clus<-cldata[,c("city")]
beta.start<-matrix(0,2,3)
u.start<-matrix(0,10,3)
l1cov.start<-matrix(diag(1,3),30,3,2)
l2cov.start<-diag(1,3)
l1cov.prior=diag(1,3);
l2cov.prior=diag(1,3);
a=5
nburn=as.integer(100);
nbetween=as.integer(100);
nimp=as.integer(4);
#Finally we run either the model with fixed or random cluster-specific cov. matrices:
# Check help page for function jomo to see how to fit the model and
# combine estimates with Rubin's rules
jomo1rancathr.MCMCchain
JM Imputation of clustered data with categorical variables with
cluster-specific covariance matrices - A tool to check convergence of
the MCMC
jomo1rancathr.MCMCchain 71
Description
This function is similar to jomo1rancathr, but it returns the values of all the parameters in the model
at each step of the MCMC instead of the imputations. It is useful to check the convergence of the
MCMC sampler.
Usage
jomo1rancathr.MCMCchain(Y.cat, Y.numcat, X=NULL, Z=NULL, clus, beta.start=NULL,
u.start=NULL, l1cov.start=NULL, l2cov.start=NULL, l1cov.prior=NULL,
l2cov.prior=NULL, start.imp=NULL, nburn=1000, a=NULL, a.prior=NULL, meth="random",
output=1, out.iter=10)
Arguments
Y.cat A data frame, or matrix, with categorical (or binary) responses of the joint im-
putation model. Rows correspond to different observations, while columns are
different variables. Missing values are coded as NA.
Y.numcat A vector with the number of categories in each categorical (or binary) variable.
X A data frame, or matrix, with covariates of the joint imputation model. Rows
correspond to different observations, while columns are different variables. Miss-
ing values are not allowed in these variables. In case we want an intercept, a
column of 1 is needed. The default is a column of 1.
Z A data frame, or matrix, for covariates associated to random effects in the joint
imputation model. Rows correspond to different observations, while columns
are different variables. Missing values are not allowed in these variables. In
case we want an intercept, a column of 1 is needed. The default is a column of
1.
clus A data frame, or matrix, containing the cluster indicator for each observation.
beta.start Starting value for beta, the vector(s) of fixed effects. Rows index different co-
variates and columns index different outcomes. For each n-category variable we
define n-1 latent normals. The default is a matrix of zeros.
u.start A matrix where different rows are the starting values within each cluster for the
random effects estimates u. The default is a matrix of zeros.
l1cov.start Starting value for the covariance matrices, stacked one above the other. Dimen-
sion of each square matrix is equal to the number of outcomes (continuous plus
latent normals) in the imputation model. The default is the identity matrix for
each cluster.
l2cov.start Starting value for the level 2 covariance matrix. Dimension of this square ma-
trix is equal to the number of outcomes (continuous plus latent normals) in the
imputation model times the number of random effects. The default is an identity
matrix.
l1cov.prior Scale matrix for the inverse-Wishart prior for the covariance matrices. The de-
fault is the identity matrix.
l2cov.prior Scale matrix for the inverse-Wishart prior for the level 2 covariance matrix. The
default is the identity matrix.
72 jomo1rancathr.MCMCchain
start.imp Starting value for the imputed dataset. n-level categorical variables are substi-
tuted by n-1 latent normals.
nburn Number of burn in iterations. Default is 1000.
a Starting value for the degrees of freedom of the inverse Wishart distribution
of the cluster-specific covariance matrices. Default is 50+D, with D being the
dimension of the covariance matrices.
a.prior Hyperparameter (Degrees of freedom) of the chi square prior distribution for the
degrees of freedom of the inverse Wishart distribution for the cluster-specific
covariance matrices. Default is D, with D being the dimension of the covariance
matrices.
meth When set to "fixed", a flat prior is put on the study-specific covariance matrices
and each matrix is updated separately with a different MH-step. When set to
"random", we are assuming that all the covariance matrices are draws from an
inverse-Wishart distribution, whose parameter values are updated with 2 steps
similar to the ones presented in the case of continuous data only for function
jomo1ranconhr.
output When set to any value different from 1 (default), no output is shown on screen
at the end of the process.
out.iter When set to K, every K iterations a dot is printed on screen. Default is 10.
Value
A list with six elements is returned: the final imputed dataset (finimp) and four 3-dimensional
matrices, containing all the values for beta (collectbeta), the random effects (collectu) and the level
1 (collectomega) and level 2 covariance matrices (collectcovu). Finally, the final state of the imputed
dataset with the latent normals in place of the categorical variables is stored in finimp.latnorm.
Examples
Y.cat=cldata[,c("social"), drop=FALSE]
Y.numcat=matrix(4,1,1)
X=data.frame(rep(1,1000),cldata[,c("sex")])
colnames(X)<-c("const", "sex")
Z<-data.frame(rep(1,1000))
clus<-cldata[,c("city")]
beta.start<-matrix(0,2,3)
u.start<-matrix(0,10,3)
l1cov.start<-matrix(diag(1,3),30,3,2)
l2cov.start<-diag(1,3)
l1cov.prior=diag(1,3);
l2cov.prior=diag(1,3);
a=5
nburn=as.integer(100);
jomo1rancon 73
#Finally we run either the model with fixed or random cluster-specific covariance matrices:
plot(c(1:nburn),imp$collectbeta[1,1,1:nburn],type="l")
#Or similarly we can check the convergence of any element of th elevel 2 covariance matrix:
plot(c(1:nburn),imp$collectcovu[1,2,1:nburn],type="l")
Description
Impute a clustered dataset with continuous outcomes only. A joint multivariate model for partially
observed data is assumed and imputations are generated through the use of a Gibbs sampler. Cate-
gorical covariates may be considered, but they have to be included with dummy variables.
Usage
jomo1rancon(Y, X=NULL, Z=NULL, clus, beta.start=NULL,u.start=NULL,
l1cov.start=NULL,l2cov.start=NULL, l1cov.prior=NULL, l2cov.prior=NULL,
nburn=1000, nbetween=1000, nimp=5, output=1, out.iter=10)
Arguments
Y A data frame, or matrix, with responses of the joint imputation model. Rows cor-
respond to different observations, while columns are different variables. Missing
values are coded as NA.
X A data frame, or matrix, with covariates of the joint imputation model. Rows
correspond to different observations, while columns are different variables. Miss-
ing values are not allowed in these variables. In case we want an intercept, a
column of 1 is needed. The default is a column of 1.
Z A data frame, or matrix, for covariates associated to random effects in the joint
imputation model. Rows correspond to different observations, while columns
are different variables. Missing values are not allowed in these variables. In
case we want an intercept, a column of 1 is needed. The default is a column of
1.
clus A data frame, or matrix, containing the cluster indicator for each observation.
beta.start Starting value for beta, the vector(s) of fixed effects. Rows index different co-
variates and columns index different outcomes. The default is a matrix of zeros.
u.start A matrix where different rows are the starting values within each cluster for the
random effects estimates u. The default is a matrix of zeros.
74 jomo1rancon
l1cov.start Starting value for the covariance matrix. Dimension of this square matrix is
equal to the number of outcomes in the imputation model. The default is the
identity matrix.
l2cov.start Starting value for the level 2 covariance matrix. Dimension of this square matrix
is equal to the number of outcomes in the imputation model times the number
of random effects. The default is an identity matrix.
l1cov.prior Scale matrix for the inverse-Wishart prior for the covariance matrix. The default
is the identity matrix.
l2cov.prior Scale matrix for the inverse-Wishart prior for the level 2 covariance matrix. The
default is the identity matrix.
nburn Number of burn in iterations. Default is 1000.
nbetween Number of iterations between two successive imputations. Default is 1000.
nimp Number of Imputations. Default is 5.
output When set to any value different from 1 (default), no output is shown on screen
at the end of the process.
out.iter When set to K, every K iterations a dot is printed on screen. Default is 10.
Details
The Gibbs sampler algorithm used is a simplification of the one described in detail in Chapter 9 of
Carpenter and Kenward (2013), where we exclude the presence of level 2 variables. Regarding the
choice of the priors, a flat prior is considered for beta, while an inverse-Wishart prior is given to
the covariance matrices, with p-1 degrees of freedom, aka the minimum possible, to guarantee the
greatest uncertainty. Binary or continuous covariates in the imputation model may be considered
without any problem, but when considering a categorical covariate it has to be included with dummy
variables (binary indicators) only.
Value
On screen, the posterior mean of the fixed effects estimates and of the covariance matrix are shown.
The only argument returned is the imputed dataset in long format. Column "Imputation" indexes
the imputations. Imputation number 0 are the original data.
References
Carpenter J.R., Kenward M.G., (2013), Multiple Imputation and its Application. Chapter 9, Wiley,
ISBN: 978-0-470-74052-1.
Examples
beta.start<-matrix(0,2,2)
u.start<-matrix(0,10,2)
l1cov.start<-diag(1,2)
l2cov.start<-diag(1,2)
l1cov.prior=diag(1,2);
nburn=as.integer(200);
nbetween=as.integer(200);
nimp=as.integer(5);
l2cov.prior=diag(1,5);
# Check help page for function jomo to see how to fit the model and
# combine estimates with Rubin's rules
Description
This function is similar to jomo1rancon, but it returns the values of all the parameters in the model
at each step of the MCMC instead of the imputations. It is useful to check the convergence of the
MCMC sampler.
Usage
Arguments
Y A data frame, or matrix, with responses of the joint imputation model. Rows cor-
respond to different observations, while columns are different variables. Missing
values are coded as NA.
X A data frame, or matrix, with covariates of the joint imputation model. Rows
correspond to different observations, while columns are different variables. Miss-
ing values are not allowed in these variables. In case we want an intercept, a
column of 1 is needed. The default is a column of 1.
76 jomo1rancon.MCMCchain
Z A data frame, or matrix, for covariates associated to random effects in the joint
imputation model. Rows correspond to different observations, while columns
are different variables. Missing values are not allowed in these variables. In
case we want an intercept, a column of 1 is needed. The default is a column of
1.
clus A data frame, or matrix, containing the cluster indicator for each observation.
beta.start Starting value for beta, the vector(s) of fixed effects. Rows index different co-
variates and columns index different outcomes. The default is a matrix of zeros.
u.start A matrix where different rows are the starting values within each cluster for the
random effects estimates u. The default is a matrix of zeros.
l1cov.start Starting value for the covariance matrix. Dimension of this square matrix is
equal to the number of outcomes in the imputation model. The default is the
identity matrix.
l2cov.start Starting value for the level 2 covariance matrix. Dimension of this square matrix
is equal to the number of outcomes in the imputation model times the number
of random effects. The default is an identity matrix.
l1cov.prior Scale matrix for the inverse-Wishart prior for the covariance matrix. The default
is the identity matrix.
l2cov.prior Scale matrix for the inverse-Wishart prior for the level 2 covariance matrix. The
default is the identity matrix.
start.imp Starting value for the imputed dataset.
nburn Number of iterations. Default is 1000.
output When set to any value different from 1 (default), no output is shown on screen
at the end of the process.
out.iter When set to K, every K iterations a dot is printed on screen. Default is 10.
Value
A list with five elements is returned: the final imputed dataset (finimp) and four 3-dimensional
matrices, containing all the values for beta (collectbeta), the random effects (collectu) and the level
1 (collectomega) and level 2 covariance matrices (collectcovu).
Examples
# define all the inputs:
Y<-cldata[,c("measure","age")]
clus<-cldata[,c("city")]
X=data.frame(rep(1,1000),cldata[,c("sex")])
colnames(X)<-c("const", "sex")
Z<-data.frame(rep(1,1000))
beta.start<-matrix(0,2,2)
u.start<-matrix(0,10,2)
l1cov.start<-diag(1,2)
l2cov.start<-diag(1,2)
l1cov.prior=diag(1,2);
nburn=as.integer(200);
jomo1ranconhr 77
l2cov.prior=diag(1,5);
plot(c(1:nburn),imp$collectbeta[1,1,1:nburn],type="l")
#Or similarly we can check the convergence of any element of the level 2 covariance matrix:
plot(c(1:nburn),imp$collectcovu[1,1,1:nburn],type="l")
Description
Impute a clustered dataset with continuous outcomes only. A joint multivariate model for partially
observed data is assumed and imputations are generated through the use of a Gibbs sampler. A dif-
ferent covariance matrix is estimated within each cluster. Categorical covariates may be considered,
but they have to be included with dummy variables.
Usage
jomo1ranconhr(Y, X=NULL, Z=NULL, clus, beta.start=NULL, u.start=NULL,
l1cov.start=NULL, l2cov.start=NULL, l1cov.prior=NULL, l2cov.prior=NULL,
nburn=1000, nbetween=1000, nimp=5, a=(ncol(Y)+50),a.prior=NULL,
meth="random", output=1, out.iter=10)
Arguments
Y A data frame, or matrix, with responses of the joint imputation model. Rows cor-
respond to different observations, while columns are different variables. Missing
values are coded as NA.
X A data frame, or matrix, with covariates of the joint imputation model. Rows
correspond to different observations, while columns are different variables. Miss-
ing values are not allowed in these variables. In case we want an intercept, a
column of 1 is needed. The default is a column of 1.
Z A data frame, or matrix, for covariates associated to random effects in the joint
imputation model. Rows correspond to different observations, while columns
are different variables. Missing values are not allowed in these variables. In
case we want an intercept, a column of 1 is needed. The default is a column of
1.
78 jomo1ranconhr
clus A data frame, or matrix, containing the cluster indicator for each observation.
beta.start Starting value for beta, the vector(s) of fixed effects. Rows index different co-
variates and columns index different outcomes. The default is a matrix of zeros.
u.start A matrix where different rows are the starting values within each cluster for the
random effects estimates u. The default is a matrix of zeros.
l1cov.start Starting value for the covariance matrices, stacked one above the other. Dimen-
sion of each square matrix is equal to the number of outcomes in the imputation
model. The default is the identity matrix for each cluster.
l2cov.start Starting value for the level 2 covariance matrix. Dimension of this square matrix
is equal to the number of outcomes in the imputation model times the number
of random effects. The default is an identity matrix.
l1cov.prior Scale matrix for the inverse-Wishart prior for the covariance matrices. The de-
fault is the identity matrix.
l2cov.prior Scale matrix for the inverse-Wishart prior for the level 2 covariance matrix. The
default is the identity matrix.
nburn Number of burn in iterations. Default is 1000.
nbetween Number of iterations between two successive imputations. Default is 1000.
nimp Number of Imputations. Default is 5.
a Starting value for the degrees of freedom of the inverse Wishart distribution
of the cluster-specific covariance matrices. Default is 50+D, with D being the
dimension of the covariance matrices.
a.prior Hyperparameter (Degrees of freedom) of the chi square prior distribution for the
degrees of freedom of the inverse Wishart distribution for the cluster-specific
covariance matrices. Default is D, with D being the dimension of the covariance
matrices.
meth This can be set to "Fixed" or "Random". In the first case the function will
consider fixed study-specific covariance matrices, in the second, random study-
specific distributed according to an inverse-Wishart distribution.
output When set to any value different from 1 (default), no output is shown on screen
at the end of the process.
out.iter When set to K, every K iterations a dot is printed on screen. Default is 10.
Details
The Gibbs sampler algorithm used is similar to the one described in detail in Chapter 9 of Carpenter
and Kenward (2013), where we exclude the presence of level 2 variables and we estimate separetely
different covariance matrices within each study. When option meth="random" is specified, all the
covariance matrices ae assumed to be random draws from the same underlying inverse Wishart dis-
tributions. Details of this algorithm may be found in (Yucel, 2011). Regarding the choice of the
priors, a flat prior is considered for beta, while an inverse-Wishart prior is given to the covariance
matrices, with p-1 degrees of freedom, aka the minimum possible, to guarantee the greatest uncer-
tainty. Binary or continuous covariates in the imputation model may be considered without any
problem, but when considering a categorical covariate it has to be included with dummy variables
(binary indicators) only.
jomo1ranconhr 79
Value
On screen, the posterior mean of the fixed effects estimates and of the covariance matrix are shown.
The only argument returned is the imputed dataset in long format. Column "Imputation" indexes
the imputations. Imputation number 0 are the original data.
References
Carpenter J.R., Kenward M.G., (2013), Multiple Imputation and its Application. Chapter 9, Wiley,
ISBN: 978-0-470-74052-1.
Yucel R.M., (2011), Random-covariances and mixed-effects models for imputing multivariate mul-
tilevel continuous data, Statistical Modelling, 11 (4), 351-370, DOI: 10.1177/1471082X100110040.
Examples
Y<-cldata[,c("measure","age")]
clus<-cldata[,c("city")]
X=data.frame(rep(1,1000),cldata[,c("sex")])
colnames(X)<-c("const", "sex")
Z<-data.frame(rep(1,1000))
beta.start<-matrix(0,2,2)
u.start<-matrix(0,10,2)
l1cov.start<-matrix(diag(1,2),20,2,2)
l2cov.start<-diag(1,2)
l1cov.prior=diag(1,2);
nburn=as.integer(50);
nbetween=as.integer(20);
nimp=as.integer(5);
l2cov.prior=diag(1,5);
a=3
# Finally we run either the model with fixed or random cluster-specific covariance matrices:
imp<-jomo1ranconhr(Y,X,Z,clus,beta.start,u.start,l1cov.start, l2cov.start,
l1cov.prior,l2cov.prior,nburn,nbetween,nimp,meth="fixed")
#or:
#imp<-jomo1ranconhr(Y,X,Z,clus,beta.start,u.start,l1cov.start, l2cov.start,
# l1cov.prior,l2cov.prior,nburn,nbetween,nimp,a,meth="random")
# Check help page for function jomo to see how to fit the model and
# combine estimates with Rubin's rules
80 jomo1ranconhr.MCMCchain
jomo1ranconhr.MCMCchain
JM Imputation of clustered data with continuous variables only with
cluster-specific covariance matrices - A tool to check convergence of
the MCMC
Description
This function is similar to jomo1ranconhr, but it returns the values of all the parameters in the model
at each step of the MCMC instead of the imputations. It is useful to check the convergence of the
MCMC sampler.
Usage
jomo1ranconhr.MCMCchain(Y, X=NULL, Z=NULL, clus,
beta.start=NULL, u.start=NULL, l1cov.start=NULL,
l2cov.start=NULL, l1cov.prior=NULL, l2cov.prior=NULL,start.imp=NULL,
nburn=1000, a=(ncol(Y)+50),a.prior=NULL, meth="random", output=1, out.iter=10)
Arguments
Y A data frame, or matrix, with responses of the joint imputation model. Rows cor-
respond to different observations, while columns are different variables. Missing
values are coded as NA.
X A data frame, or matrix, with covariates of the joint imputation model. Rows
correspond to different observations, while columns are different variables. Miss-
ing values are not allowed in these variables. In case we want an intercept, a
column of 1 is needed. The default is a column of 1.
Z A data frame, or matrix, for covariates associated to random effects in the joint
imputation model. Rows correspond to different observations, while columns
are different variables. Missing values are not allowed in these variables. In
case we want an intercept, a column of 1 is needed. The default is a column of
1.
clus A data frame, or matrix, containing the cluster indicator for each observation.
beta.start Starting value for beta, the vector(s) of fixed effects. Rows index different co-
variates and columns index different outcomes. The default is a matrix of zeros.
u.start A matrix where different rows are the starting values within each cluster for the
random effects estimates u. The default is a matrix of zeros.
l1cov.start in column. Dimension of each square matrix is equal to the number of outcomes
in the imputation model. The default is the identity matrix for each cluster.
jomo1ranconhr.MCMCchain 81
l2cov.start Starting value for the level 2 covariance matrix. Dimension of this square matrix
is equal to the number of outcomes in the imputation model times the number
of random effects. The default is an identity matrix.
l1cov.prior Scale matrix for the inverse-Wishart prior for the covariance matrices. The de-
fault is the identity matrix.
l2cov.prior Scale matrix for the inverse-Wishart prior for the level 2 covariance matrix. The
default is the identity matrix.
start.imp Starting value for the imputed dataset.
nburn Number of iterations. Default is 1000.
a Starting value for the degrees of freedom of the inverse Wishart distribution
of the cluster-specific covariance matrices. Default is 50+D, with D being the
dimension of the covariance matrices.
a.prior Hyperparameter (Degrees of freedom) of the chi square prior distribution for the
degrees of freedom of the inverse Wishart distribution for the cluster-specific
covariance matrices. Default is D, with D being the dimension of the covariance
matrices.
meth This can be set to "Fixed" or "Random". In the first case the function will
consider fixed study-specific covariance matrices, in the second, random study-
specific distributed according to an inverse-Wishart distribution.
output When set to any value different from 1 (default), no output is shown on screen
at the end of the process.
out.iter When set to K, every K iterations a dot is printed on screen. Default is 10.
Value
A list with five elements is returned: the final imputed dataset (finimp) and four 3-dimensional
matrices, containing all the values for beta (collectbeta), the random effects (collectu) and the level
1 (collectomega) and level 2 covariance matrices (collectcovu).
Examples
Y<-cldata[,c("measure","age")]
clus<-cldata[,c("city")]
X=data.frame(rep(1,1000),cldata[,c("sex")])
colnames(X)<-c("const", "sex")
Z<-data.frame(rep(1,1000))
nburn=as.integer(200);
a=3
# Finally we run either the model with fixed or random cluster-specific cov. matrices:
82 jomo1ranmix
imp<-jomo1ranconhr.MCMCchain(Y,X,Z,clus,nburn=nburn,meth="random")
plot(c(1:nburn),imp$collectbeta[1,1,1:nburn],type="l")
#Or similarly we can check the convergence of any element of the level 2 cov. matrix:
plot(c(1:nburn),imp$collectcovu[1,2,1:nburn],type="l")
Description
Impute a clustered dataset with mixed data types as outcome. A joint multivariate model for par-
tially observed data is assumed and imputations are generated through the use of a Gibbs sampler
where the covariance matrix is updated with a Metropolis-Hastings step. Fully observed categor-
ical covariates may be considered as covariates as well, but they have to be included as dummy
variables.
Usage
jomo1ranmix(Y.con, Y.cat, Y.numcat, X=NULL, Z=NULL, clus,
beta.start=NULL, u.start=NULL, l1cov.start=NULL, l2cov.start=NULL,
l1cov.prior=NULL, l2cov.prior=NULL, nburn=1000, nbetween=1000, nimp=5,
output=1, out.iter=10)
Arguments
Y.con A data frame, or matrix, with continuous responses of the joint imputation
model. Rows correspond to different observations, while columns are differ-
ent variables. Missing values are coded as NA.
Y.cat A data frame, or matrix, with categorical (or binary) responses of the joint im-
putation model. Rows correspond to different observations, while columns are
different variables. Categories must be integer numbers from 1 to N. Missing
values are coded as NA.
Y.numcat A vector with the number of categories in each categorical (or binary) variable.
X A data frame, or matrix, with covariates of the joint imputation model. Rows
correspond to different observations, while columns are different variables. Miss-
ing values are not allowed in these variables. In case we want an intercept, a
column of 1 is needed. The default is a column of 1.
Z A data frame, or matrix, for covariates associated to random effects in the joint
imputation model. Rows correspond to different observations, while columns
are different variables. Missing values are not allowed in these variables. In
case we want an intercept, a column of 1 is needed. The default is a column of
1.
jomo1ranmix 83
clus A data frame, or matrix, containing the cluster indicator for each observation.
beta.start Starting value for beta, the vector(s) of fixed effects. Rows index different co-
variates and columns index different outcomes. For each n-category variable we
define n-1 latent normals. The default is a matrix of zeros.
u.start A matrix where different rows are the starting values within each cluster for the
random effects estimates u. The default is a matrix of zeros.
l1cov.start Starting value for the covariance matrix. Dimension of this square matrix is
equal to the number of outcomes (continuous plus latent normals) in the impu-
tation model. The default is the identity matrix.
l2cov.start Starting value for the level 2 covariance matrix. Dimension of this square ma-
trix is equal to the number of outcomes (continuous plus latent normals) in the
imputation model times the number of random effects. The default is an identity
matrix.
l1cov.prior Scale matrix for the inverse-Wishart prior for the covariance matrix. The default
is the identity matrix.
l2cov.prior Scale matrix for the inverse-Wishart prior for the level 2 covariance matrix. The
default is the identity matrix.
nburn Number of burn in iterations. Default is 1000.
nbetween Number of iterations between two successive imputations. Default is 1000.
nimp Number of Imputations. Default is 5.
output When set to any value different from 1 (default), no output is shown on screen
at the end of the process.
out.iter When set to K, every K iterations a dot is printed on screen. Default is 10.
Details
TThe Gibbs sampler algorithm used is described in detail in Chapter 9 of Carpenter and Kenward
(2013). Regarding the choice of the priors, a flat prior is considered for beta and for the covariance
matrix. A Metropolis Hastings step is implemented to update the covariance matrix, as described in
the book. Binary or continuous covariates in the imputation model may be considered without any
problem, but when considering a categorical covariate it has to be included with dummy variables
(binary indicators) only.
Value
On screen, the posterior mean of the fixed effects estimates and of the covariance matrix are shown.
The only argument returned is the imputed dataset in long format. Column "Imputation" indexes
the imputations. Imputation number 0 are the original data.
References
Carpenter J.R., Kenward M.G., (2013), Multiple Imputation and its Application. Chapter 9, Wiley,
ISBN: 978-0-470-74052-1.
84 jomo1ranmix.MCMCchain
Examples
Y.con=cldata[,c("measure","age")]
Y.cat=cldata[,c("social"), drop=FALSE]
Y.numcat=matrix(4,1,1)
X=data.frame(rep(1,1000),cldata[,c("sex")])
colnames(X)<-c("const", "sex")
Z<-data.frame(rep(1,1000))
clus<-cldata[,c("city")]
beta.start<-matrix(0,2,5)
u.start<-matrix(0,10,5)
l1cov.start<-diag(1,5)
l2cov.start<-diag(1,5)
l1cov.prior=diag(1,5);
l2cov.prior=diag(1,5);
nburn=as.integer(50);
nbetween=as.integer(50);
nimp=as.integer(5);
# Check help page for function jomo to see how to fit the model and
# combine estimates with Rubin's rules
Description
This function is similar to jomo1ranmix, but it returns the values of all the parameters in the model
at each step of the MCMC instead of the imputations. It is useful to check the convergence of the
MCMC sampler.
Usage
jomo1ranmix.MCMCchain(Y.con, Y.cat, Y.numcat, X=NULL, Z=NULL, clus,
beta.start=NULL, u.start=NULL, l1cov.start=NULL, l2cov.start=NULL,
jomo1ranmix.MCMCchain 85
Arguments
Y.con A data frame, or matrix, with continuous responses of the joint imputation
model. Rows correspond to different observations, while columns are differ-
ent variables. If no continuous outcomes are present in the model, jomo1rancat
must be used instead.
Y.cat A data frame, or matrix, with categorical (or binary) responses of the joint im-
putation model. Rows correspond to different observations, while columns are
different variables. Categories must be integer numbers from 1 to N. Missing
values are coded as NA.
Y.numcat A vector with the number of categories in each categorical (or binary) variable.
X A data frame, or matrix, with covariates of the joint imputation model. Rows
correspond to different observations, while columns are different variables. Miss-
ing values are not allowed in these variables. In case we want an intercept, a
column of 1 is needed. The default is a column of 1.
Z A data frame, or matrix, for covariates associated to random effects in the joint
imputation model. Rows correspond to different observations, while columns
are different variables. Missing values are not allowed in these variables. In
case we want an intercept, a column of 1 is needed. The default is a column of
1.
clus A data frame, or matrix, containing the cluster indicator for each observation.
beta.start Starting value for beta, the vector(s) of fixed effects. Rows index different co-
variates and columns index different outcomes. For each n-category variable we
define n-1 latent normals. The default is a matrix of zeros.
u.start A matrix where different rows are the starting values within each cluster for the
random effects estimates u. The default is a matrix of zeros.
l1cov.start Starting value for the covariance matrix. Dimension of this square matrix is
equal to the number of outcomes (continuous plus latent normals) in the impu-
tation model. The default is the identity matrix.
l2cov.start Starting value for the level 2 covariance matrix. Dimension of this square ma-
trix is equal to the number of outcomes (continuous plus latent normals) in the
imputation model times the number of random effects. The default is an identity
matrix.
l1cov.prior Scale matrix for the inverse-Wishart prior for the covariance matrix. The default
is the identity matrix.
l2cov.prior Scale matrix for the inverse-Wishart prior for the level 2 covariance matrix. The
default is the identity matrix.
start.imp Starting value for the imputed dataset. n-level categorical variables are substi-
tuted by n-1 latent normals.
nburn Number of burn in iterations. Default is 1000.
86 jomo1ranmix.MCMCchain
output When set to any value different from 1 (default), no output is shown on screen
at the end of the process.
out.iter When set to K, every K iterations a dot is printed on screen. Default is 10.
Value
A list with six elements is returned: the final imputed dataset (finimp) and four 3-dimensional
matrices, containing all the values for beta (collectbeta), the random effects (collectu) and the level
1 (collectomega) and level 2 covariance matrices (collectcovu). Finally, the final state of the imputed
dataset with the latent normals in place of the categorical variables is stored in finimp.latnorm.
Examples
Y.con=cldata[,c("measure","age")]
Y.cat=cldata[,c("social"), drop=FALSE]
Y.numcat=matrix(4,1,1)
X=data.frame(rep(1,1000),cldata[,c("sex")])
colnames(X)<-c("const", "sex")
Z<-data.frame(rep(1,1000))
clus<-cldata[,c("city")]
beta.start<-matrix(0,2,5)
u.start<-matrix(0,10,5)
l1cov.start<-diag(1,5)
l2cov.start<-diag(1,5)
l1cov.prior=diag(1,5);
l2cov.prior=diag(1,5);
nburn=as.integer(100);
plot(c(1:nburn),imp$collectbeta[1,1,1:nburn],type="l")
#Or similarly we can check the convergence of any element of the level 2 covariance matrix:
plot(c(1:nburn),imp$collectcovu[1,2,1:nburn],type="l")
jomo1ranmixhr 87
Description
Impute a clustered dataset with mixed data types as outcome. A joint multivariate model for partially
observed data is assumed and imputations are generated through the use of a Gibbs sampler where
a different covariance matrix is sampled within each cluster. Fully observed categorical covariates
may be considered as covariates as well, but they have to be included as dummy variables.
Usage
jomo1ranmixhr(Y.con, Y.cat, Y.numcat, X=NULL, Z=NULL, clus,
beta.start=NULL, u.start=NULL, l1cov.start=NULL,l2cov.start=NULL,
l1cov.prior=NULL, l2cov.prior=NULL, nburn=1000, nbetween=1000,nimp=5,
a=NULL,a.prior=NULL,meth="random", output=1, out.iter=10)
Arguments
Y.con A data frame, or matrix, with continuous responses of the joint imputation
model. Rows correspond to different observations, while columns are differ-
ent variables. Missing values are coded as NA. If no continuous outcomes are
present in the model, jomo1rancathr must be used instead.
Y.cat A data frame, or matrix, with categorical (or binary) responses of the joint im-
putation model. Rows correspond to different observations, while columns are
different variables. Missing values are coded as NA.
Y.numcat A vector with the number of categories in each categorical (or binary) variable.
X A data frame, or matrix, with covariates of the joint imputation model. Rows
correspond to different observations, while columns are different variables. Miss-
ing values are not allowed in these variables. In case we want an intercept, a
column of 1 is needed. The default is a column of 1.
Z A data frame, or matrix, for covariates associated to random effects in the joint
imputation model. Rows correspond to different observations, while columns
are different variables. Missing values are not allowed in these variables. In
case we want an intercept, a column of 1 is needed. The default is a column of
1.
clus A data frame, or matrix, containing the cluster indicator for each observation.
beta.start Starting value for beta, the vector(s) of fixed effects. Rows index different co-
variates and columns index different outcomes. For each n-category variable we
define n-1 latent normals. The default is a matrix of zeros.
u.start A matrix where different rows are the starting values within each cluster for the
random effects estimates u. The default is a matrix of zeros.
88 jomo1ranmixhr
l1cov.start Starting value for the covariance matrices, stacked one above the other. Dimen-
sion of each square matrix is equal to the number of outcomes (continuous plus
latent normals) in the imputation model. The default is the identity matrix for
each cluster.
l2cov.start Starting value for the level 2 covariance matrix. Dimension of this square ma-
trix is equal to the number of outcomes (continuous plus latent normals) in the
imputation model times the number of random effects. The default is an identity
matrix.
l1cov.prior Scale matrix for the inverse-Wishart prior for the covariance matrices. The de-
fault is the identity matrix.
l2cov.prior Scale matrix for the inverse-Wishart prior for the level 2 covariance matrix. The
default is the identity matrix.
nburn Number of burn in iterations. Default is 1000.
nbetween Number of iterations between two successive imputations. Default is 1000.
nimp Number of Imputations. Default is 5.
a Starting value for the degrees of freedom of the inverse Wishart distribution
of the cluster-specific covariance matrices. Default is 50+D, with D being the
dimension of the covariance matrices.
a.prior Hyperparameter (Degrees of freedom) of the chi square prior distribution for the
degrees of freedom of the inverse Wishart distribution for the cluster-specific
covariance matrices. Default is D, with D being the dimension of the covariance
matrices.
meth When set to "fixed", a flat prior is put on the study-specific covariance matrices
and each matrix is updated separately with a different MH-step. When set to
"random", we are assuming that all the covariance matrices are draws from an
inverse-Wishart distribution, whose parameter values are updated with 2 steps
similar to the ones presented in the case of continuous data only for function
jomo1ranconhr.
output When set to any value different from 1 (default), no output is shown on screen
at the end of the process.
out.iter When set to K, every K iterations a dot is printed on screen. Default is 10.
Details
The Gibbs sampler algorithm used is obtained is a mixture of the ones described in chapter 5 and 9 of
Carpenter and Kenward (2013). We update the covariance matrices element-wise with a Metropolis-
Hastings step. When meth="fixed", we use a flat prior for rhe matrices, while with meth="random"
we use an inverse-Wishar tprior and we assume that all the covariance matrices are drawn from an
inverse Wishart distribution. We update values of a and A, degrees of freedom and scale matrix
of the inverse Wishart distribution from which all the covariance matrices are sampled, from the
proper conditional distributions. A flat prior is considered for beta. Binary or continuous covariates
in the imputation model may be considered without any problem, but when considering a categorical
covariate it has to be included with dummy variables (binary indicators) only.
jomo1ranmixhr 89
Value
On screen, the posterior mean of the fixed effects estimates and of the covariance matrix are shown.
The only argument returned is the imputed dataset in long format. Column "Imputation" indexes
the imputations. Imputation number 0 are the original data.
References
Carpenter J.R., Kenward M.G., (2013), Multiple Imputation and its Application. Chapter 9, Wiley,
ISBN: 978-0-470-74052-1.
Yucel R.M., (2011), Random-covariances and mixed-effects models for imputing multivariate mul-
tilevel continuous data, Statistical Modelling, 11 (4), 351-370, DOI: 10.1177/1471082X100110040.
Examples
Y.con=cldata[,c("measure","age")]
Y.cat=cldata[,c("social"), drop=FALSE]
Y.numcat=matrix(4,1,1)
X=data.frame(rep(1,1000),cldata[,c("sex")])
colnames(X)<-c("const", "sex")
Z<-data.frame(rep(1,1000))
clus<-cldata[,c("city")]
beta.start<-matrix(0,2,5)
u.start<-matrix(0,10,5)
l1cov.start<-matrix(diag(1,5),50,5,2)
l2cov.start<-diag(1,5)
l1cov.prior=diag(1,5);
l2cov.prior=diag(1,5);
nburn=as.integer(50);
nbetween=as.integer(50);
nimp=as.integer(5);
a=6
# Check help page for function jomo to see how to fit the model and
# combine estimates with Rubin's rules
90 jomo1ranmixhr.MCMCchain
jomo1ranmixhr.MCMCchain
JM Imputation of clustered data with mixed variable types with
cluster-specific covariance matrices - A tool to check convergence of
the MCMC
Description
This function is similar to jomo1ranmixhr, but it returns the values of all the parameters in the model
at each step of the MCMC instead of the imputations. It is useful to check the convergence of the
MCMC sampler.
Usage
jomo1ranmixhr.MCMCchain(Y.con, Y.cat, Y.numcat, X=NULL, Z=NULL, clus,
beta.start=NULL, u.start=NULL, l1cov.start=NULL, l2cov.start=NULL,
l1cov.prior=NULL, l2cov.prior=NULL, start.imp=NULL,
nburn=1000, a=NULL,a.prior=NULL,meth="random", output=1, out.iter=10)
Arguments
Y.con A data frame, or matrix, with continuous responses of the joint imputation
model. Rows correspond to different observations, while columns are differ-
ent variables. Missing values are coded as NA. If no continuous outcomes are
present in the model, jomo1rancathr must be used instead.
Y.cat A data frame, or matrix, with categorical (or binary) responses of the joint im-
putation model. Rows correspond to different observations, while columns are
different variables. Missing values are coded as NA.
Y.numcat A vector with the number of categories in each categorical (or binary) variable.
X A data frame, or matrix, with covariates of the joint imputation model. Rows
correspond to different observations, while columns are different variables. Miss-
ing values are not allowed in these variables. In case we want an intercept, a
column of 1 is needed. The default is a column of 1.
Z A data frame, or matrix, for covariates associated to random effects in the joint
imputation model. Rows correspond to different observations, while columns
are different variables. Missing values are not allowed in these variables. In
case we want an intercept, a column of 1 is needed. The default is a column of
1.
clus A data frame, or matrix, containing the cluster indicator for each observation.
beta.start Starting value for beta, the vector(s) of fixed effects. Rows index different co-
variates and columns index different outcomes. For each n-category variable we
define n-1 latent normals. The default is a matrix of zeros.
u.start A matrix where different rows are the starting values within each cluster for the
random effects estimates u. The default is a matrix of zeros.
jomo1ranmixhr.MCMCchain 91
l1cov.start Starting value for the covariance matrices, stacked one above the other. Dimen-
sion of each square matrix is equal to the number of outcomes (continuous plus
latent normals) in the imputation model. The default is the identity matrix for
each cluster.
l2cov.start Starting value for the level 2 covariance matrix. Dimension of this square ma-
trix is equal to the number of outcomes (continuous plus latent normals) in the
imputation model times the number of random effects. The default is an identity
matrix.
l1cov.prior Scale matrix for the inverse-Wishart prior for the covariance matrices. The de-
fault is the identity matrix.
l2cov.prior Scale matrix for the inverse-Wishart prior for the level 2 covariance matrix. The
default is the identity matrix.
start.imp Starting value for the imputed dataset. n-level categorical variables are substi-
tuted by n-1 latent normals.
nburn Number of iterations. Default is 1000.
a Starting value for the degrees of freedom of the inverse Wishart distribution
of the cluster-specific covariance matrices. Default is 50+D, with D being the
dimension of the covariance matrices.
a.prior Hyperparameter (Degrees of freedom) of the chi square prior distribution for the
degrees of freedom of the inverse Wishart distribution for the cluster-specific
covariance matrices. Default is D, with D being the dimension of the covariance
matrices.
meth When set to "fixed", a flat prior is used for the study-specific covariance matrices
and each matrix is updated separately with a different MH-step. When set to
"random", we are assuming that all the covariance matrices are draws from an
inverse-Wishart distribution, whose parameter values are updated with 2 steps
similar to the ones presented in the case of continuous data only for function
jomo1ranconhr.
output When set to any value different from 1 (default), no output is shown on screen
at the end of the process.
out.iter When set to K, every K iterations a dot is printed on screen. Default is 10.
Value
A list with six elements is returned: the final imputed dataset (finimp) and four 3-dimensional
matrices, containing all the values for beta (collectbeta), the random effects (collectu) and the level
1 (collectomega) and level 2 covariance matrices (collectcovu). Finally, the final state of the imputed
dataset with the latent normals in place of the categorical variables is stored in finimp.latnorm.
Examples
Y.con=cldata[,c("measure","age")]
Y.cat=cldata[,c("social"), drop=FALSE]
Y.numcat=matrix(4,1,1)
X=data.frame(rep(1,1000),cldata[,c("sex")])
colnames(X)<-c("const", "sex")
Z<-data.frame(rep(1,1000))
clus<-cldata[,c("city")]
beta.start<-matrix(0,2,5)
u.start<-matrix(0,10,5)
l1cov.start<-matrix(diag(1,5),50,5,2)
l2cov.start<-diag(1,5)
l1cov.prior=diag(1,5);
l2cov.prior=diag(1,5);
nburn=as.integer(80);
a=6
plot(c(1:nburn),imp$collectbeta[1,1,1:nburn],type="l")
#Or similarly we can check the convergence of any element of the level 2 covariance matrix:
plot(c(1:nburn),imp$collectcovu[1,2,1:nburn],type="l")
Description
A wrapper function linking the 2-level JM Imputation functions. The matrices of responses Y and
Y2, must be data.frames where continuous variables are numeric and binary/categorical variables
are factors.
Usage
Arguments
Y A data.frame with the level-1 outcomes of the imputation model, where columns
related to continuous variables are numeric and columns related to binary/categorical
variables are factors.
Y2 A data.frame containing the level-2 outcomes of the imputation model, i.e. the
partially observed level-2 variables. Columns related to continuous variables
have to be numeric and columns related to binary/categorical variables have to
be factors.
X A data frame, or matrix, with covariates of the joint imputation model. Rows
correspond to different observations, while columns are different variables. Miss-
ing values are not allowed in these variables. In case we want an intercept, a
column of 1 is needed. The default is a column of 1.
X2 A data frame, or matrix, with level-2 covariates of the joint imputation model.
Rows correspond to different level-1 observations, while columns are different
variables. Missing values are not allowed in these variables. In case we want an
intercept, a column of 1 is needed. The default is a column of 1.
Z A data frame, or matrix, for covariates associated to random effects in the joint
imputation model. Rows correspond to different observations, while columns
are different variables. Missing values are not allowed in these variables. In
case we want an intercept, a column of 1 is needed. The default is a column of
1.
clus A data frame, or matrix, containing the cluster indicator for each observation.
beta.start Starting value for beta, the vector(s) of level-1 fixed effects. Rows index dif-
ferent covariates and columns index different outcomes. For each n-category
variable we have a fixed effect parameter for each of the n-1 latent normals. The
default is a matrix of zeros.
l2.beta.start Starting value for beta2, the vector(s) of level-2 fixed effects. Rows index dif-
ferent covariates and columns index different level-2 outcomes. For each n-
category variable we have a fixed effect parameter for each of the n-1 latent
normals. The default is a matrix of zeros.
u.start A matrix where different rows are the starting values within each cluster for the
random effects estimates u. The default is a matrix of zeros.
l1cov.start Starting value for the covariance matrix. Dimension of this square matrix is
equal to the number of outcomes (continuous plus latent normals) in the impu-
tation model. The default is the identity matrix.
l2cov.start Starting value for the level 2 covariance matrix. Dimension of this square matrix
is equal to the number of outcomes (continuous plus latent normals) in the im-
putation model times the number of random effects plus the number of level-2
outcomes. The default is an identity matrix.
l1cov.prior Scale matrix for the inverse-Wishart prior for the covariance matrix. The default
is the identity matrix.
l2cov.prior Scale matrix for the inverse-Wishart prior for the level 2 covariance matrix. The
default is the identity matrix.
nburn Number of burn in iterations. Default is 1000.
94 jomo2
Details
This is just a wrapper function to link jomo1rancon, jomo1rancat and jomo1ranmix and the respec-
tive "hr" (heterogeneity in covariance matrices) versions. Format of the columns of Y is crucial in
order for the function to be using the right sub-function.
Value
On screen, the posterior mean of the fixed effects estimates and of the covariance matrix are shown.
The only argument returned is the imputed dataset in long format. Column "Imputation" indexes
the imputations. Imputation number 0 are the original data.
References
Carpenter J.R., Kenward M.G., (2013), Multiple Imputation and its Application. Chapter 9, Wiley,
ISBN: 978-0-470-74052-1.
Examples
Y<-tldata[,c("measure.a"), drop=FALSE]
Y2<-tldata[,c("big.city"), drop=FALSE]
clus<-tldata[,c("city")]
nburn=10
nbetween=10
nimp=2
#now we run the imputation function. Note that we would typically use an higher
#number of nburn iterations in real applications (at least 1000)
jomo2.MCMCchain 95
# Check help page for function jomo to see how to fit the model and
# combine estimates with Rubin's rules
Description
This function is similar to jomo2, but it returns the values of all the parameters in the model at each
step of the MCMC instead of the imputations. It is useful to check the convergence of the MCMC
sampler.
Usage
jomo2.MCMCchain(Y, Y2, X=NULL, X2=NULL, Z=NULL, clus, beta.start=NULL,
l2.beta.start=NULL, u.start=NULL, l1cov.start=NULL,l2cov.start=NULL,
l1cov.prior=NULL, l2cov.prior=NULL, start.imp=NULL, l2.start.imp=NULL,
nburn=1000, a=NULL, a.prior=NULL, meth="common", output=1, out.iter=10)
Arguments
Y A data.frame with level-1 outcomes of the imputation model, where columns re-
lated to continuous variables are numeric and columns related to binary/categorical
variables are factors.
Y2 A data.frame containing the level-2 outcomes of the imputation model. Columns
related to continuous variables have to be numeric and columns related to bi-
nary/categorical variables have to be factors.
X A data frame, or matrix, with covariates of the joint imputation model. Rows
correspond to different observations, while columns are different variables. Miss-
ing values are not allowed in these variables. In case we want an intercept, a
column of 1 is needed. The default is a column of 1.
X2 A data frame, or matrix, with level-2 covariates of the joint imputation model.
Rows correspond to different level-1 observations, while columns are different
variables. Missing values are not allowed in these variables. In case we want an
intercept, a column of 1 is needed. The default is a column of 1.
Z A data frame, or matrix, for covariates associated to random effects in the joint
imputation model. Rows correspond to different observations, while columns
are different variables. Missing values are not allowed in these variables. In
case we want an intercept, a column of 1 is needed. The default is a column of
1.
96 jomo2.MCMCchain
clus A data frame, or matrix, containing the cluster indicator for each observation.
beta.start Starting value for beta, the vector(s) of level-1 fixed effects. Rows index dif-
ferent covariates and columns index different outcomes. For each n-category
variable we have a fixed effect parameter for each of the n-1 latent normals. The
default is a matrix of zeros.
l2.beta.start Starting value for beta2, the vector(s) of level-2 fixed effects. Rows index dif-
ferent covariates and columns index different level-2 outcomes. For each n-
category variable we have a fixed effect parameter for each of the n-1 latent
normals. The default is a matrix of zeros.
u.start A matrix where different rows are the starting values within each cluster for the
random effects estimates u. The default is a matrix of zeros.
l1cov.start Starting value for the covariance matrix. Dimension of this square matrix is
equal to the number of outcomes (continuous plus latent normals) in the impu-
tation model. The default is the identity matrix.
l2cov.start Starting value for the level 2 covariance matrix. Dimension of this square matrix
is equal to the number of outcomes (continuous plus latent normals) in the im-
putation model times the number of random effects plus the number of level-2
outcomes. The default is an identity matrix.
l1cov.prior Scale matrix for the inverse-Wishart prior for the covariance matrix. The default
is the identity matrix.
l2cov.prior Scale matrix for the inverse-Wishart prior for the level 2 covariance matrix. The
default is the identity matrix.
start.imp Starting value for the imputed dataset. n-level categorical variables are substi-
tuted by n-1 latent normals.
l2.start.imp Starting value for the level-2 imputed variables. n-level categorical variables are
substituted by n-1 latent normals.
nburn Number of iterations. Default is 1000.
a Starting value for the degrees of freedom of the inverse Wishart distribution
of the cluster-specific covariance matrices. Default is 50+D, with D being the
dimension of the covariance matrices. This is used only when option meth is set
to "random".
a.prior Hyperparameter (Degrees of freedom) of the chi square prior distribution for the
degrees of freedom of the inverse Wishart distribution for the cluster-specific
covariance matrices. Default is D, with D being the dimension of the covariance
matrices.
meth Method used to deal with level 1 covariance matrix. When set to "common",
a common matrix across clusters is used (function jomo2com). When set to
"fixed", fixed study-specific matrices are considered (jomo2hr with option meth="fixed").
Finally, when set to "random", random study-specific matrices are considered
(jomo2hr with option meth="random")
output When set to any value different from 1 (default), no output is shown on screen
at the end of the process.
out.iter When set to K, every K iterations a dot is printed on screen. Default is 10.
jomo2com 97
Value
A list is returned; this contains the final imputed dataset (finimp) and several 3-dimensional matri-
ces, containing all the values drawn for each parameter at each iteration: these are, potentially, fixed
effect parameters beta (collectbeta), random effects (collectu), level 1 (collectomega) and level 2
covariance matrices (collectcovu) and level-2 fixed effect parameters. If there are some categorical
outcomes, a further output is included in the list, finimp.latnorm, containing the final state of the
imputed dataset with the latent normal variables.
Examples
Y<-tldata[,c("measure.a"), drop=FALSE]
Y2<-tldata[,c("big.city"), drop=FALSE]
clus<-tldata[,c("city")]
nburn=20
#now we run the imputation function. Note that we would typically use an higher
#number of nburn iterations in real applications (at least 100)
plot(c(1:nburn),imp$collectbeta[1,1,1:nburn],type="l")
#Or similarly we can check the convergence of any element of the level 2 covariance matrix:
plot(c(1:nburn),imp$collectcovu[1,2,1:nburn],type="l")
Description
Impute a 2-level dataset with mixed data types as outcome. A joint multivariate model for partially
observed data is assumed and imputations are generated through the use of a Gibbs sampler where
the covariance matrix is updated with a Metropolis-Hastings step. Fully observed categorical co-
variates may be considered as covariates as well, but they have to be included as dummy variables.
Usage
jomo2com(Y.con=NULL, Y.cat=NULL, Y.numcat=NULL, Y2.con=NULL, Y2.cat=NULL,
Y2.numcat=NULL,X=NULL, X2=NULL, Z=NULL, clus, beta.start=NULL, l2.beta.start=NULL,
u.start=NULL, l1cov.start=NULL, l2cov.start=NULL, l1cov.prior=NULL,
l2cov.prior=NULL, nburn=1000, nbetween=1000, nimp=5, output=1, out.iter=10)
98 jomo2com
Arguments
Y.con A data frame, or matrix, with level-1 continuous responses of the joint impu-
tation model. Rows correspond to different observations, while columns are
different variables.
Y.cat A data frame, or matrix, with categorical (or binary) responses of the joint im-
putation model. Rows correspond to different observations, while columns are
different variables. Missing values are coded as NA.
Y.numcat A vector with the number of categories in each categorical (or binary) variable.
Y2.con A data frame, or matrix, with level-2 continuous responses of the joint impu-
tation model. Rows correspond to different observations, while columns are
different variables.
Y2.cat A data frame, or matrix, with level-2 categorical (or binary) responses of the
joint imputation model. Rows correspond to different observations, while columns
are different variables. Missing values are coded as NA.
Y2.numcat A vector with the number of categories in each level-2 categorical (or binary)
variable.
X A data frame, or matrix, with covariates of the joint imputation model. Rows
correspond to different observations, while columns are different variables. Miss-
ing values are not allowed in these variables. In case we want an intercept, a
column of 1 is needed. The default is a column of 1.
X2 A data frame, or matrix, with level-2 covariates of the joint imputation model.
Rows correspond to different observations, while columns are different vari-
ables. Missing values are not allowed in these variables. In case we want an
intercept, a column of 1 is needed. The default is a column of 1.
Z A data frame, or matrix, for covariates associated to random effects in the joint
imputation model. Rows correspond to different observations, while columns
are different variables. Missing values are not allowed in these variables. In
case we want an intercept, a column of 1 is needed. The default is a column of
1.
clus A data frame, or matrix, containing the cluster indicator for each observation.
beta.start Starting value for beta, the vector(s) of level-1 fixed effects. Rows index dif-
ferent covariates and columns index different outcomes. For each n-category
variable we have a fixed effect parameter for each of the n-1 latent normals. The
default is a matrix of zeros.
l2.beta.start Starting value for beta2, the vector(s) of level-2 fixed effects. Rows index dif-
ferent covariates and columns index different level-2 outcomes. For each n-
category variable we have a fixed effect parameter for each of the n-1 latent
normals. The default is a matrix of zeros.
u.start A matrix where different rows are the starting values within each cluster for the
random effects estimates u. The default is a matrix of zeros.
l1cov.start Starting value for the covariance matrix. Dimension of this square matrix is
equal to the number of outcomes (continuous plus latent normals) in the impu-
tation model. The default is the identity matrix.
jomo2com 99
l2cov.start Starting value for the level 2 covariance matrix. Dimension of this square matrix
is equal to the number of outcomes (continuous plus latent normals) in the im-
putation model times the number of random effects plus the number of level-2
outcomes. The default is an identity matrix.
l1cov.prior Scale matrix for the inverse-Wishart prior for the covariance matrix. The default
is the identity matrix.
l2cov.prior Scale matrix for the inverse-Wishart prior for the level 2 covariance matrix. The
default is the identity matrix.
nburn Number of burn in iterations. Default is 1000.
nbetween Number of iterations between two successive imputations. Default is 1000.
nimp Number of Imputations. Default is 5.
output When set to any value different from 1 (default), no output is shown on screen
at the end of the process.
out.iter When set to K, every K iterations a dot is printed on screen. Default is 10.
Details
TThe Gibbs sampler algorithm used is described in detail in Chapter 9 of Carpenter and Kenward
(2013). Regarding the choice of the priors, a flat prior is considered for beta and for the covariance
matrix. A Metropolis Hastings step is implemented to update the covariance matrix, as described in
the book. Binary or continuous covariates in the imputation model may be considered without any
problem, but when considering a categorical covariate it has to be included with dummy variables
(binary indicators) only.
Value
On screen, the posterior mean of the fixed effects estimates and of the covariance matrix are shown.
The only argument returned is the imputed dataset in long format. Column "Imputation" indexes
the imputations. Imputation number 0 are the original data.
References
Carpenter J.R., Kenward M.G., (2013), Multiple Imputation and its Application. Chapter 9, Wiley,
ISBN: 978-0-470-74052-1.
Examples
Y<-tldata[,c("measure.a"), drop=FALSE]
Y2<-tldata[,c("big.city"), drop=FALSE]
clus<-tldata[,c("city")]
#now we run the imputation function. Note that we would typically use an higher
#number of nburn iterations in real applications (at least 1000)
Description
This function is similar to jomo2com, but it returns the values of all the parameters in the model
at each step of the MCMC instead of the imputations. It is useful to check the convergence of the
MCMC sampler.
Usage
jomo2com.MCMCchain(Y.con=NULL, Y.cat=NULL, Y.numcat=NULL, Y2.con=NULL,
Y2.cat=NULL, Y2.numcat=NULL, X=NULL, X2=NULL, Z=NULL, clus, beta.start=NULL,
l2.beta.start=NULL, u.start=NULL, l1cov.start=NULL, l2cov.start=NULL,
l1cov.prior=NULL, l2cov.prior=NULL, start.imp=NULL, l2.start.imp=NULL, nburn=1000,
output=1, out.iter=10)
Arguments
Y.con A data frame, or matrix, with level-1 continuous responses of the joint impu-
tation model. Rows correspond to different observations, while columns are
different variables.
Y.cat A data frame, or matrix, with categorical (or binary) responses of the joint im-
putation model. Rows correspond to different observations, while columns are
different variables. Missing values are coded as NA.
Y.numcat A vector with the number of categories in each categorical (or binary) variable.
Y2.con A data frame, or matrix, with level-2 continuous responses of the joint impu-
tation model. Rows correspond to different observations, while columns are
different variables.
Y2.cat A data frame, or matrix, with level-2 categorical (or binary) responses of the
joint imputation model. Rows correspond to different observations, while columns
are different variables. Missing values are coded as NA.
Y2.numcat A vector with the number of categories in each level-2 categorical (or binary)
variable.
X A data frame, or matrix, with covariates of the joint imputation model. Rows
correspond to different observations, while columns are different variables. Miss-
ing values are not allowed in these variables. In case we want an intercept, a
column of 1 is needed. The default is a column of 1.
X2 A data frame, or matrix, with level-2 covariates of the joint imputation model.
Rows correspond to different observations, while columns are different vari-
ables. Missing values are not allowed in these variables. In case we want an
intercept, a column of 1 is needed. The default is a column of 1.
jomo2com.MCMCchain 101
Z A data frame, or matrix, for covariates associated to random effects in the joint
imputation model. Rows correspond to different observations, while columns
are different variables. Missing values are not allowed in these variables. In
case we want an intercept, a column of 1 is needed. The default is a column of
1.
clus A data frame, or matrix, containing the cluster indicator for each observation.
beta.start Starting value for beta, the vector(s) of level-1 fixed effects. Rows index dif-
ferent covariates and columns index different outcomes. For each n-category
variable we have a fixed effect parameter for each of the n-1 latent normals. The
default is a matrix of zeros.
l2.beta.start Starting value for beta2, the vector(s) of level-2 fixed effects. Rows index dif-
ferent covariates and columns index different level-2 outcomes. For each n-
category variable we have a fixed effect parameter for each of the n-1 latent
normals. The default is a matrix of zeros.
u.start A matrix where different rows are the starting values within each cluster for the
random effects estimates u. The default is a matrix of zeros.
l1cov.start Starting value for the covariance matrix. Dimension of this square matrix is
equal to the number of outcomes (continuous plus latent normals) in the impu-
tation model. The default is the identity matrix.
l2cov.start Starting value for the level 2 covariance matrix. Dimension of this square matrix
is equal to the number of outcomes (continuous plus latent normals) in the im-
putation model times the number of random effects plus the number of level-2
outcomes. The default is an identity matrix.
l1cov.prior Scale matrix for the inverse-Wishart prior for the covariance matrix. The default
is the identity matrix.
l2cov.prior Scale matrix for the inverse-Wishart prior for the level 2 covariance matrix. The
default is the identity matrix.
start.imp Starting value for the imputed dataset. n-level categorical variables are substi-
tuted by n-1 latent normals.
l2.start.imp Starting value for the level-2 imputed variables. n-level categorical variables are
substituted by n-1 latent normals.
nburn Number of burn in iterations. Default is 1000.
output When set to any value different from 1 (default), no output is shown on screen
at the end of the process.
out.iter When set to K, every K iterations a dot is printed on screen. Default is 10.
Value
A list is returned; this contains the final imputed dataset (finimp) and several 3-dimensional matri-
ces, containing all the values drawn for each parameter at each iteration: these are, potentially, fixed
effect parameters beta (collectbeta), random effects (collectu), level 1 (collectomega) and level 2
covariance matrices (collectcovu) and level-2 fixed effect parameters. If there are some categorical
outcomes, a further output is included in the list, finimp.latnorm, containing the final state of the
imputed dataset with the latent normal variables.
102 jomo2hr
Examples
Y<-tldata[,c("measure.a"), drop=FALSE]
Y2<-tldata[,c("big.city"), drop=FALSE]
clus<-tldata[,c("city")]
nburn=20
#now we run the imputation function. Note that we would typically use an higher
#number of nburn iterations in real applications (at least 100)
plot(c(1:nburn),imp$collectbeta[1,1,1:nburn],type="l")
#Or similarly we can check the convergence of any element of the level 2 covariance matrix:
plot(c(1:nburn),imp$collectcovu[1,2,1:nburn],type="l")
Description
Impute a 2-level dataset with mixed data types as outcome. A joint multivariate normal model for
partially observed data, with (either fixed or random) study-specific covariance matrices is assumed
and imputations are generated through the use of a Gibbs sampler where a different covariance
matrix is sampled within each cluster. Fully observed categorical covariates may be considered as
covariates as well, but they have to be included as dummy variables.
Usage
jomo2hr(Y.con=NULL, Y.cat=NULL, Y.numcat=NULL, Y2.con=NULL,
Y2.cat=NULL, Y2.numcat=NULL,X=NULL, X2=NULL, Z=NULL, clus, beta.start=NULL,
l2.beta.start=NULL, u.start=NULL, l1cov.start=NULL, l2cov.start=NULL,
l1cov.prior=NULL, l2cov.prior=NULL, nburn=1000, nbetween=1000, nimp=5,
a=NULL, a.prior=NULL, meth="random", output=1, out.iter=10)
Arguments
Y.con A data frame, or matrix, with level-1 continuous responses of the joint impu-
tation model. Rows correspond to different observations, while columns are
different variables.
Y.cat A data frame, or matrix, with categorical (or binary) responses of the joint im-
putation model. Rows correspond to different observations, while columns are
different variables. Missing values are coded as NA.
jomo2hr 103
Y.numcat A vector with the number of categories in each categorical (or binary) variable.
Y2.con A data frame, or matrix, with level-2 continuous responses of the joint impu-
tation model. Rows correspond to different observations, while columns are
different variables.
Y2.cat A data frame, or matrix, with level-2 categorical (or binary) responses of the
joint imputation model. Rows correspond to different observations, while columns
are different variables. Missing values are coded as NA.
Y2.numcat A vector with the number of categories in each level-2 categorical (or binary)
variable.
X A data frame, or matrix, with covariates of the joint imputation model. Rows
correspond to different observations, while columns are different variables. Miss-
ing values are not allowed in these variables. In case we want an intercept, a
column of 1 is needed. The default is a column of 1.
X2 A data frame, or matrix, with level-2 covariates of the joint imputation model.
Rows correspond to different observations, while columns are different vari-
ables. Missing values are not allowed in these variables. In case we want an
intercept, a column of 1 is needed. The default is a column of 1.
Z A data frame, or matrix, for covariates associated to random effects in the joint
imputation model. Rows correspond to different observations, while columns
are different variables. Missing values are not allowed in these variables. In
case we want an intercept, a column of 1 is needed. The default is a column of
1.
clus A data frame, or matrix, containing the cluster indicator for each observation.
beta.start Starting value for beta, the vector(s) of level-1 fixed effects. Rows index dif-
ferent covariates and columns index different outcomes. For each n-category
variable we have a fixed effect parameter for each of the n-1 latent normals. The
default is a matrix of zeros.
l2.beta.start Starting value for beta2, the vector(s) of level-2 fixed effects. Rows index dif-
ferent covariates and columns index different level-2 outcomes. For each n-
category variable we have a fixed effect parameter for each of the n-1 latent
normals. The default is a matrix of zeros.
u.start A matrix where different rows are the starting values within each cluster for the
random effects estimates u. The default is a matrix of zeros.
l1cov.start Starting value for the covariance matrices, stacked one above the other. Dimen-
sion of each square matrix is equal to the number of outcomes (continuous plus
latent normals) in the imputation model. The default is the identity matrix for
each cluster.
l2cov.start Starting value for the level 2 covariance matrix. Dimension of this square matrix
is equal to the number of outcomes (continuous plus latent normals) in the im-
putation model times the number of random effects plus the number of level-2
outcomes. The default is an identity matrix.
l1cov.prior Scale matrix for the inverse-Wishart prior for the covariance matrices. The de-
fault is the identity matrix.
l2cov.prior Scale matrix for the inverse-Wishart prior for the level 2 covariance matrix. The
default is the identity matrix.
104 jomo2hr
Details
The Gibbs sampler algorithm used is obtained is a mixture of the ones described in chapter 5 and 9 of
Carpenter and Kenward (2013). We update the covariance matrices element-wise with a Metropolis-
Hastings step. When meth="fixed", we use a flat prior for rhe matrices, while with meth="random"
we use an inverse-Wishar tprior and we assume that all the covariance matrices are drawn from an
inverse Wishart distribution. We update values of a and A, degrees of freedom and scale matrix
of the inverse Wishart distribution from which all the covariance matrices are sampled, from the
proper conditional distributions. A flat prior is considered for beta. Binary or continuous covariates
in the imputation model may be considered without any problem, but when considering a categorical
covariate it has to be included with dummy variables (binary indicators) only.
Value
On screen, the posterior mean of the fixed effects estimates and of the covariance matrix are shown.
The only argument returned is the imputed dataset in long format. Column "Imputation" indexes
the imputations. Imputation number 0 are the original data.
References
Carpenter J.R., Kenward M.G., (2013), Multiple Imputation and its Application. Chapter 9, Wiley,
ISBN: 978-0-470-74052-1.
Yucel R.M., (2011), Random-covariances and mixed-effects models for imputing multivariate mul-
tilevel continuous data, Statistical Modelling, 11 (4), 351-370, DOI: 10.1177/1471082X100110040.
jomo2hr.MCMCchain 105
Examples
Y<-tldata[,c("measure.a"), drop=FALSE]
Y2<-tldata[,c("big.city"), drop=FALSE]
clus<-tldata[,c("city")]
#now we run the imputation function. Note that we would typically use an higher
#number of nburn iterations in real applications (at least 1000)
# Check help page for function jomo to see how to fit the model and
# combine estimates with Rubin's rules
Description
This function is similar to jomo2hr, but it returns the values of all the parameters in the model at
each step of the MCMC instead of the imputations. It is useful to check the convergence of the
MCMC sampler.
Usage
jomo2hr.MCMCchain(Y.con=NULL, Y.cat=NULL, Y.numcat=NULL, Y2.con=NULL,
Y2.cat=NULL, Y2.numcat=NULL, X=NULL, X2=NULL, Z=NULL, clus, beta.start=NULL,
l2.beta.start=NULL, u.start=NULL, l1cov.start=NULL, l2cov.start=NULL,
l1cov.prior=NULL, l2cov.prior=NULL, start.imp=NULL, l2.start.imp=NULL,
nburn=1000, a=NULL,a.prior=NULL,meth="random", output=1, out.iter=10)
Arguments
Y.con A data frame, or matrix, with level-1 continuous responses of the joint impu-
tation model. Rows correspond to different observations, while columns are
different variables.
Y.cat A data frame, or matrix, with categorical (or binary) responses of the joint im-
putation model. Rows correspond to different observations, while columns are
different variables. Missing values are coded as NA.
Y.numcat A vector with the number of categories in each categorical (or binary) variable.
Y2.con A data frame, or matrix, with level-2 continuous responses of the joint impu-
tation model. Rows correspond to different observations, while columns are
different variables.
106 jomo2hr.MCMCchain
Y2.cat A data frame, or matrix, with level-2 categorical (or binary) responses of the
joint imputation model. Rows correspond to different observations, while columns
are different variables. Missing values are coded as NA.
Y2.numcat A vector with the number of categories in each level-2 categorical (or binary)
variable.
X A data frame, or matrix, with covariates of the joint imputation model. Rows
correspond to different observations, while columns are different variables. Miss-
ing values are not allowed in these variables. In case we want an intercept, a
column of 1 is needed. The default is a column of 1.
X2 A data frame, or matrix, with level-2 covariates of the joint imputation model.
Rows correspond to different observations, while columns are different vari-
ables. Missing values are not allowed in these variables. In case we want an
intercept, a column of 1 is needed. The default is a column of 1.
Z A data frame, or matrix, for covariates associated to random effects in the joint
imputation model. Rows correspond to different observations, while columns
are different variables. Missing values are not allowed in these variables. In
case we want an intercept, a column of 1 is needed. The default is a column of
1.
clus A data frame, or matrix, containing the cluster indicator for each observation.
beta.start Starting value for beta, the vector(s) of level-1 fixed effects. Rows index dif-
ferent covariates and columns index different outcomes. For each n-category
variable we have a fixed effect parameter for each of the n-1 latent normals. The
default is a matrix of zeros.
l2.beta.start Starting value for beta2, the vector(s) of level-2 fixed effects. Rows index dif-
ferent covariates and columns index different level-2 outcomes. For each n-
category variable we have a fixed effect parameter for each of the n-1 latent
normals. The default is a matrix of zeros.
u.start A matrix where different rows are the starting values within each cluster for the
random effects estimates u. The default is a matrix of zeros.
l1cov.start Starting value for the covariance matrices, stacked one above the other. Dimen-
sion of each square matrix is equal to the number of outcomes (continuous plus
latent normals) in the imputation model. The default is the identity matrix for
each cluster.
l2cov.start Starting value for the level 2 covariance matrix. Dimension of this square matrix
is equal to the number of outcomes (continuous plus latent normals) in the im-
putation model times the number of random effects plus the number of level-2
outcomes. The default is an identity matrix.
l1cov.prior Scale matrix for the inverse-Wishart prior for the covariance matrices. The de-
fault is the identity matrix.
l2cov.prior Scale matrix for the inverse-Wishart prior for the level 2 covariance matrix. The
default is the identity matrix.
start.imp Starting value for the imputed dataset. n-level categorical variables are substi-
tuted by n-1 latent normals.
l2.start.imp Starting value for the level-2 imputed variables. n-level categorical variables are
substituted by n-1 latent normals.
jomo2hr.MCMCchain 107
Value
A list is returned; this contains the final imputed dataset (finimp) and several 3-dimensional matri-
ces, containing all the values drawn for each parameter at each iteration: these are, potentially, fixed
effect parameters beta (collectbeta), random effects (collectu), level 1 (collectomega) and level 2
covariance matrices (collectcovu) and level-2 fixed effect parameters. If there are some categorical
outcomes, a further output is included in the list, finimp.latnorm, containing the final state of the
imputed dataset with the latent normal variables.
Examples
Y<-tldata[,c("measure.a"), drop=FALSE]
Y2<-tldata[,c("big.city"), drop=FALSE]
clus<-tldata[,c("city")]
nburn=20
#now we run the imputation function. Note that we would typically use an higher
#number of nburn iterations in real applications (at least 100)
plot(c(1:nburn),imp$collectbeta[1,1,1:nburn],type="l")
#Or similarly we can check the convergence of any element of the level 2 covariance matrix:
plot(c(1:nburn),imp$collectcovu[1,2,1:nburn],type="l")
108 JSPmiss
Description
A partially observed version of the jspmix1 dataset in package R2MLwiN. This is an educational
dataset of pupils’ test scores, a subset of the Junior School Project (Mortimore et al, 1988).
Usage
data(cldata)
Format
Details
These fully observed verison of the data is available with package R2MLwiN.
Source
Browne, W. J. (2012) MCMC Estimation in MLwiN Version 2.26. University of Bristol: Centre for
Multilevel Modelling.
Mortimore, P., Sammons, P., Stoll, L., Lewis, D., Ecob, R. (1988) School Matters. Wells: Open
Books.
Rasbash, J., Charlton, C., Browne, W.J., Healy, M. and Cameron, B. (2009) MLwiN Version 2.1.
Centre for Multilevel Modelling, University of Bristol.
sldata 109
Description
A simulated dataset to test single level functions, i.e. jomo1con, jomo1cat and jomo1mix.
Usage
data(sldata)
Format
A data frame with 300 observations on the following 4 variables.
age A numeric variable with age. Fully observed.
measure A numeric variable with some measure of interest (unspecified). This is partially ob-
served.
sex A binary variable for gender indicator. Fully observed.
social A 4-category variable with a social status indicator. This is partially observed.
Details
These are not real data, they are simulated to illustrate the use of the main functions of the package.
Description
A simulated dataset to test functions for imputation compatible with cox model.
Usage
data(cldata)
Format
A data frame with 500 observations on the following 5 variables.
measure A numeric variable with some measure of interest (unspecified). This is partially ob-
served.
sex A binary variable with gender indicator. Partially observed.
id The id for individuals within each city.
time Time to event (death or censoring).
status Binary variables, which takes value 0 for censored observations and 1 for deaths/events.
110 tldata
Details
These are not real data, they are simulated to illustrate the use of the main functions of the package.
Description
A simulated dataset to test 2-level functions, i.e. jomo2com and jomo2hr.
Usage
data(tldata)
Format
A data frame with 1000 observations on the following 6 variables.
measure.a A numeric variable with some measure of interest (unspecified). This is partially ob-
served.
measure.b A numeric variable with some measure of interest (unspecified). This is fully observed.
measure.a2 A numeric variable with some level-2 measure of interest (unspecified). This is par-
tially observed.
previous.events A binary variable indicating if a patient has previous history of (unspecified)
events. Patially observed.
group A 3-category variable indicating to which group each patient belongs. This is partially
observed.
big.city A binary variable indicating if each city has more than 100000 inhabitants. Patially
observed.
region A 3-category variable indicating to which region each city belongs. This is fully observed.
city The cluster indicator vector. 200 cities are indexed 0 to 199.
id The id for each individual within each city.
Details
These are not real data, they are simulated to illustrate the use of the main functions of the package.
Index
cldata, 3 jomo1ranmix, 82
jomo1ranmix.MCMCchain, 84
ExamScores, 3 jomo1ranmixhr, 87
jomo1ranmixhr.MCMCchain, 90
jomo, 4 jomo2, 92
jomo.clmm, 7 jomo2.MCMCchain, 95
jomo.clmm.MCMCchain, 10 jomo2com, 97
jomo.coxph, 12 jomo2com.MCMCchain, 100
jomo.coxph.MCMCchain, 14 jomo2hr, 102
jomo.glm, 15 jomo2hr.MCMCchain, 105
jomo.glm.MCMCchain, 17 JSPmiss, 108
jomo.glmer, 19
jomo.glmer.MCMCchain, 21 sldata, 109
jomo.lm, 24 surdata, 109
jomo.lm.MCMCchain, 26
jomo.lmer, 28 tldata, 110
jomo.lmer.MCMCchain, 30
jomo.MCMCchain, 33
jomo.polr, 36
jomo.polr.MCMCchain, 38
jomo.smc, 39
jomo.smc.MCMCchain, 42
jomo1, 45
jomo1.MCMCchain, 47
jomo1cat, 48
jomo1cat.MCMCchain, 50
jomo1con, 52
jomo1con.MCMCchain, 54
jomo1mix, 55
jomo1mix.MCMCchain, 57
jomo1ran, 59
jomo1ran.MCMCchain, 61
jomo1rancat, 63
jomo1rancat.MCMCchain, 65
jomo1rancathr, 68
jomo1rancathr.MCMCchain, 70
jomo1rancon, 73
jomo1rancon.MCMCchain, 75
jomo1ranconhr, 77
jomo1ranconhr.MCMCchain, 80
111