Description Usage Arguments Details Value Author(s) See Also Examples
Fits generalized linear mixed effects models under maximum likelihood using adaptive Gaussian quadrature.
1 2 3 
fixed 
a formula for the fixedeffects part of the model, including the outcome. 
random 
a formula for the randomeffects part of the model. This should only contain
the righthand side part, e.g., 
data 
a data.frame containing the variables required in 
family 
a 
na.action 
what to do with missing values in 
zi_fixed, zi_random 
formulas for the fixed and random effects of the zero inflated part. 
penalized 
logical or a list. If logical and equal to 
n_phis 
a numeric scalar; in case the family corresponds to a distribution that has extra (dispersion/shape) parameters, you need to specify how many extra parameters are needed. 
initial_values 
a list of initial values. This can have up to three components, namely,

control 
a list with the following components:

... 
arguments passed to 
General: The mixed_model()
function fits mixed effects models in which the
integrals over the random effects in the definition of the marginal loglikelihood cannot
be solved analytically and need to be approximated. The function works under the
assumption of normally distributed random effects with mean zero and variancecovariance
matrix D. These integrals are approximated numerically using an adaptive
GaussHermite quadrature rule. Using the control argument nAGQ
, the user can
specify the number of quadrature points used in the approximation.
Userdefined family: The user can define its own family object; for an example,
see the help page of negative.binomial
.
Optimization: A hybrid approach is used, starting with iter_EM
iterations
and unless convergence was achieved it continuous with a direct optimization of the
loglikelihood using function optim
and the algorithm specified by
optim_method
. For stability and speed, the derivative of the loglikelihood with
respect to the parameters are internally programmed.
An object of class "MixMod"
with components:
coefficients 
a numeric vector with the estimated fixed effects. 
phis 
a numeric vector with the estimated extra parameters. 
D 
a numeric matrix denoting the estimated covariance matrix of the random effects. 
post_modes 
a numeric matrix with the empirical Bayes estimates of the random effects. 
post_vars 
a list of numeric matrices with the posterior variances of the random effects. 
logLik 
a numeric scalar denoting the loglikelihood value at the end of the optimization procedure. 
Hessian 
a numeric matrix denoting the Hessian matrix at the end of the optimization procedure. 
converged 
a logical indicating whether convergence was attained. 
id 
a copy of the grouping variable from 
id_name 
a character string with the name of the grouping variable. 
Terms 
a list with two terms components, 
model_frames 
a list with two model.frame components, 
control 
a copy of the (userspecific) 
Funs 
a list of functions used in the optimization procedure. 
family 
a copy of the 
call 
the matched call. 
Dimitris Rizopoulos [email protected]
methods.MixMod
,
effectPlotData
,
marginal_coefs
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92  # simulate some data
set.seed(123L)
n < 500
K < 15
t.max < 25
betas < c(2.13, 0.25, 0.24, 0.05)
D < matrix(0, 2, 2)
D[1:2, 1:2] < c(0.48, 0.08, 0.08, 0.18)
times < c(replicate(n, c(0, sort(runif(K1, 0, t.max)))))
group < sample(rep(0:1, each = n/2))
DF < data.frame(year = times, group = factor(rep(group, each = K)))
X < model.matrix(~ group * year, data = DF)
Z < model.matrix(~ year, data = DF)
b < cbind(rnorm(n, sd = sqrt(D[1, 1])), rnorm(n, sd = sqrt(D[2, 2])))
id < rep(1:n, each = K)
eta.y < as.vector(X %*% betas + rowSums(Z * b[id, ]))
DF$y < rbinom(n * K, 1, plogis(eta.y))
DF$id < factor(id)
################################################
fm1 < mixed_model(fixed = y ~ year * group, random = ~ 1  id, data = DF,
family = binomial())
# fixed effects
fixef(fm1)
# random effects
head(ranef(fm1))
# detailed output
summary(fm1)
# fitted values for the 'mean subject', i.e., with
# random effects values equal to 0
head(fitted(fm1, type = "mean_subject"))
# fitted values for the conditioning on the estimated random effects
head(fitted(fm1, type = "subject_specific"))
##############
fm2 < mixed_model(fixed = y ~ year, random = ~ 1  id, data = DF,
family = binomial())
# likelihood ratio test between the two models
anova(fm2, fm1)
# the same hypothesis but with a Wald test
anova(fm1, L = rbind(c(0, 0, 1, 0), c(0, 0, 0, 1)))
##############
# An effects plot for the mean subject (i.e., with random effects equal to 0)
nDF < with(DF, expand.grid(year = seq(min(year), max(year), length.out = 15),
group = levels(group)))
plot_data < effectPlotData(fm2, nDF)
require("lattice")
xyplot(pred + low + upp ~ year  group, data = plot_data,
type = "l", lty = c(1, 2, 2), col = c(2, 1, 1), lwd = 2,
xlab = "Followup time", ylab = "log odds")
expit < function (x) exp(x) / (1 + exp(x))
xyplot(expit(pred) + expit(low) + expit(upp) ~ year  group, data = plot_data,
type = "l", lty = c(1, 2, 2), col = c(2, 1, 1), lwd = 2,
xlab = "Followup time", ylab = "Probabilities")
# An effects plots for the marginal probabilities
plot_data_m < effectPlotData(fm2, nDF, marginal = TRUE)
expit < function (x) exp(x) / (1 + exp(x))
xyplot(expit(pred) + expit(low) + expit(upp) ~ year  group, data = plot_data_m,
type = "l", lty = c(1, 2, 2), col = c(2, 1, 1), lwd = 2,
xlab = "Followup time", ylab = "Probabilities")
##############
# include random slopes
fm1_slp < update(fm1, random = ~ year  id)
# increase the number of quadrature points to 15
fm1_slp_q15 < update(fm1_slp, nAGQ = 15)
# a diagonal covariance matrix for the random effects
fm1_slp_diag < update(fm1, random = ~ year  id)
anova(fm1_slp_diag, fm1_slp)

Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.