Description Usage Arguments Details Value Author(s) See Also Examples
Methods for object of class "MixMod"
for standard generic functions.
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  coef(object, ...)
## S3 method for class 'MixMod'
coef(object, sub_model = c("main", "zero_part"),
...)
fixef(object, ...)
## S3 method for class 'MixMod'
fixef(object, sub_model = c("main", "zero_part"), ...)
ranef(object, ...)
## S3 method for class 'MixMod'
ranef(object, post_vars = FALSE, ...)
confint(object, parm, level = 0.95, ...)
## S3 method for class 'MixMod'
confint(object,
parm = c("fixedeffects", "varcov","extra", "zero_part"),
level = 0.95, sandwich = FALSE, ...)
anova(object, ...)
## S3 method for class 'MixMod'
anova(object, object2, test = TRUE,
L = NULL, sandwich = FALSE, ...)
fitted(object, ...)
## S3 method for class 'MixMod'
fitted(object,
type = c("mean_subject", "subject_specific", "marginal"),
link_fun = NULL, ...)
residuals(object, ...)
## S3 method for class 'MixMod'
residuals(object,
type = c("mean_subject", "subject_specific", "marginal"),
link_fun = NULL, tasnf_y = function (x) x, ...)
predict(object, ...)
## S3 method for class 'MixMod'
predict(object, newdata, newdata2 = NULL,
type_pred = c("response", "link"),
type = c("mean_subject", "subject_specific", "marginal", "zero_part"),
se.fit = FALSE, M = 300, df = 10, scale = 0.3, level = 0.95,
seed = 1, return_newdata = FALSE, sandwich = FALSE, ...)
simulate(object, nsim = 1, seed = NULL, ...)
## S3 method for class 'MixMod'
simulate(object, nsim = 1, seed = NULL,
type = c("subject_specific", "mean_subject"),
acount_MLEs_var = FALSE, sim_fun = NULL,
sandwich = FALSE, ...)
terms(x, ...)
## S3 method for class 'MixMod'
terms(x, type = c("fixed", "random", "zi_fixed", "zi_random"), ...)
formula(x, ...)
## S3 method for class 'MixMod'
formula(x, type = c("fixed", "random", "zi_fixed", "zi_random"), ...)
model.frame(formula, ...)
## S3 method for class 'MixMod'
model.frame(formula, type = c("fixed", "random", "zi_fixed", "zi_random"), ...)
model.matrix(object, ...)
## S3 method for class 'MixMod'
model.matrix(object, type = c("fixed", "random", "zi_fixed", "zi_random"), ...)
nobs(object, ...)
## S3 method for class 'MixMod'
nobs(object, level = 1, ...)

object, object2, x, formula 
objects inheriting from class 
sub_model 
character string indicating for which submodel to extract the estimated coefficients; it is only relevant for zeroinflated models. 
post_vars 
logical; if 
parm 
character string; for which type of parameters to calculate confidence
intervals. Option 
level 
numeric scalar between 0 and 1 denoting the level of the confidence interval.
In the 
test 
logical; should a pvalue be calculated. 
L 
a numeric matrix representing a contrasts matrix. This is only used when in

sandwich 
logical; if 
type 
character string indicating the type of fitted values / residuals / predictions
to calculate. Option 
link_fun 
the 
tasnf_y 
a function to transform the grouped / repeated measurements outcome before calculating the residuals; for example, relevant in twopart models for semicontinuous data, in which it is assumed that the log outcome follows a normal distribution. 
newdata, newdata2 
a data frame based on which predictions are to be calculated.

