Title: | Transformation Models with Mixed Effects |
---|---|
Description: | Likelihood-based estimation of mixed-effects transformation models using the Template Model Builder ('TMB', Kristensen et al., 2016) <doi:10.18637/jss.v070.i05>. The technical details of transformation models are given in Hothorn et al. (2018) <doi:10.1111/sjos.12291>. Likelihood contributions of exact, randomly censored (left, right, interval) and truncated observations are supported. The random effects are assumed to be normally distributed on the scale of the transformation function, the marginal likelihood is evaluated using the Laplace approximation, and the gradients are calculated with automatic differentiation (Tamasi & Hothorn, 2021) <doi:10.32614/RJ-2021-075>. Penalized smooth shift terms can be defined using 'mgcv'. |
Authors: | Balint Tamasi [aut, cre] , Torsten Hothorn [ctb] |
Maintainer: | Balint Tamasi <[email protected]> |
License: | GPL-2 |
Version: | 1.0.4 |
Built: | 2024-11-18 20:26:26 UTC |
Source: | https://github.com/r-forge/ctm |
Calculates information criteria and LR ratio test for nested tramME models. The calculation of the degrees of freedom is problematic, because the parameter space is restricted.
## S3 method for class 'tramME' anova(object, object2, ...)
## S3 method for class 'tramME' anova(object, object2, ...)
object |
A |
object2 |
A |
... |
Optional arguments, for compatibility with the generic. (Ignored) |
Currently only supports the comparison of two models. Additional arguments will be ignored.
The nestedness of the models is not checked.
A data.frame
with the calculated statistics.
data("sleepstudy", package = "lme4") mod1 <- LmME(Reaction ~ Days + (Days | Subject), data = sleepstudy) mod2 <- LmME(Reaction ~ Days + (Days || Subject), data = sleepstudy) anova(mod1, mod2)
data("sleepstudy", package = "lme4") mod1 <- LmME(Reaction ~ Days + (Days | Subject), data = sleepstudy) mod2 <- LmME(Reaction ~ Days + (Days || Subject), data = sleepstudy) anova(mod1, mod2)
BoxCox
Mixed-effects version of BoxCox
BoxCoxME( formula, data, subset, weights, offset, na.action = na.omit, silent = TRUE, resid = FALSE, do_update = FALSE, estinit = TRUE, initpar = NULL, fixed = NULL, nofit = FALSE, control = optim_control(), ... )
BoxCoxME( formula, data, subset, weights, offset, na.action = na.omit, silent = TRUE, resid = FALSE, do_update = FALSE, estinit = TRUE, initpar = NULL, fixed = NULL, nofit = FALSE, control = optim_control(), ... )
formula |
an object of class |
data |
an optional data frame, list or environment (or object
coercible by |
subset |
an optional vector specifying a subset of observations to be used in the fitting process. |
weights |
an optional vector of weights to be used in the fitting
process. Should be |
offset |
this can be used to specify an _a priori_ known component to
be included in the linear predictor during fitting. This
should be |
na.action |
a function which indicates what should happen when the data
contain |
silent |
Logical. Make TMB functionality silent. |
resid |
Logical. If |
do_update |
Logical. If |
estinit |
logical, estimate a vector of initial values for the fixed effects parameters from a (fixed effects only) mlt model |
initpar |
named list of initial parameter values, if |
fixed |
a named vector of fixed regression coefficients; the names need to correspond to column names of the design matrix |
nofit |
logical, if TRUE, creates the model object, but does not run the optimization |
control |
list with controls for optimization |
... |
additional arguments to |
A BoxCoxME object.
Extract the coefficients of the fixed effects terms of an LmME model.
## S3 method for class 'LmME' coef(object, as.lm = FALSE, fixed = TRUE, ...)
## S3 method for class 'LmME' coef(object, as.lm = FALSE, fixed = TRUE, ...)
object |
An |
as.lm |
If |
fixed |
If |
... |
Optional arguments passed to |
A numeric vector of the transformed coefficients.
data("sleepstudy", package = "lme4") fit <- LmME(Reaction ~ Days + (Days | Subject), data = sleepstudy) coef(fit, as.lm = TRUE)
data("sleepstudy", package = "lme4") fit <- LmME(Reaction ~ Days + (Days | Subject), data = sleepstudy) coef(fit, as.lm = TRUE)
Extract the coefficients of the fixed effects terms of an SurvregME model.
## S3 method for class 'SurvregME' coef(object, as.survreg = FALSE, ...)
## S3 method for class 'SurvregME' coef(object, as.survreg = FALSE, ...)
object |
An |
as.survreg |
If |
... |
Optional arguments passed to |
A numeric vector of the transformed coefficients.
library("survival") fit <- SurvregME(Surv(time, status) ~ rx + (1 | litter), data = rats) coef(fit, as.survreg = TRUE)
library("survival") fit <- SurvregME(Surv(time, status) ~ rx + (1 | litter), data = rats) coef(fit, as.survreg = TRUE)
Extract the coefficients of the fixed effects terms.
## S3 method for class 'tramME' coef(object, with_baseline = FALSE, fixed = TRUE, ...)
## S3 method for class 'tramME' coef(object, with_baseline = FALSE, fixed = TRUE, ...)
object |
A |
with_baseline |
If |
fixed |
If |
... |
Optional parameters (ignored). |
Numeric vector of parameter values.
library("survival") mod <- SurvregME(Surv(time, status) ~ rx + (1 | litter/rx), data = rats, dist = "exponential", nofit = TRUE) coef(mod, with_baseline = TRUE) coef(mod, with_baseline = TRUE, fixed = FALSE)
library("survival") mod <- SurvregME(Surv(time, status) ~ rx + (1 | litter/rx), data = rats, dist = "exponential", nofit = TRUE) coef(mod, with_baseline = TRUE) coef(mod, with_baseline = TRUE, fixed = FALSE)
Sets the whole vector of fixed-effects coefficients of a tramME model. The parameters of the baseline transformation function should respect the restrictions of the parameter space. This is checked before setting the new parameter values provided that the parameters for the variance components has already been set. If the model contains fixed coefficient parameters, the input should also respect that. When called on a fitted tram object, the function sets it to unfitted and removes all parts that come from the estimation.
## S3 replacement method for class 'tramME' coef(object) <- value
## S3 replacement method for class 'tramME' coef(object) <- value
object |
A |
value |
Numeric vector of new coefficient values. |
A tramME
object with the new coefficient values.
data("sleepstudy", package = "lme4") mod <- LmME(Reaction ~ Days + (Days | Subject), data = sleepstudy, nofit = TRUE) coef(mod) <- c(-1, 0.5, 1)
data("sleepstudy", package = "lme4") mod <- LmME(Reaction ~ Days + (Days | Subject), data = sleepstudy, nofit = TRUE) coef(mod) <- c(-1, 0.5, 1)
Colr
Mixed-effects version of Colr
ColrME( formula, data, subset, weights, offset, na.action = na.omit, silent = TRUE, resid = FALSE, do_update = FALSE, estinit = TRUE, initpar = NULL, fixed = NULL, nofit = FALSE, control = optim_control(), ... )
ColrME( formula, data, subset, weights, offset, na.action = na.omit, silent = TRUE, resid = FALSE, do_update = FALSE, estinit = TRUE, initpar = NULL, fixed = NULL, nofit = FALSE, control = optim_control(), ... )
formula |
an object of class |
data |
an optional data frame, list or environment (or object
coercible by |
subset |
an optional vector specifying a subset of observations to be used in the fitting process. |
weights |
an optional vector of weights to be used in the fitting
process. Should be |
offset |
this can be used to specify an _a priori_ known component to
be included in the linear predictor during fitting. This
should be |
na.action |
a function which indicates what should happen when the data
contain |
silent |
Logical. Make TMB functionality silent. |
resid |
Logical. If |
do_update |
Logical. If |
estinit |
logical, estimate a vector of initial values for the fixed effects parameters from a (fixed effects only) mlt model |
initpar |
named list of initial parameter values, if |
fixed |
a named vector of fixed regression coefficients; the names need to correspond to column names of the design matrix |
nofit |
logical, if TRUE, creates the model object, but does not run the optimization |
control |
list with controls for optimization |
... |
additional arguments to |
A ColrME object.
Confidence intervals for model parameters on their original scale,
optionally consistent with the linear mixed-model specification.
When as.lm = TRUE
, only Wald CIs are available.
## S3 method for class 'LmME' confint( object, parm = NULL, level = 0.95, as.lm = FALSE, pargroup = c("all", "fixef", "ranef"), type = c("Wald", "wald", "profile"), estimate = FALSE, ... )
## S3 method for class 'LmME' confint( object, parm = NULL, level = 0.95, as.lm = FALSE, pargroup = c("all", "fixef", "ranef"), type = c("Wald", "wald", "profile"), estimate = FALSE, ... )
object |
An |
parm |
Names of the parameters to extract. |
level |
Confidence level. |
as.lm |
Logical. If |
pargroup |
The name of the parameter group to extract. With
|
type |
Type of the CI: either Wald or profile. |
estimate |
Logical, add the point estimates in a thrid column. |
... |
Optional parameters passed to |
A matrix with lower and upper bounds.
data("sleepstudy", package = "lme4") fit <- LmME(Reaction ~ Days + (Days | Subject), data = sleepstudy) confint(fit) ## transformation model parametrization confint(fit, as.lm = TRUE) ## LMM parametrization confint(fit, as.lm = TRUE, pargroup = "fixef", estimate = TRUE) confint(fit, as.lm = TRUE, parm = "(Sigma)") ## error SD
data("sleepstudy", package = "lme4") fit <- LmME(Reaction ~ Days + (Days | Subject), data = sleepstudy) confint(fit) ## transformation model parametrization confint(fit, as.lm = TRUE) ## LMM parametrization confint(fit, as.lm = TRUE, pargroup = "fixef", estimate = TRUE) confint(fit, as.lm = TRUE, parm = "(Sigma)") ## error SD
Confidence intervals for model parameters on their original scale. Either Wald CI or profile CI by root finding. Multicore computations are supported in the case of profile confidence intervals, but snow support is yet to be implemented.
## S3 method for class 'tramME' confint( object, parm = NULL, level = 0.95, pargroup = c("all", "fixef", "shift", "baseline", "ranef", "smooth"), type = c("Wald", "wald", "profile"), estimate = FALSE, pmatch = FALSE, parallel = c("no", "multicore", "snow"), ncpus = getOption("profile.ncpus", 1L), ... )
## S3 method for class 'tramME' confint( object, parm = NULL, level = 0.95, pargroup = c("all", "fixef", "shift", "baseline", "ranef", "smooth"), type = c("Wald", "wald", "profile"), estimate = FALSE, pmatch = FALSE, parallel = c("no", "multicore", "snow"), ncpus = getOption("profile.ncpus", 1L), ... )
object |
A |
parm |
The indeces or names of the parameters of interest. See in details. |
level |
Confidence level. |
pargroup |
The name of the parameter group to return:
|
type |
Type of the CI: either Wald or profile. |
estimate |
Logical, add the point estimates in a thrid column. |
pmatch |
Logical. If |
parallel |
Method for parallel computation. |
ncpus |
Number of cores to use for parallel computation. |
... |
Optional parameters. |
A matrix with lower and upper bounds.
data("sleepstudy", package = "lme4") fit <- BoxCoxME(Reaction ~ Days + (Days | Subject), data = sleepstudy) confint(fit) confint(fit, pargroup = "shift", estimate = TRUE) exp(confint(fit, 1:2, pargroup = "ranef")) ## CIs for the SDs of the REs
data("sleepstudy", package = "lme4") fit <- BoxCoxME(Reaction ~ Days + (Days | Subject), data = sleepstudy) confint(fit) confint(fit, pargroup = "shift", estimate = TRUE) exp(confint(fit, 1:2, pargroup = "ranef")) ## CIs for the SDs of the REs
Coxph
Mixed-effects version of Coxph
CoxphME( formula, data, subset, weights, offset, na.action = na.omit, silent = TRUE, resid = FALSE, do_update = FALSE, estinit = TRUE, initpar = NULL, fixed = NULL, nofit = FALSE, control = optim_control(), ... )
CoxphME( formula, data, subset, weights, offset, na.action = na.omit, silent = TRUE, resid = FALSE, do_update = FALSE, estinit = TRUE, initpar = NULL, fixed = NULL, nofit = FALSE, control = optim_control(), ... )
formula |
an object of class |
data |
an optional data frame, list or environment (or object
coercible by |
subset |
an optional vector specifying a subset of observations to be used in the fitting process. |
weights |
an optional vector of weights to be used in the fitting
process. Should be |
offset |
this can be used to specify an _a priori_ known component to
be included in the linear predictor during fitting. This
should be |
na.action |
a function which indicates what should happen when the data
contain |
silent |
Logical. Make TMB functionality silent. |
resid |
Logical. If |
do_update |
Logical. If |
estinit |
logical, estimate a vector of initial values for the fixed effects parameters from a (fixed effects only) mlt model |
initpar |
named list of initial parameter values, if |
fixed |
a named vector of fixed regression coefficients; the names need to correspond to column names of the design matrix |
nofit |
logical, if TRUE, creates the model object, but does not run the optimization |
control |
list with controls for optimization |
... |
additional arguments to |
A CoxphME object.
Generic for copying objects that are (partly) modified in place
duplicate(object, ...)
duplicate(object, ...)
object |
An object. |
... |
Optional parameters. |
Create a duplicate of the tramTMB object
## S3 method for class 'tramTMB' duplicate(object, ...)
## S3 method for class 'tramTMB' duplicate(object, ...)
object |
A |
... |
Optional parameters (not used). |
Returns an estimate of effective degrees of freedom associated with each smooth term.
## S3 method for class 'tramME' edf_smooth(object, ...)
## S3 method for class 'tramME' edf_smooth(object, ...)
object |
A |
... |
Optional arguments passed to the Hessian calculations. |
The EDFs are calculated by summing up the elements of
term-by-term.
is the joint covariance matrix of fixed and random
parameters (the inverse of the joint precision, i.e., Hessian of the
negative log-likelihood), and
is the joint precision of the
unpenalized negative log-likelihood function. See Wood et al. (2016) or
Wood (2017, Chapter 6) for references.
A named vector with the edf values.
Wood, Simon N., Natalya Pya, and Benjamin Saefken (2016). "Smoothing Parameter and Model Selection for General Smooth Models." Journal of the American Statistical Association 111, <doi:10.1080/01621459.2016.1180986>
Wood, Simon N. (2017). Generalized Additive Models: An Introduction with R. Second edition. Chapman & Hall/CRC Texts in Statistical Science.
data("mcycle", package = "MASS") fit <- LmME(accel ~ s(times), data = mcycle) edf_smooth(fit)
data("mcycle", package = "MASS") fit <- LmME(accel ~ s(times), data = mcycle) edf_smooth(fit)
Lehmann
Mixed-effects version of Lehmann
LehmannME( formula, data, subset, weights, offset, na.action = na.omit, silent = TRUE, resid = FALSE, do_update = FALSE, estinit = TRUE, initpar = NULL, fixed = NULL, nofit = FALSE, control = optim_control(), ... )
LehmannME( formula, data, subset, weights, offset, na.action = na.omit, silent = TRUE, resid = FALSE, do_update = FALSE, estinit = TRUE, initpar = NULL, fixed = NULL, nofit = FALSE, control = optim_control(), ... )
formula |
an object of class |
data |
an optional data frame, list or environment (or object
coercible by |
subset |
an optional vector specifying a subset of observations to be used in the fitting process. |
weights |
an optional vector of weights to be used in the fitting
process. Should be |
offset |
this can be used to specify an _a priori_ known component to
be included in the linear predictor during fitting. This
should be |
na.action |
a function which indicates what should happen when the data
contain |
silent |
Logical. Make TMB functionality silent. |
resid |
Logical. If |
do_update |
Logical. If |
estinit |
logical, estimate a vector of initial values for the fixed effects parameters from a (fixed effects only) mlt model |
initpar |
named list of initial parameter values, if |
fixed |
a named vector of fixed regression coefficients; the names need to correspond to column names of the design matrix |
nofit |
logical, if TRUE, creates the model object, but does not run the optimization |
control |
list with controls for optimization |
... |
additional arguments to |
A LehmannME object.
Lm
Mixed-effects version of Lm
LmME( formula, data, subset, weights, offset, na.action = na.omit, silent = TRUE, resid = FALSE, do_update = FALSE, estinit = TRUE, initpar = NULL, fixed = NULL, nofit = FALSE, control = optim_control(), ... )
LmME( formula, data, subset, weights, offset, na.action = na.omit, silent = TRUE, resid = FALSE, do_update = FALSE, estinit = TRUE, initpar = NULL, fixed = NULL, nofit = FALSE, control = optim_control(), ... )
formula |
an object of class |
data |
an optional data frame, list or environment (or object
coercible by |
subset |
an optional vector specifying a subset of observations to be used in the fitting process. |
weights |
an optional vector of weights to be used in the fitting
process. Should be |
offset |
this can be used to specify an _a priori_ known component to
be included in the linear predictor during fitting. This
should be |
na.action |
a function which indicates what should happen when the data
contain |
silent |
Logical. Make TMB functionality silent. |
resid |
Logical. If |
do_update |
Logical. If |
estinit |
logical, estimate a vector of initial values for the fixed effects parameters from a (fixed effects only) mlt model |
initpar |
named list of initial parameter values, if |
fixed |
a named vector of fixed regression coefficients; the names need to correspond to column names of the design matrix |
nofit |
logical, if TRUE, creates the model object, but does not run the optimization |
control |
list with controls for optimization |
... |
additional arguments to |
A LmME object.
Evaluates the log-likelihood function. New parameter values and data can optionally be supplied. In the latter case, the function returns the out-of-sample log-likelihood.
## S3 method for class 'tramME' logLik( object, param = NULL, newdata = NULL, type = c("integrated", "fix_smooth", "penalized"), ... )
## S3 method for class 'tramME' logLik( object, param = NULL, newdata = NULL, type = c("integrated", "fix_smooth", "penalized"), ... )
object |
A |
param |
An optional named list of parameter values (beta and theta). See details. Optionally, gamma elements can also be added, which leads to 'fixing' those random effects terms at the supplied values. |
newdata |
An optional data.frame to calculate the out-of-sample log-likelihood. |
type |
The type of the likelihood to be calculated:
See details. |
... |
Optional argument (for consistency with generic). |
By default, param
is set to the estimated (or previously set)
parameters. If the parameter vectors in the model are incomplete (contain
NA
elemets), the returned log-likelihood will also be NA
,
unless the user provides new values.
Setting type = "fix_smooth"
fixes the random effects terms that
correspond to penalized smooths at their estimated values, so that they
are not refitted when newdata
is supplied. This is consistent with
treating these parameter regularized fixed terms, i.e. as 'new-style'
random effects described by Hodges (2014, Chapter 13).
The "fix_smooth"
and "penalized"
options for type
are
just for convenience. The same functionality can be achieved by setting
param$gamma
to the desired values. "penalized"
respects the
values of param$gamma
if both are supplied, while
"fix_smooth"
overwrites them with the fitted values if there are
ambiguities.
A numeric value of the log-likelihood.
By default, logLik
calculates the _integrated_ (or marginal)
log-likelihood by integrating over the random effects. By fixing the
random effects, the value of the log-likelihood changes, because TMB won't
integrate over these random effects. This will result in the _penalized_
log-likelihood (conditional log-likelihood + penalty for smooth terms and
random effects, see example).
By setting type = "penalized"
, the function will 'fix' all random
effects and penalized parameters of the smooth terms at their predicted
levels, and calcualte the penalized log-likelihood. In this sense, setting
type = "fix_smooth"
will result in a hybrid log-likelihood value,
where the 'true' random effects (c.f. Hodges 2014, Ch. 13) are integrated
out, while it includes the penalty values for the penalized parameters of
the smooths terms.
In general, it is not clear which type of log-likelihood we should calculate when we want to evaluate models based on their out-of-sample log-likelihood values. The context and the model setup are key in these cases. Please make sure you know what you want to calculate to avoid misunderstandings.
Hodges, James S. (2014). Richly Parameterized Linear Models: Additive, Time Series, and Spatial Models Using Random Effects. Chapman & Hall/CRC Texts in Statistical Science Series.
data("sleepstudy", package = "lme4") fit <- LmME(Reaction ~ Days + (Days | Subject), data = sleepstudy) logLik(fit) data("mcycle", package = "MASS") fit <- LmME(accel ~ s(times), data = mcycle) logLik(fit) < logLik(fit, type = "penalized")
data("sleepstudy", package = "lme4") fit <- LmME(Reaction ~ Days + (Days | Subject), data = sleepstudy) logLik(fit) data("mcycle", package = "MASS") fit <- LmME(accel ~ s(times), data = mcycle) logLik(fit) < logLik(fit, type = "penalized")
Extract model frame from a tramME model
## S3 method for class 'tramME' model.frame( formula, data = NULL, group_as_factor = FALSE, ignore_response = FALSE, ... )
## S3 method for class 'tramME' model.frame( formula, data = NULL, group_as_factor = FALSE, ignore_response = FALSE, ... )
formula |
A |
data |
a data.frame, list or environment (or object
coercible by |
group_as_factor |
Logical; If |
ignore_response |
Logical; If |
... |
Optional arguments, passed to |
In mlt
, the basis functions expect the response variables
in the data to be evaluated, i.e. instead of x
and y
columns
we should have a `Surv(x, y)`
column when the response is a
Surv
object. model.frame.tramME
builds the
model frame accordingly, assigning to the resulting object the class
tramME_data
to indicate this structure to other functions that use
its results. If the input data
is a tramME_data
is also expects
this structure.
A tramME_data
object, which is also a data.frame
.
data("sleepstudy", package = "lme4") mod <- LmME(Reaction ~ Days + (Days | Subject), data = sleepstudy, nofit = TRUE) model.frame(mod)
data("sleepstudy", package = "lme4") mod <- LmME(Reaction ~ Days + (Days | Subject), data = sleepstudy, nofit = TRUE) model.frame(mod)
tramME
modelsModel matrix for fixed effects, random effects, and baseline transformations (with interacting terms if present).
## S3 method for class 'tramME' model.matrix( object, data = model.frame(object), type = c("Y", "X", "Zt"), drop_unused_groups = FALSE, keep_sign = TRUE, simplify = FALSE, ... )
## S3 method for class 'tramME' model.matrix( object, data = model.frame(object), type = c("Y", "X", "Zt"), drop_unused_groups = FALSE, keep_sign = TRUE, simplify = FALSE, ... )
object |
A |
data |
A |
type |
"X": Fixed effects model matrix. "Zt": Random effects model matrix (transposed). "Y": Model matrices for the baseline transfromations. |
drop_unused_groups |
Logical; remove unused levels of the random effects.
(see |
keep_sign |
Logical; the terms will have the same sign as in the
|
simplify |
Logical; Remove empty |
... |
Optional arguments. |
Creates model matrices for fixed effects (type = "X"
) and random
effects (type = "Zt"
) and baseline transfromation (type = "Y"
),
by evaluating the respective basis functions given a new dataset.
The response values may be exact, censored (left, right, interval) and truncated (left, right, interval), and the function returns several, potentially empty, model matrices:
Ye: Exact observations.
Yeprime: The model matrix corresponding to the first derivative of the baseline transformation, evaluated at exact observations.
Yl: Left-censored observations.
Yr: Rigt-censored observations.
Yil and Yir: Interval-censored observations evaluated at the left and right bounds of the interval.
Ytl: Left-truncated observations.
Ytr: Rigt-truncated observations.
Ytil and Ytir: Interval-truncated observations evaluated at the left and right bounds of the interval.
for the baseline transfromations (unless simplify = TRUE
).
List of requested model matrices.
The model matrix of the random effects is a sparse matrix and it is transposed
to be directly used with Matrix::crossprod
which is faster than transposing
and multiplying ("Zt" instead of "Z").
library("survival") rats$litter <- factor(rats$litter) m <- CoxphME(Surv(time, status) ~ rx + (1 | litter), data = rats, log_first = TRUE, nofit = TRUE) mm <- model.matrix(m) nd <- model.frame(m)[rep(1, 100), ] nd[[1]] <- seq(1, 120, length.out = 100) mm2 <- model.matrix(m, data = nd, simplify = TRUE) mm3 <- model.matrix(m, data = nd, simplify = TRUE, drop_unused_groups = TRUE) ## compare mm2$Zt & mm3$Zt
library("survival") rats$litter <- factor(rats$litter) m <- CoxphME(Surv(time, status) ~ rx + (1 | litter), data = rats, log_first = TRUE, nofit = TRUE) mm <- model.matrix(m) nd <- model.frame(m)[rep(1, 100), ] nd[[1]] <- seq(1, 120, length.out = 100) mm2 <- model.matrix(m, data = nd, simplify = TRUE) mm3 <- model.matrix(m, data = nd, simplify = TRUE, drop_unused_groups = TRUE) ## compare mm2$Zt & mm3$Zt
Set up and control optimization parameters
optim_control( method = c("nlminb", "BFGS", "CG", "L-BFGS-B"), scale = TRUE, trace = FALSE, ntry = 5, ... )
optim_control( method = c("nlminb", "BFGS", "CG", "L-BFGS-B"), scale = TRUE, trace = FALSE, ntry = 5, ... )
method |
Optimization procedure. |
scale |
Logical; if |
trace |
Logical; print trace of the optimization. |
ntry |
Number of restarts with new random initialization if optimization fails to converge. |
... |
Optional arguments passed to |
Plot smooth terms of a tramME model.
## S3 method for class 'smooth.tramME' plot( x, which = seq_along(x), col = 1, fill = grey(0.5, 0.25), trafo = I, add = FALSE, ... )
## S3 method for class 'smooth.tramME' plot( x, which = seq_along(x), col = 1, fill = grey(0.5, 0.25), trafo = I, add = FALSE, ... )
x |
A |
which |
Select terms to be printed by their indices |
col |
Line color for the point estimates. |
fill |
Fill color for the confidence intervals. |
trafo |
Monotonic transformation to be applied on the smooth terms |
add |
Add the plot to an existing figure. |
... |
Optional parameters passed to the plotting functions. |
data("mcycle", package = "MASS") fit <- LmME(accel ~ s(times), data = mcycle) plot(smooth_terms(fit, as.lm = TRUE))
data("mcycle", package = "MASS") fit <- LmME(accel ~ s(times), data = mcycle) plot(smooth_terms(fit, as.lm = TRUE))
Plot the conditional distribution evaluated at a grid of possible response values and a set of covariate and random effects values on a specified scale.
## S3 method for class 'tramME' plot( x, newdata = model.frame(x), ranef = NULL, fix_smooth = TRUE, type = c("trafo", "distribution", "survivor", "density", "logdensity", "hazard", "loghazard", "cumhazard", "odds", "logodds", "quantile"), ... )
## S3 method for class 'tramME' plot( x, newdata = model.frame(x), ranef = NULL, fix_smooth = TRUE, type = c("trafo", "distribution", "survivor", "density", "logdensity", "hazard", "loghazard", "cumhazard", "odds", "logodds", "quantile"), ... )
x |
A |
newdata |
an optional data frame of observations |
ranef |
Random effects (either in named list format or a numeric vector) or the word "zero". See Details. |
fix_smooth |
If |
type |
The scale on which the predictions are evaluated:
|
... |
Additional arguments, passed to |
When ranef
is equal to "zero", a vector of zeros with the right size is
substituted. For more details, see predict.tramME
.
For more information on how to control the grid on which the functions are evaluated,
see the documentation of predict.mlt
.
A numeric matrix of the predicted values invisibly.
data("sleepstudy", package = "lme4") fit <- BoxCoxME(Reaction ~ Days + (Days | Subject), data = sleepstudy) plot(fit, K = 100, type = "density")
data("sleepstudy", package = "lme4") fit <- BoxCoxME(Reaction ~ Days + (Days | Subject), data = sleepstudy) plot(fit, K = 100, type = "density")
Polr
Mixed-effects version of Polr
PolrME( formula, data, subset, weights, offset, na.action = na.omit, method = c("logistic", "probit", "loglog", "cloglog"), silent = TRUE, resid = FALSE, do_update = FALSE, estinit = TRUE, initpar = NULL, fixed = NULL, nofit = FALSE, control = optim_control(), ... )
PolrME( formula, data, subset, weights, offset, na.action = na.omit, method = c("logistic", "probit", "loglog", "cloglog"), silent = TRUE, resid = FALSE, do_update = FALSE, estinit = TRUE, initpar = NULL, fixed = NULL, nofit = FALSE, control = optim_control(), ... )
formula |
an object of class |
data |
an optional data frame, list or environment (or object
coercible by |
subset |
an optional vector specifying a subset of observations to be used in the fitting process. |
weights |
an optional vector of weights to be used in the fitting
process. Should be |
offset |
this can be used to specify an _a priori_ known component to
be included in the linear predictor during fitting. This
should be |
na.action |
a function which indicates what should happen when the data
contain |
method |
a character describing the link function. |
silent |
Logical. Make TMB functionality silent. |
resid |
Logical. If |
do_update |
Logical. If |
estinit |
logical, estimate a vector of initial values for the fixed effects parameters from a (fixed effects only) mlt model |
initpar |
named list of initial parameter values, if |
fixed |
a named vector of fixed regression coefficients; the names need to correspond to column names of the design matrix |
nofit |
logical, if TRUE, creates the model object, but does not run the optimization |
control |
list with controls for optimization |
... |
additional arguments to |
A PolrME object.
Evaluates the _conditional_ distribution implied by a tramME model, given by a set of covariates and random effects on a selected scale.
## S3 method for class 'tramME' predict( object, newdata = model.frame(object), ranef = NULL, fix_smooth = TRUE, type = c("lp", "trafo", "distribution", "survivor", "density", "logdensity", "hazard", "loghazard", "cumhazard", "odds", "logodds", "quantile"), ... )
## S3 method for class 'tramME' predict( object, newdata = model.frame(object), ranef = NULL, fix_smooth = TRUE, type = c("lp", "trafo", "distribution", "survivor", "density", "logdensity", "hazard", "loghazard", "cumhazard", "odds", "logodds", "quantile"), ... )
object |
A |
newdata |
an optional data frame of observations |
ranef |
Random effects it can be a |
fix_smooth |
If |
type |
The scale on which the predictions are evaluated:
|
... |
Additional arguments, passed to |
When newdata
contains values of the response variable, prediction is only
done for those values. In this case, if random effects vector (ranef
) is not
supplied by the user, the function predicts the random effects from the model
using newdata
.
When no response values are supplied in newdata
, the prediction is done
on a grid of values for each line of the dataset (see predict.mlt
for information on how to control the setup of this grid).
In this case, the user has to specify the vector of random effects to avoid ambiguities.
The linear predictor (type = "lp"
) equals to the shift terms plus the random
effects terms _without the baseline transfromation function_.
The linear predictor (type = "lp"
) and the conditional quantile function
(type = "quantile"
) are special in that they do not return results evaluated
on a grid, even when the response variable in newdata
is missing. The probabilities
for the evaluation of the quantile function can be supplied with the prob
argument
of predict.mlt
.
In the case of type = "quantile"
, when the some of the requested conditonal
quantiles fall outside of the support of the response distribution
(specified when the model was set up), the inversion of the CDF cannot be done exactly
and tramME
returns censored values.
ranef
can be different objects based on what we want to calculate and
what the other inputs are. If ranef
is a ranef.tramME
, we assume
that it contains the full set of random effects, but not the penalized coefficients
of the smooth terms. In this case fix_smooth
must be TRUE
. If
ranef
is a named vector, we are fixing the supplied random effects (and
penalized coefficients) and predict the rest from newdata
(fix_smooth
may also be used in this case). In this case, the random effects are identified
with the same naming convention as in object$param$gamma
.
If ranef
is an unnamed vector, the function expects the
full set of necessary random effects (with or without penalized coefficients, depending
on fix_smooth
). If ranef = NULL
(the default), all random effects and
optionally penalized parameters (although this is not recommended) are predicted from
newdata
. Finally, if ranef
is equal to "zero", a vector of zeros with the
right size is used.
A numeric vector/matrix of the predicted values (depending on the inputs)
or a response
object, when the some of the requested conditonal quantiles
fall outside of the support of the response distribution specified when the model
was set up (only can occur with type = "quantile"
).
data("sleepstudy", package = "lme4") fit <- BoxCoxME(Reaction ~ Days + (Days | Subject), data = sleepstudy) predict(fit, type = "trafo") ## evaluate on the transformation function scale nd <- sleepstudy nd$Reaction <- NULL pr <- predict(fit, newdata = nd, ranef = ranef(fit), type = "distribution", K = 100)
data("sleepstudy", package = "lme4") fit <- BoxCoxME(Reaction ~ Days + (Days | Subject), data = sleepstudy) predict(fit, type = "trafo") ## evaluate on the transformation function scale nd <- sleepstudy nd$Reaction <- NULL pr <- predict(fit, newdata = nd, ranef = ranef(fit), type = "distribution", K = 100)
Post-estimation calculations in a tramTMB model
## S3 method for class 'tramTMB' predict( object, newdata, parameters = .get_par(object, full = TRUE), scale = c("lp", "trafo"), cov = FALSE, as.lm = FALSE, ... )
## S3 method for class 'tramTMB' predict( object, newdata, parameters = .get_par(object, full = TRUE), scale = c("lp", "trafo"), cov = FALSE, as.lm = FALSE, ... )
object |
A |
newdata |
A named list with elements Y, X and Z (not all necessary) |
parameters |
A named list of parameter values |
scale |
The scale on which the post-estimation calculations are done |
cov |
Logical; If |
as.lm |
Logical; reparameterize as a LMM |
... |
Optional arguments (ignored). |
anova.tramME
tablePrinting anova.tramME
table
## S3 method for class 'anova.tramME' print( x, digits = max(getOption("digits") - 2L, 3L), signif.stars = getOption("show.signif.stars"), ... )
## S3 method for class 'anova.tramME' print( x, digits = max(getOption("digits") - 2L, 3L), signif.stars = getOption("show.signif.stars"), ... )
x |
A |
digits |
minimum number of significant digits to be used for most numbers. |
signif.stars |
logical; if |
... |
Optional arguments passed to |
Invisibly retrurns the anova.tramME
object.
Print method for tramME model summary
## S3 method for class 'summary.tramME' print( x, fancy = !isTRUE(getOption("knitr.in.progress")) && interactive(), digits = max(getOption("digits") - 2L, 3L), signif.stars = getOption("show.signif.stars"), ... )
## S3 method for class 'summary.tramME' print( x, fancy = !isTRUE(getOption("knitr.in.progress")) && interactive(), digits = max(getOption("digits") - 2L, 3L), signif.stars = getOption("show.signif.stars"), ... )
x |
A |
fancy |
Logical, if |
digits |
minimum number of significant digits to be used for most numbers. |
signif.stars |
logical; if |
... |
Optional arguments passed to |
The input summary.tramME object, invisibly.
Print tramME model
## S3 method for class 'tramME' print(x, digits = max(getOption("digits") - 2L, 3L), ...)
## S3 method for class 'tramME' print(x, digits = max(getOption("digits") - 2L, 3L), ...)
x |
A |
digits |
Number of significant digits |
... |
Optional arguments (for consistency with the generic) |
The original tramME
object invisibly
Print method for the variance-correlation parameters of a tramME object
## S3 method for class 'VarCorr.tramME' print(x, sd = TRUE, digits = max(getOption("digits") - 2L, 3L), ...)
## S3 method for class 'VarCorr.tramME' print(x, sd = TRUE, digits = max(getOption("digits") - 2L, 3L), ...)
x |
A |
sd |
Logical. Print standard deviations instead of variances. |
digits |
Number of digits |
... |
optional arguments |
Invisibly returns the input VarCorr.tramME object.
The condVar
option is not implemented for ranef.LmME
.
Setting raw=TURE
will return the raw random effects estimates from
the transformation model parametrization.
## S3 method for class 'LmME' ranef(object, as.lm = FALSE, ...)
## S3 method for class 'LmME' ranef(object, as.lm = FALSE, ...)
object |
A fitted LmME object. |
as.lm |
If |
... |
Optional parameters passed to |
A numeric vector or a ranef.tramME
object depending on the inputs.
data("sleepstudy", package = "lme4") fit <- LmME(Reaction ~ Days + (Days | Subject), data = sleepstudy) ranef(fit, raw = TRUE) ## transformation model parametrization! ranef(fit, as.lm = TRUE)
data("sleepstudy", package = "lme4") fit <- LmME(Reaction ~ Days + (Days | Subject), data = sleepstudy) ranef(fit, raw = TRUE) ## transformation model parametrization! ranef(fit, as.lm = TRUE)
Extract the conditional modes and conditional variances of random effects in a formatted or unformatted way.
## S3 method for class 'tramME' ranef( object, param = NULL, newdata = NULL, fix_smooth = !is.null(newdata), condVar = FALSE, raw = FALSE, ... )
## S3 method for class 'tramME' ranef( object, param = NULL, newdata = NULL, fix_smooth = !is.null(newdata), condVar = FALSE, raw = FALSE, ... )
object |
A |
param |
An optional named list of parameter values (beta and theta). See details. Optionally, gamma elements can also be added, which leads to 'fixing' those random effects terms at the supplied values. |
newdata |
An optional |
fix_smooth |
Logical; it is set to |
condVar |
If |
raw |
Return the unformatted RE estimates as fitted by the model. |
... |
Optional arguments (for consistency with generic) |
raw = TRUE
returns the whole vector of random effects (i.e. with
parameters of smooth shift terms), while raw = FALSE
only returns
the formatted list of actual random effects (i.e. for grouped
observations) values. For the conceptual differences between the two types
of random effects, see Hodges (2014, Chapter 13).
The conditional variances of the fixed random effects are set to NA
.
Depending on the value of raw
, either a numeric vector or a
ranef.tramME
object which contains the conditional mode and variance
estimates by grouping factors.
The function has several optional arguments that allow great flexibilty beyond its most basic usage. The user should be careful with setting these, because some combinations might not return sensical results. Only limited sanity checks are performed.
Hodges, James S. (2014). Richly Parameterized Linear Models: Additive, Time Series, and Spatial Models Using Random Effects. Chapman & Hall/CRC Texts in Statistical Science Series.
data("sleepstudy", package = "lme4") fit <- BoxCoxME(Reaction ~ Days + (Days | Subject), data = sleepstudy, order = 5) ranef(fit, raw = TRUE) ranef(fit)
data("sleepstudy", package = "lme4") fit <- BoxCoxME(Reaction ~ Days + (Days | Subject), data = sleepstudy, order = 5) ranef(fit, raw = TRUE) ranef(fit)
Calculates the score residuals of an intercept term fixed at 0. In the case of an LmME model, this is equal to the residual of an LMM.
## S3 method for class 'LmME' residuals(object, as.lm = FALSE, ...)
## S3 method for class 'LmME' residuals(object, as.lm = FALSE, ...)
object |
An |
as.lm |
If |
... |
Optional arguments (for consistency with generic) |
data("sleepstudy", package = "lme4") fit <- LmME(Reaction ~ Days + (Days | Subject), data = sleepstudy) resid(fit)
data("sleepstudy", package = "lme4") fit <- LmME(Reaction ~ Days + (Days | Subject), data = sleepstudy) resid(fit)
Calculates the score residuals of an intercept term fixed at 0.
## S3 method for class 'tramME' residuals( object, param = NULL, newdata = NULL, fix_smooth = !is.null(newdata), ... )
## S3 method for class 'tramME' residuals( object, param = NULL, newdata = NULL, fix_smooth = !is.null(newdata), ... )
object |
A |
param |
An optional named list of parameter values (beta and theta). See details. Optionally, gamma elements can also be added, which leads to 'fixing' those random effects terms at the supplied values. |
newdata |
An optional |
fix_smooth |
Logical; it is set to |
... |
Optional arguments (for consistency with generic) |
library("survival") fit <- SurvregME(Surv(time, status) ~ rx + (1 | litter), data = rats) resid(fit)
library("survival") fit <- SurvregME(Surv(time, status) ~ rx + (1 | litter), data = rats) resid(fit)
Response objects to represent censored and truncated observations
Resp( cleft, cright, tleft, tright, bounds = c(-Inf, Inf), open_lwr_bnd = TRUE, tol = sqrt(.Machine$double.eps) ) ## S3 method for class 'Resp' R(object, ...) ## S3 method for class 'Resp' print(x, ...) ## S3 method for class 'Resp' x[i, j, drop = FALSE] ## S3 method for class 'Resp' is.na(x) ## S3 method for class 'Resp' length(x) ## S3 method for class 'Resp' format(x, ...)
Resp( cleft, cright, tleft, tright, bounds = c(-Inf, Inf), open_lwr_bnd = TRUE, tol = sqrt(.Machine$double.eps) ) ## S3 method for class 'Resp' R(object, ...) ## S3 method for class 'Resp' print(x, ...) ## S3 method for class 'Resp' x[i, j, drop = FALSE] ## S3 method for class 'Resp' is.na(x) ## S3 method for class 'Resp' length(x) ## S3 method for class 'Resp' format(x, ...)
cleft |
A vector of left borders of censoring intervals |
cright |
A vector of right borders of censoring intervals |
tleft |
A vector of left truncation values |
tright |
A vector of right truncation values |
bounds |
An optional numeric vector of two elements ( |
open_lwr_bnd |
Logical; if |
tol |
Tolerance level. |
object |
A |
... |
Optional arguments |
x |
A |
i |
Row index (typically the only index) |
j |
Column index (typically missing) |
drop |
If |
Resp
extends the functionality of Surv
class
by allowing cases that cannot be defined with it. An example is an
interval-censored outcome with left truncatation (see Examples).
Censored and exactly observed data can be defined similarly to type =
"interval2"
objects in Surv
. NA
values for
left or right censoring borders mean left- or right-censored observations,
respectively. If both borders are NA
, the observation is considered
NA
by is.na()
. Truncation times (tleft
and
tright
arguments) can be omitted or take NA
values, which
means no truncation. If only the censoring intervals are provided, i.e.,
no trunction is present, the function returns a Surv
object.
Resp
also provides a limited interface between tramME
and the
response
class (technically, inherits from it) of mlt
(see
R
), which uses an internal representation that is not
compatible with tramME
.
The optional argument open_lwr_bnd
can be used to enforce lower
boundaries of the outcome. Left boundaries in the Resp
object
(cleft
and tleft
) that are equal to the first element of
bounds
will be increased with one tol
value to avoid
downstream numerical problems in mlt
. This adjustment is recorded
and reversed when we print the object.
A Resp
object or a Surv
object
R(Resp)
: Converting Resp
objects to response
(from
mlt
) objects (see R
)
print(Resp)
: Print method for the Resp
class
[
: Subsetting Resp
objects
is.na(Resp)
: Missing values
length(Resp)
: Length of a Resp
object
format(Resp)
: format
method for a Resp
object
This function is experimental and currently limited to continuous outcome types. It may be subject to change.
dat <- data.frame(x1 = 1:10, x2 = c(2:10, NA), x3 = c(NA, 0:8)) dat$r <- with(dat, Resp(x1, x2, x3)) dat$r dat[1:3, ]$r dat$r[1:3] is.na(dat$r) model.frame(r ~ 1, data = dat, na.action = na.omit)
dat <- data.frame(x1 = 1:10, x2 = c(2:10, NA), x3 = c(NA, 0:8)) dat$r <- with(dat, Resp(x1, x2, x3)) dat$r dat[1:3, ]$r dat$r[1:3] is.na(dat$r) model.frame(r ~ 1, data = dat, na.action = na.omit)
Extract the SD of the error term of an LmME model.
## S3 method for class 'LmME' sigma(object, ...)
## S3 method for class 'LmME' sigma(object, ...)
object |
An |
... |
Optional argument (for consistency with generic). |
A numeric value of the transformed sigma parameter.
data("sleepstudy", package = "lme4") fit <- LmME(Reaction ~ Days + (Days | Subject), data = sleepstudy) sigma(fit)
data("sleepstudy", package = "lme4") fit <- LmME(Reaction ~ Days + (Days | Subject), data = sleepstudy) sigma(fit)
tramME
modelSimulate from a tramME
model
## S3 method for class 'tramME' simulate( object, nsim = 1, seed = NULL, newdata = model.frame(object), type = c("ranef", "response", "joint"), ... )
## S3 method for class 'tramME' simulate( object, nsim = 1, seed = NULL, newdata = model.frame(object), type = c("ranef", "response", "joint"), ... )
object |
A |
nsim |
number of samples to generate |
seed |
optional seed for the random number generator |
newdata |
an optional data frame of observations |
type |
Defaults to |
... |
Additional arguments, passed to |
A length nsim
list of draws.
This method is under active development and may be subject to change. It is currently limited to simulating random effects.
data("sleepstudy", package = "lme4") fit <- BoxCoxME(Reaction ~ Days + (Days | Subject), data = sleepstudy) sim <- simulate(fit, nsim = 10, seed = 123)
data("sleepstudy", package = "lme4") fit <- BoxCoxME(Reaction ~ Days + (Days | Subject), data = sleepstudy) sim <- simulate(fit, nsim = 10, seed = 123)
LmME
model.Evaluate smooth terms of a LmME
model.
## S3 method for class 'LmME' smooth_terms(object, as.lm = FALSE, k = 100, newdata = NULL, ...)
## S3 method for class 'LmME' smooth_terms(object, as.lm = FALSE, k = 100, newdata = NULL, ...)
object |
A |
as.lm |
Logical; if |
k |
Integer, the number of points to be used to evaluate the smooth terms.
Ignored when |
newdata |
A |
... |
Optional arguments. |
A list of results from evaluating the smooth terms of the model.
data("mcycle", package = "MASS") fit <- LmME(accel ~ s(times), data = mcycle) plot(smooth_terms(fit, as.lm = TRUE))
data("mcycle", package = "MASS") fit <- LmME(accel ~ s(times), data = mcycle) plot(smooth_terms(fit, as.lm = TRUE))
Extract and evaluate the smooth terms of a tramME model
## S3 method for class 'tramME' smooth_terms(object, k = 100, newdata = NULL, ...)
## S3 method for class 'tramME' smooth_terms(object, k = 100, newdata = NULL, ...)
object |
A |
k |
Integer, the number of points to be used to evaluate the smooth terms.
Ignored when |
newdata |
A |
... |
Optional arguments. |
A list of results from evaluating the smooth terms of the model.
data("mcycle", package = "MASS") fit <- LmME(accel ~ s(times), data = mcycle) plot(smooth_terms(fit))
data("mcycle", package = "MASS") fit <- LmME(accel ~ s(times), data = mcycle) plot(smooth_terms(fit))
Summary method for tramME model
## S3 method for class 'tramME' summary(object, ...)
## S3 method for class 'tramME' summary(object, ...)
object |
A |
... |
Optional arguments (for consistency with the generic) |
A summary.tramME object.
Survreg
Mixed-effects version of Survreg
SurvregME( formula, data, subset, weights, offset, na.action = na.omit, dist = c("weibull", "logistic", "gaussian", "exponential", "rayleigh", "loggaussian", "lognormal", "loglogistic"), scale = 0, silent = TRUE, resid = FALSE, do_update = FALSE, estinit = TRUE, initpar = NULL, fixed = NULL, nofit = FALSE, control = optim_control(), ... )
SurvregME( formula, data, subset, weights, offset, na.action = na.omit, dist = c("weibull", "logistic", "gaussian", "exponential", "rayleigh", "loggaussian", "lognormal", "loglogistic"), scale = 0, silent = TRUE, resid = FALSE, do_update = FALSE, estinit = TRUE, initpar = NULL, fixed = NULL, nofit = FALSE, control = optim_control(), ... )
formula |
an object of class |
data |
an optional data frame, list or environment (or object
coercible by |
subset |
an optional vector specifying a subset of observations to be used in the fitting process. |
weights |
an optional vector of weights to be used in the fitting
process. Should be |
offset |
this can be used to specify an _a priori_ known component to
be included in the linear predictor during fitting. This
should be |
na.action |
a function which indicates what should happen when the data
contain |
dist |
character defining the conditional distribution of the (not necessarily positive) response, current choices include Weibull, logistic, normal, exponential, Rayleigh, log-normal (same as log-gaussian), or log-logistic. |
scale |
a fixed value for the scale parameter(s). |
silent |
logical, make TMB functionality silent |
resid |
logical, Should the score residuals also be calculated? |
do_update |
Logical. If |
estinit |
logical, estimate a vector of initial values for the fixed effects parameters from a (fixed effects only) mlt model |
initpar |
named list of initial parameter values, if |
fixed |
a named vector of fixed regression coefficients; the names need to correspond to column names of the design matrix |
nofit |
logical, if TRUE, creates the model object, but does not run the optimization |
control |
list with controls for optimization |
... |
additional arguments to |
A SurvregME
object.
The specific model types (LmME
,
BoxCoxME
, ColrME
, etc.) are
wrappers around this function.
tramME( formula, tram, call, data, subset, weights, offset, na.action, silent = TRUE, resid = FALSE, do_update = FALSE, estinit = TRUE, initpar = NULL, fixed = NULL, nofit = FALSE, control = optim_control(), ... )
tramME( formula, tram, call, data, subset, weights, offset, na.action, silent = TRUE, resid = FALSE, do_update = FALSE, estinit = TRUE, initpar = NULL, fixed = NULL, nofit = FALSE, control = optim_control(), ... )
formula |
an object of class |
tram |
Parameter vector for the |
call |
The original function call (to be passed from the wrapper). |
data |
an optional data frame, list or environment (or object
coercible by |
subset |
an optional vector specifying a subset of observations to be used in the fitting process. |
weights |
an optional vector of weights to be used in the fitting
process. Should be |
offset |
this can be used to specify an _a priori_ known component to
be included in the linear predictor during fitting. This
should be |
na.action |
a function which indicates what should happen when the data
contain |
silent |
Logical. Make TMB functionality silent. |
resid |
Logical. If |
do_update |
Logical. If |
estinit |
logical, estimate a vector of initial values for the fixed effects parameters from a (fixed effects only) mlt model |
initpar |
named list of initial parameter values, if |
fixed |
a named vector of fixed regression coefficients; the names need to correspond to column names of the design matrix |
nofit |
logical, if TRUE, creates the model object, but does not run the optimization |
control |
list with controls for optimization |
... |
additional arguments to |
You should not call directly this function. Only exported for technical reasons.
There are two ways of defining tramME models:
A ctm model and a formula defining the random effects and smooth terms.
A formula combining the notation of tram, lme4 and mgcv, a tram function name, and a dataset to set up the bases.
tramME_model( formula = NULL, data = NULL, tram = NULL, ctm = NULL, smooth = NULL, negative = NULL, ... )
tramME_model( formula = NULL, data = NULL, tram = NULL, ctm = NULL, smooth = NULL, negative = NULL, ... )
formula |
formula that either describes the whole model or
the random effects specification. If the model contains random effects or
smooth terms |
data |
an optional data frame, list or environment (or object
coercible by |
tram |
tram model name: Lm, BoxCox, Colr, Polr, Coxph, Survreg, Lehmann,
Aareg, or the suffixed versions of these (e.g. ColrME). Ignored when a |
ctm |
A |
smooth |
Optional pre-defined smooth specification of the class |
negative |
an optional parameter that defines whether the random effects have a positive or a negative sign in the model when the fixed effecst part is defined through a ctm |
... |
optional arguments passed to tram when the model is defined by the formula |
A tramME_model object that defines the mixed effects transfromation model.
Similarly to mlt, the offsets and the weights are not part of the model, but they are data and they are not saved in the returned object.
Create a tramTMB object
tramTMB( data, parameters, constraint, negative, map = list(), resid = FALSE, do_update = FALSE, check_const = TRUE, no_int = FALSE, ... )
tramTMB( data, parameters, constraint, negative, map = list(), resid = FALSE, do_update = FALSE, check_const = TRUE, no_int = FALSE, ... )
data |
List of data objects (vectors, matrices, arrays, factors, sparse matrices) required by the user template (order does not matter and un-used components are allowed). |
parameters |
List of all parameter objects required by the user template (both random and fixed effects). |
constraint |
list describing the constarints on the parameters |
negative |
logical, whether the model is parameterized with negative values |
map |
same as map argument of |
resid |
logical, indicating whether the score residuals are calculated from the resulting object |
do_update |
logical, indicating whether the model should be set up with updateable offsets and weights |
check_const |
Logical; if |
no_int |
Logical; if |
... |
optional parameters passed to |
A tramTMB object.
The post-estimation parameters are supplied as a part of data
The returned parameters are the transformed versions of the original parameters that correspond to the normal linear mixed model parametrization.
## S3 method for class 'LmME' VarCorr(x, sigma = 1, as.lm = FALSE, ...)
## S3 method for class 'LmME' VarCorr(x, sigma = 1, as.lm = FALSE, ...)
x |
An |
sigma |
Standard deviation of the error term in the LMM parametrization (should not be set manually, only for consistency with the generic method) |
as.lm |
If |
... |
Optional arguments (for consistency with generic) |
The function only returns the correlation matrices that belong to actual random effects
(defined for groups in the data) and ignores the random effects parameters of the smooth
shift terms. To extract these, the user should use varcov
with full = TRUE
.
A list of vectors with variances and correlation matrices corresponding to the various grouping variables.
data("sleepstudy", package = "lme4") fit <- LmME(Reaction ~ Days + (Days | Subject), data = sleepstudy) VarCorr(fit) ## tranformation model parametrization VarCorr(fit, as.lm = TRUE) ## LMM parametrization
data("sleepstudy", package = "lme4") fit <- LmME(Reaction ~ Days + (Days | Subject), data = sleepstudy) VarCorr(fit) ## tranformation model parametrization VarCorr(fit, as.lm = TRUE) ## LMM parametrization
This function calculates the variances and correlations from varcov.tramME
.
## S3 method for class 'tramME' VarCorr(x, ...)
## S3 method for class 'tramME' VarCorr(x, ...)
x |
A |
... |
optional arguments (for consistency with the generic method) |
The function only returns the correlation matrices that belong to actual random effects
(defined for groups in the data) and ignores the random effects parameters of the smooth
shift terms. To extract these, the user should use varcov
with full = TRUE
.
A list of vectors with variances and correlation matrices corresponding to the various grouping variables.
data("sleepstudy", package = "lme4") fit <- BoxCoxME(Reaction ~ Days + (Days | Subject), data = sleepstudy) VarCorr(fit)
data("sleepstudy", package = "lme4") fit <- BoxCoxME(Reaction ~ Days + (Days | Subject), data = sleepstudy) VarCorr(fit)
varcov
Generic method for varcov
varcov(object, ...)
varcov(object, ...)
object |
A model object. |
... |
Optional inputs. |
A variance-covariance matrix.
Extract the variance-covariance matrix of the random effects of an LmME model
## S3 method for class 'LmME' varcov(object, as.lm = FALSE, as.theta = FALSE, full = FALSE, ...)
## S3 method for class 'LmME' varcov(object, as.lm = FALSE, as.theta = FALSE, full = FALSE, ...)
object |
A |
as.lm |
If |
as.theta |
Logical value, if |
full |
Logical value; if |
... |
Optional arguments (unused). |
A list of the covariance matrices or a vector of theta values.
data("sleepstudy", package = "lme4") fit <- LmME(Reaction ~ Days + (Days | Subject), data = sleepstudy) varcov(fit, as.lm = TRUE) varcov(fit, as.theta = TRUE, as.lm = TRUE)
data("sleepstudy", package = "lme4") fit <- LmME(Reaction ~ Days + (Days | Subject), data = sleepstudy) varcov(fit, as.lm = TRUE) varcov(fit, as.theta = TRUE, as.lm = TRUE)
Returns the covariance matrix of the random effects as saved in the tramME
object.
The returned values correspond to the transformation model parametrization.
## S3 method for class 'tramME' varcov(object, as.theta = FALSE, full = FALSE, ...)
## S3 method for class 'tramME' varcov(object, as.theta = FALSE, full = FALSE, ...)
object |
A |
as.theta |
Logical value, if |
full |
Logical value; if |
... |
Optional arguments (unused). |
A list of the covariance matrices or a vector of theta values.
data("sleepstudy", package = "lme4") fit <- LmME(Reaction ~ Days + (Days | Subject), data = sleepstudy) varcov(fit) varcov(fit, as.theta = TRUE)
data("sleepstudy", package = "lme4") fit <- LmME(Reaction ~ Days + (Days | Subject), data = sleepstudy) varcov(fit) varcov(fit, as.theta = TRUE)
"varcov<-"
Generic method for "varcov<-"
varcov(object, ...) <- value
varcov(object, ...) <- value
object |
A model object. |
... |
Optional inputs. |
value |
The new value of the covariance matrix. |
An object with the same class as object
, with updated
variance-covariance matrix of random effects.
Sets the list containing the covariance matrices of a tramME model. The matrices have
to be positive definite. Just as in "coef<-"
, when the function is called
on a fitted object, the function will remove the infromation about the optimization.
## S3 replacement method for class 'tramME' varcov(object, as.theta = FALSE, ...) <- value
## S3 replacement method for class 'tramME' varcov(object, as.theta = FALSE, ...) <- value
object |
A |
as.theta |
Logical value, if |
... |
Optional arguments (ignored). |
value |
A list of positive definite covariance matrices. |
The supplied list has to be named with the same names as implied by the model.
Hence, it might be a good idea to call varcov
first, and
modify this list to make sure that the input has the right structure.
The new values can also be supplied in a form that corresponds to the reparametrization
used by the tramTMB
model (see the option as.theta = TRUE
).
All random effects variance parameters must be supplied. When there are penalized smooth terms in the model variance parameters corresponding to these should also be part of the input list.
A new tramME
object with the new coefficient values.
data("sleepstudy", package = "lme4") mod <- LmME(Reaction ~ Days + (Days | Subject), data = sleepstudy, nofit = TRUE) vc <- varcov(mod) vc[[1]] <- matrix(c(1, 0, 0, 2), ncol = 2) varcov(mod) <- vc
data("sleepstudy", package = "lme4") mod <- LmME(Reaction ~ Days + (Days | Subject), data = sleepstudy, nofit = TRUE) vc <- varcov(mod) vc[[1]] <- matrix(c(1, 0, 0, 2), ncol = 2) varcov(mod) <- vc
Returns the variable names corresponding to different variable groups in a tramME model.
## S3 method for class 'tramME' variable.names( object, which = c("all", "response", "grouping", "shifting", "interacting", "smooth", "ranef"), ... )
## S3 method for class 'tramME' variable.names( object, which = c("all", "response", "grouping", "shifting", "interacting", "smooth", "ranef"), ... )
object |
a tramME object (fitted or unfitted) |
which |
|
... |
optional parameters |
The returned names are the names as they are used by tramME. For example,
when the response is a Surv
object, variable.names
returns
the name of that object, and not the names of the variables used to create it.
A vector of variable names.
data("sleepstudy", package = "lme4") mod <- LmME(Reaction ~ Days + (Days | Subject), data = sleepstudy, nofit = TRUE) variable.names(mod) variable.names(mod, "response")
data("sleepstudy", package = "lme4") mod <- LmME(Reaction ~ Days + (Days | Subject), data = sleepstudy, nofit = TRUE) variable.names(mod) variable.names(mod, "response")
Get the variance-covariance matrix of the parameters of an LmME model
## S3 method for class 'LmME' vcov( object, as.lm = FALSE, parm = NULL, pargroup = c("all", "fixef", "ranef"), ... )
## S3 method for class 'LmME' vcov( object, as.lm = FALSE, parm = NULL, pargroup = c("all", "fixef", "ranef"), ... )
object |
A fitted |
as.lm |
If |
parm |
Names of the parameters to extract. |
pargroup |
The name of the parameter group to extract. With
|
... |
Optional parameters passed to |
A numeric covariance matrix.
data("sleepstudy", package = "lme4") fit <- LmME(Reaction ~ Days + (Days | Subject), data = sleepstudy) vcov(fit) ## transformation model parametrization vcov(fit, as.lm = TRUE) ## LMM parametrization vcov(fit, as.lm = TRUE, pargroup = "fixef") ## cov of fixed effects
data("sleepstudy", package = "lme4") fit <- LmME(Reaction ~ Days + (Days | Subject), data = sleepstudy) vcov(fit) ## transformation model parametrization vcov(fit, as.lm = TRUE) ## LMM parametrization vcov(fit, as.lm = TRUE, pargroup = "fixef") ## cov of fixed effects
Extracts the covariance matrix of the selected parameters. The returned values are on the same scale as the estimated parameter values, i.e. the standard deviations of the random effect terms are on log scale.
## S3 method for class 'tramME' vcov( object, parm = NULL, pargroup = c("all", "fixef", "shift", "baseline", "ranef", "smooth"), pmatch = FALSE, ... )
## S3 method for class 'tramME' vcov( object, parm = NULL, pargroup = c("all", "fixef", "shift", "baseline", "ranef", "smooth"), pmatch = FALSE, ... )
object |
A fitted tramME object. |
parm |
The indeces or names of the parameters of interest. See in details. |
pargroup |
The name of the parameter group to return:
|
pmatch |
Logical. If |
... |
Optional arguments passed to |
The argument parm
defines the indices or the names of the parameters
of interest within the selected pargroup
. When pmatch = TRUE
,
partial matching of parameter names is allowed.
A numeric covariance matrix.
data("sleepstudy", package = "lme4") fit <- BoxCoxME(Reaction ~ Days + (Days | Subject), data = sleepstudy, order = 10) vcov(fit) vcov(fit, pargroup = "ranef") vcov(fit, pargroup = "baseline") vcov(fit, parm = "Reaction") ## same as previous
data("sleepstudy", package = "lme4") fit <- BoxCoxME(Reaction ~ Days + (Days | Subject), data = sleepstudy, order = 10) vcov(fit) vcov(fit, pargroup = "ranef") vcov(fit, pargroup = "baseline") vcov(fit, parm = "Reaction") ## same as previous