merlin {merlin} | R Documentation |
merlin - Mixed Effects Regression for Linear, Nonlinear and User-defined models
Description
merlin fits linear, non-linear and user-defined mixed effects regression models. merlin can fit multivariate outcome models of any type, each of which could be repeatedly measured (longitudinal), with any number of levels, and with any number of random effects at each level. Standard distributions/models available include the Bernoulli, Gaussian, Poisson, beta, negative-binomial, and time-to-event/survival models include the exponential, Gompertz, Weibull, Royston-Parmar, and general hazard model. merlin provides a flexible predictor syntax, allowing the user to define variables, random effects, spline and fractional polynomial functions, functions of other outcome models, and any interaction between each of them. Non-linear and time-dependent effects are seamlessly incorporated into the predictor. merlin allows multivariate normal random effects, which are integrated out using Gaussian quadrature or Monte-Carlo integration. Relative survival (excess hazard) models are supported. Utility functions are provided to allow user-defined models to be specified, in conjunction with the complex predictor.
Usage
merlin(
model,
from = NULL,
family = "gaussian",
link = NULL,
timevar = NULL,
covariance = "diagonal",
data,
userf = NULL,
sweights = NULL,
levels = NULL,
predict = FALSE,
predtype = NULL,
predmodel = NULL,
causes = NULL,
at = NULL,
contrast = NULL,
modelfit = NULL,
control = list()
)
Arguments
model |
specify the fixed and random elements for each model outcome.
Where there are multiple outcomes, the models should be specified in a list.
Each model should be specified as a formula (e.g.
|
from |
this is an optional argument giving the initial values for the full parameter vector, for more details on how to specify the initial estimates see the vignette. |
family |
a vector of strings specifying the family for each outcome specified in model. The currently available models include,
with survival models including,
and user-defined,
|
link |
string vector defining the link functions for each model.
Default is |
timevar |
specifies the variable which represents time, this is necessary when a function of time is used in the linear predictor of a survival model as it may interact with other elements of the model. |
covariance |
the structure of the variance-covariance matrix can be varied, the default is |
data |
a data frame containing all variables required for fitting the model.
Can be a |
userf |
string vector defining the name of the user-written functions for each |
sweights |
Not documented. |
levels |
if the model contains random-effects then a vector giving the order of levels must be specified, from the highest level to the lowest, e.g. |
predict |
Not documented. |
predtype |
Not documented. |
predmodel |
Not documented. |
causes |
Not documented. |
at |
Not documented. |
contrast |
Not documented. |
modelfit |
Not documented. |
control |
A list of parameters that control the estimation algorithm. Generally it should not be modified, unless there are convergence issues. Possible values are:
|
Author(s)
Emma C. Martin, Alessandro Gasparini and Michael J. Crowther
References
Crowther MJ. Extended multivariate generalised linear and non-linear mixed effects models. https://arxiv.org/abs/1710.02223
Crowther MJ. merlin - a unified framework for data analysis and methods development in Stata. https://arxiv.org/abs/1806.01615
Martin EC, Gasparini A, Crowther MJ. merlin - an R package for mixed effects regression of linear, non-linear and user-defined models.
See Also
merlin_util_depvar
, merlin_util_timevar
,
merlin_util_xzb
, merlin_util_xzb_mod
merlin_util_xzb_deriv
, merlin_util_xzb_deriv_mod
merlin_util_xzb_deriv2
, merlin_util_xzb_deriv2_mod
merlin_util_xzb_integ
, merlin_util_xzb_integ_mod
merlin_util_ev
, merlin_util_ev_mod
merlin_util_ev_deriv
, merlin_util_ev_deriv_mod
merlin_util_ev_deriv2
, merlin_util_ev_deriv2_mod
merlin_util_ev_integ
, merlin_util_ev_integ_mod
merlin_util_ap
, merlin_util_ap_mod
Examples
## Not run:
library(merlin)
data(pbc.merlin, package = "merlin")
# Linear fixed-effects model
merlin(logb ~ year,
family = "gaussian",
data = pbc.merlin)
# Linear mixed-effects model with random intercept and slope at ID level
merlin(logb ~ year + M1[id] * 1 + year:M2[id] * 1,
family = "gaussian",
levels = "id",
data = pbc.merlin)
# Joint longitudinal and survival model with shared random effects
merlin(model = list(logb ~ year + M1[id] * 1,
Surv(stime, died) ~ trt + M1[id]),
family = c("gaussian", "weibull"),
levels = "id",
data = pbc.merlin)
# Joint longitudinal and survival model with expected value
merlin(model = list(logb ~ year + M1[id] * 1,
Surv(stime, died) ~ trt + EV[logb]),
family = c("gaussian", "weibull"),
levels = "id",
timevar = c("year","stime"),
data = pbc.merlin)
# Gaussian distribution - implemented as a user-written family
logl_gaussian <- function(gml)
{
y <- merlin_util_depvar(gml)
xzb <- merlin_util_xzb(gml)
se <- exp(merlin_util_ap(gml,1))
mu <- (sweep(xzb,1,y,"-"))^2
logl <- ((-0.5 * log(2*pi) - log(se)) - (mu/(2 * se^2)))
return(logl)
}
merlin(logb ~ year + ap(1), family = "user", data = pbc.merlin,
userf = "logl_gaussian")
# 3-level Weibull model
merlin(Surv(stime1,dead1) ~ age + M1[id1]*1 + M2[id2]*1,
levels=c("id1","id2"), family="weibull", data=sim3)
## End(Not run)