type_pred 
character string indicating at which scale to calculate predictions.
Options are 
se.fit 
logical, if 
M 
numeric scalar denoting the number of Monte Carlo samples; see Details for more information. 
df 
numeric scalar denoting the degrees of freedom for the Student's t proposal distribution; see Details for more information. 
scale 
numeric scalar or vector denoting the scaling applied to the subjectspecific covariance matrices of the random effects; see Details for more information. 
seed 
numerical scalar giving the seed to be used in the Monte Carlo scheme. 
return_newdata 
logical; if 
nsim 
numeric scalar giving the number of times to simulate the response variable. 
acount_MLEs_var 
logical; if 
sim_fun 
a function based on which to simulate the response variable. This is
relevant for nonstandard models. The 
... 
further arguments; currently none is used. 
In generic terms, we assume that the mean of the outcome y_i (i = 1, ..., n denotes the subjects) conditional on the random effects is given by the equation:
g{E(y_i  b_i)} = η_i = X_i β + Z_i b_i,
where g(.) denotes the link function, b_i the vector of random effects, β the vector of fixed effects, and X_i and Z_i the design matrices for the fixed and random effects, respectively.
Argument type_pred
of predict()
specifies whether predictions will be
calculated in the link / linear predictor scale, i.e., η_i or in the response
scale, i.e., g{E(y_i  b_i)}.
When type = "mean_subject"
, predictions are calculated using only the fixed
effects, i.e., the X_i β part, where X_i is evaluated in newdata
.
This corresponds to predictions for the 'mean' subjects, i.e., subjects who have
random effects value equal to 0. Note, that in the case of nonlinear link functions this
does not correspond to the averaged over the population predictions (i.e., marginal
predictions).
When type = "marginal"
, predictions are calculated using only the fixed
effects, i.e., the X_i β part, where X_i is evaluated in newdata
,
but with β coefficients the marginalized coefficients obtain from
marginal_coefs
. These predictions will be marginal / population averaged
predictions.
When type = "zero_part"
, predictions are calculated for the logistic regression of
the extra zeropart of the model (i.e., applicable for zeroinflated and hurdle models).
When type = "subject_specific"
, predictions are calculated using both the fixed
and randomeffects parts, i.e., X_i β + Z_i b_i, where X_i and Z_i
are evaluated in newdata
. Estimates for the random effects of each subject are
obtained as modes from the posterior distribution [b_i  y_i; θ] evaluated in
newdata
and with theta (denoting the parameters of the model, fixed effects
and variance components) replaced by their maximum likelihood estimates.
Notes: (i) When se.fit = TRUE
and type_pred = "response"
, the
standard errors returned are on the linear predictor scale, not the response scale.
(ii) When se.fit = TRUE
and the model contains an extra zeropart, no standard
errors are computed when type = "mean_subject"
. (iii) When the model contains an
extra zeropart, type = "marginal"
predictions are not yet implemented.
When se.fit = TRUE
and type = "subject_specific"
, standard errors and
confidence intervals for the subjectspecific predictions are obtained by a Monte Carlo
scheme entailing three steps repeated M
times, namely
Account for the variability of maximum likelihood estimates (MLES) by simulating a new value θ^* for the parameters θ from a multivariate normal distribution with mean the MLEs and covariance matrix the covariance matrix of the MLEs.
Account for the variability in the random effects estimates by
simulating a new value b_i^* for the random effects b_i from the posterior
distribution [b_i  y_i; θ^*]. Because the posterior distribution does not
have a closedform, a MetropolisHastings algorithm is used to sample the new value
b_i^* using as proposal distribution a multivariate Student'st distribution
with degrees of freedom df
, centered at the mode of the posterior distribution
[b_i  y_i; θ] with θ the MLEs, and scale matrix the inverse
Hessian matrix of the log density of [b_i  y_i; θ] evaluated at the modes,
but multiplied by scale
. The scale
and df
parameters can be used
to adjust the acceptance rate.
The predictions are calculated using X_i β^* + Z_i b_i^*.
Argument newdata2
can be used to calculate dynamic subjectspecific predictions.
I.e., using the observed responses y_i in newdata
, estimates of the random
effects of each subject are obtained. For the same subjects we want to obtain predictions
in new covariates settings for which no response data are yet available. For example,
in a longitudinal study, for a subject we have responses up to a followup t
(newdata
) and we want the prediction at t + Δ t (newdata2
).
The estimated fixed and random effects, coefficients (this is similar as in package nlme), confidence intervals fitted values (on the scale on the response) and residuals.
Dimitris Rizopoulos [email protected]
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  # 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 = ~ year  id, data = DF,
family = binomial())
head(coef(fm1))
fixef(fm1)
head(ranef(fm1))
confint(fm1)
confint(fm1, "varcov")
head(fitted(fm1, "subject_specific"))
head(residuals(fm1, "marginal"))
fm2 < mixed_model(fixed = y ~ year * group, random = ~ year  id, data = DF,
family = binomial())
# likelihood ratio test between fm1 and fm2
anova(fm1, fm2)
# the same but with a Wald test
anova(fm2, L = rbind(c(0, 0, 0, 1)))

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