predict.tramME {tramME} | R Documentation |
Predict method for tramME objects
Description
Evaluates the _conditional_ distribution implied by a tramME model, given by a set of covariates and random effects on a selected scale.
Usage
## S3 method for class 'tramME'
predict(
object,
newdata = model.frame(object),
ranef = NULL,
fix_smooth = TRUE,
type = c("lp", "trafo", "distribution", "logdistribution", "survivor", "logsurvivor",
"density", "logdensity", "hazard", "loghazard", "cumhazard", "logcumhazard", "odds",
"logodds", "quantile"),
...
)
Arguments
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 |
Details
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.
Value
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"
).
Examples
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)