Title: | Mixed Effects Regression for Linear, Non-Linear and User-Defined Models |
---|---|
Description: | Fits linear, non-linear, and user-defined mixed effects regression models following the framework developed by Crowther (2017) <arXiv:1710.02223>. '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, Royston-Parmar, Weibull 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. Note, 'merlin' is based on the 'Stata' package of the same name, described in Crowther (2018) <arXiv:1806.01615>. |
Authors: | Emma Martin [aut], Alessandro Gasparini [aut], Michael Crowther [aut, cre] |
Maintainer: | Michael Crowther <[email protected]> |
License: | GPL (>= 3) |
Version: | 0.1.0 |
Built: | 2024-11-22 08:31:05 UTC |
Source: | https://github.com/cranhaven/cranhaven.r-universe.dev |
coef
extracts model coefficients from a merlin
model fit. coefficients
is an alias for it.
## S3 method for class 'merlin' coef(object, ...) ## S3 method for class 'summary.merlin' coef(object, ...)
## S3 method for class 'merlin' coef(object, ...) ## S3 method for class 'summary.merlin' coef(object, ...)
object |
An object of class |
... |
Not used. |
coef
extracts model coefficients from a mlrcs
model fit. coefficients
is an alias for it.
## S3 method for class 'mlrcs' coef(object, ...) ## S3 method for class 'summary.mlrcs' coef(object, ...)
## S3 method for class 'mlrcs' coef(object, ...) ## S3 method for class 'summary.mlrcs' coef(object, ...)
object |
An object of class |
... |
Not used. |
coef
extracts model coefficients from a mlsurv
model fit. coefficients
is an alias for it.
## S3 method for class 'mlsurv' coef(object, ...) ## S3 method for class 'summary.mlsurv' coef(object, ...)
## S3 method for class 'mlsurv' coef(object, ...) ## S3 method for class 'summary.mlsurv' coef(object, ...)
object |
An object of class |
... |
Not used. |
This is longitudinal data on an observational study on detecting effects of different heart valves, differing on type of tissue, implanted in the aortic position. The data consists of longitudinal measurements on three different heart function outcomes, after surgery occurred. There are several baseline covariates available, and also survival data.
data(heart.valve) data(heart.valve.merlin)
data(heart.valve) data(heart.valve.merlin)
This is a data frame in the unbalanced format, that is, with one row per observation. The data consists in columns for patient identification, time of measurements, longitudinal multiple longitudinal measurements, baseline covariates, and survival data. The column names are identified as follows:
num
number for patient identification.
sex
gender of patient (0=
Male and 1=
Female).
age
age of patient at day of surgery (years).
time
observed time point, with surgery date as the time origin (years).
fuyrs
maximum follow up time, with surgery date as the time origin (years).
status
censoring indicator (1=
died and 0=
lost at follow up).
grad
valve gradient at follow-up visit.
log.grad
natural log transformation of grad
.
lvmi
left ventricular mass index (standardised) at follow-up visit.
log.lvmi
natural log transformation of lvmi
.
ef
ejection fraction at follow-up visit.
bsa
preoperative body surface area.
lvh
preoperative left ventricular hypertrophy.
prenyha
preoperative New York Heart Association (NYHA) classification (1=
I/II and 3=
III/IV).
redo
previous cardiac surgery.
size
size of the valve (millimetres).
con.cabg
concomitant coronary artery bypass graft.
creat
preoperative serum creatinine (mol/mL).
dm
preoperative diabetes.
acei
preoperative use of ace inhibitor.
lv
preoperative left ventricular ejection fraction (LVEF) (1=
good, 2=
moderate, and 3=
poor).
emergenc
operative urgency (0=
elective, 1=
urgent, and 3=
emergency).
hc
preoperative high cholesterol (0=
absent, 1=
present treated, and 2=
present untreated).
sten.reg.mix
aortic valve haemodynamics (1=
stenosis, 2=
regurgitation, 3=
mixed).
hs
implanted aortic prosthesis type (1=
homograft and 0=
stentless porcine tissue).
An object of class data.frame
with 629 rows and 29 columns.
heart.valve.merlin
is a version of the heart.valve
dataset in merlin
format.
Mr Eric Lim (http://www.drericlim.com)
Lim E, Ali A, Theodorou P, Sousa I, Ashrafian H, Chamageorgakis T, Duncan M, Diggle P, Pepper J. A longitudinal study of the profile and predictors of left ventricular mass regression after stentless aortic valve replacement. Ann Thorac Surg. 2008; 85(6): 2026-2029.
Extract log-likelihood of a merlin
model.
## S3 method for class 'merlin' logLik(object, ...) ## S3 method for class 'summary.merlin' logLik(object, ...)
## S3 method for class 'merlin' logLik(object, ...) ## S3 method for class 'summary.merlin' logLik(object, ...)
object |
An object of class |
... |
Not used. |
Extract log-likelihood of a mlrcs
model.
## S3 method for class 'mlrcs' logLik(object, ...) ## S3 method for class 'summary.mlrcs' logLik(object, ...)
## S3 method for class 'mlrcs' logLik(object, ...) ## S3 method for class 'summary.mlrcs' logLik(object, ...)
object |
An object of class |
... |
Not used. |
Extract log-likelihood of a mlsurv
model.
## S3 method for class 'mlsurv' logLik(object, ...) ## S3 method for class 'summary.mlsurv' logLik(object, ...)
## S3 method for class 'mlsurv' logLik(object, ...) ## S3 method for class 'summary.mlsurv' logLik(object, ...)
object |
An object of class |
... |
Not used. |
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.
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() )
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() )
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:
|
Emma C. Martin, Alessandro Gasparini and Michael J. Crowther
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.
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
## 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)
## 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)
merlin_util_ap - returns the current estimate of the ith ancillary parameter for the associated model
merlin_util_ap(gml, i)
merlin_util_ap(gml, i)
gml |
merlin object - should not be edited |
i |
index for which ancillary parameter to extract |
Michael J. Crowther
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 and non-linear models.
merlin_util_ap_mod - returns the current estimate of the ith ancillary parameter for the specified model
merlin_util_ap_mod(gml, m, i)
merlin_util_ap_mod(gml, m, i)
gml |
merlin object - should not be edited |
m |
specifies the merlin submodel |
i |
index for which ancillary parameter to extract |
Michael J. Crowther
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 and non-linear models.
Utility function to extract the dependent variable(s) for the current model. If the model is a survival/time-to-event model, then it will contain the event times in the first column and the event indicator in the second.
merlin_util_depvar(gml)
merlin_util_depvar(gml)
gml |
merlin object - should not be edited |
Emma C. Martin, Alessandro Gasparini and Michael J. Crowther
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 and non-linear models.
Utility function to extract the expected value of the outcome at the current parameter estimates for a particular model.
merlin_util_ev(gml, t = NULL)
merlin_util_ev(gml, t = NULL)
gml |
merlin object - should not be edited |
t |
specifies the variable which represents time |
Michael J. Crowther
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 and non-linear models.
Utility function to extract d/dt of the expected value of the outcome at the current parameter estimates for a particular model.
merlin_util_ev_deriv(gml, t = NULL)
merlin_util_ev_deriv(gml, t = NULL)
gml |
merlin object - should not be edited |
t |
specifies the variable which represents time |
Michael J. Crowther
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 and non-linear models.
library(merlin) data(pbc.merlin, package = "merlin") # Linear fixed-effects model merlin(model = list(logb ~ year), family = "gaussian", data = pbc.merlin)
library(merlin) data(pbc.merlin, package = "merlin") # Linear fixed-effects model merlin(model = list(logb ~ year), family = "gaussian", data = pbc.merlin)
Utility function to extract d/dt of the expected value of the outcome at the current parameter estimates for a specified model.
merlin_util_ev_deriv_mod(gml, m, t = NULL)
merlin_util_ev_deriv_mod(gml, m, t = NULL)
gml |
merlin object - should not be edited |
m |
specifies the merlin submodel |
t |
specifies the variable which represents time |
Michael J. Crowther
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 and non-linear models.
merlin_util_ev_deriv2 - returns the second derivative with respect to time of the observation-level expected value of the outcome
merlin_util_ev_deriv2(gml, t = NULL)
merlin_util_ev_deriv2(gml, t = NULL)
gml |
merlin object - should not be edited |
t |
specifies the variable which represents time |
Michael J. Crowther
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 and non-linear models.
merlin_util_ev_deriv2_mod - returns the second derivative with respect to time of the observation-level expected value of the specified outcome
merlin_util_ev_deriv2_mod(gml, m, t = NULL)
merlin_util_ev_deriv2_mod(gml, m, t = NULL)
gml |
merlin object - should not be edited |
m |
specifies the merlin submodel |
t |
specifies the variable which represents time |
Michael J. Crowther
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 and non-linear models.
merlin_util_ev_integ - returns the integral with respect to time of the observation-level expected value of the outcome
merlin_util_ev_integ(gml, t = NULL)
merlin_util_ev_integ(gml, t = NULL)
gml |
merlin object - should not be edited |
t |
specifies the variable which represents time |
Michael J. Crowther
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 and non-linear models.
merlin_util_ev_integ_mod - returns the integral with respect to time of the observation-level expected value of the specified outcome
merlin_util_ev_integ_mod(gml, m, t = NULL)
merlin_util_ev_integ_mod(gml, m, t = NULL)
gml |
merlin object - should not be edited |
m |
specifies the merlin submodel |
t |
specifies the variable which represents time |
Michael J. Crowther
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 and non-linear models.
Utility function to extract the expected value of the outcome at the current parameter estimates for a specified model.
merlin_util_ev_mod(gml, m, t = NULL)
merlin_util_ev_mod(gml, m, t = NULL)
gml |
merlin object - should not be edited |
m |
specifies the model |
t |
specifies the variable which represents time |
Michael J. Crowther
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 and non-linear models.
Utility function to extract the time variable(s) for the current model.
merlin_util_timevar(gml)
merlin_util_timevar(gml)
gml |
merlin object - should not be edited |
Michael J. Crowther
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 and non-linear models.
Utility function to extract the complex predictor evaluated at the current parameter estimates for a particular model.
merlin_util_xzb(gml, t = NULL)
merlin_util_xzb(gml, t = NULL)
gml |
merlin object - should not be edited |
t |
specifies the variable which represents time |
Emma C. Martin, Alessandro Gasparini and Michael J. Crowther
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 and non-linear models.
library(merlin) data(pbc.merlin, package = "merlin") # Linear fixed-effects model merlin(model = list(logb ~ year), family = "gaussian", data = pbc.merlin)
library(merlin) data(pbc.merlin, package = "merlin") # Linear fixed-effects model merlin(model = list(logb ~ year), family = "gaussian", data = pbc.merlin)
Utility function to extract d/dt of the complex predictor evaluated at the current parameter estimates for a particular model.
merlin_util_xzb_deriv(gml, t = NULL)
merlin_util_xzb_deriv(gml, t = NULL)
gml |
merlin object - should not be edited |
t |
specifies the variable which represents time |
Michael J. Crowther
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 and non-linear models.
library(merlin) data(pbc.merlin, package = "merlin") # Linear fixed-effects model merlin(model = list(logb ~ year), family = "gaussian", data = pbc.merlin)
library(merlin) data(pbc.merlin, package = "merlin") # Linear fixed-effects model merlin(model = list(logb ~ year), family = "gaussian", data = pbc.merlin)
merlin_util_xzb_deriv_mod - returns the first derivative with respect to time of the observation-level complex predictor of a specified model
merlin_util_xzb_deriv_mod(gml, m, t = NULL)
merlin_util_xzb_deriv_mod(gml, m, t = NULL)
gml |
merlin object - should not be edited |
m |
specifies the merlin submodel |
t |
specifies the variable which represents time |
Michael J. Crowther
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 and non-linear models.
merlin_util_xzb_deriv2 - returns the second derivative with respect to time of the observation-level complex predictor
merlin_util_xzb_deriv2(gml, t = NULL)
merlin_util_xzb_deriv2(gml, t = NULL)
gml |
merlin object - should not be edited |
t |
specifies the variable which represents time |
Michael J. Crowther
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 and non-linear models.
merlin_util_xzb_deriv2_mod - returns the second derivative with respect to time of the observation-level complex predictor of the specified model
merlin_util_xzb_deriv2_mod(gml, m, t = NULL)
merlin_util_xzb_deriv2_mod(gml, m, t = NULL)
gml |
merlin object - should not be edited |
m |
specifies the merlin submodel |
t |
specifies the variable which represents time |
Michael J. Crowther
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 and non-linear models.
merlin_util_xzb_integ - returns the integral with respect to time of the observation-level complex predictor
merlin_util_xzb_integ(gml, t = NULL)
merlin_util_xzb_integ(gml, t = NULL)
gml |
merlin object - should not be edited |
t |
specifies the variable which represents time |
Michael J. Crowther
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 and non-linear models.
merlin_util_xzb_integ_mod - returns the integral with respect to time of the observation-level complex predictor of the specified model
merlin_util_xzb_integ_mod(gml, m, t = NULL)
merlin_util_xzb_integ_mod(gml, m, t = NULL)
gml |
merlin object - should not be edited |
m |
specifies the merlin submodel |
t |
specifies the variable which represents time |
Michael J. Crowther
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 and non-linear models.
Utility function to extract the complex predictor evaluated at the current parameter estimates for a particular model.
merlin_util_xzb_mod(gml, m, t = NULL)
merlin_util_xzb_mod(gml, m, t = NULL)
gml |
merlin object - should not be edited |
m |
specifies the merlin submodel |
t |
specifies the variable which represents time |
Michael J. Crowther
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 and non-linear models.
Fit multi-level restricted cubic spline model
mlrcs(formula, random = NULL, data, ...)
mlrcs(formula, random = NULL, data, ...)
formula |
A model formula for the fixed-effects in the model. Must include one restricted cubic spline term, specified as |
random |
A formula for the random-effects in the model. Random-effects should be specified as a one-sided formula, e.g. |
data |
A data frame containing all variables required for fitting the model. |
... |
Further arguments passed to merlin. |
An object of class mlrcs
.
## Not run: # Two-level model data("pbc.merlin", package = "merlin") fit <- mlrcs(formula = logp ~ 1 + rcs(year, df = 4) + age + trt, random = ~ 1 + trt | id, data = pbc.merlin ) summary(fit) # Three-level model fit <- mlrcs(formula = logp ~ 1 + rcs(year, df = 4) + age + trt, random = list(~ 1 | region, ~ 1 + trt | id), data = pbc.merlin ) summary(fit) ## End(Not run)
## Not run: # Two-level model data("pbc.merlin", package = "merlin") fit <- mlrcs(formula = logp ~ 1 + rcs(year, df = 4) + age + trt, random = ~ 1 + trt | id, data = pbc.merlin ) summary(fit) # Three-level model fit <- mlrcs(formula = logp ~ 1 + rcs(year, df = 4) + age + trt, random = list(~ 1 | region, ~ 1 + trt | id), data = pbc.merlin ) summary(fit) ## End(Not run)
Fit proportional hazards survival models
mlsurv( formula, distribution, df = NULL, powers = NULL, rcs = TRUE, data, from.null = NULL, ... )
mlsurv( formula, distribution, df = NULL, powers = NULL, rcs = TRUE, data, from.null = NULL, ... )
formula |
A model formula, where the left-hand side is a Surv object. |
distribution |
A parametric distribution for the baseline hazard.
Possible values are |
df |
Represents the number of degrees of freedom used for the restricted cubic splines when flexibly modelling the baseline hazard.
Only required when |
powers |
A vector representing the degree of the fractional polynomials used to model the baseline hazard (with a maximum degree of 2).
Only required when |
rcs |
Use restricted cubic splines when flexibly modelling the baseline hazard? Defaults to |
data |
A data frame containing all variables required for fitting the model.
Can be a |
from.null |
A vector of starting values for the null model (used to get improved starting values). This is mostly useful when experiencing issues with default starting values or convergence issues. |
... |
Further arguments passed to merlin. |
An object of class mlsurv
.
# Weibull model library(survival) data("pbc.merlin", package = "merlin") fit <- mlsurv( formula = Surv(stime, died) ~ trt, distribution = "weibull", data = pbc.merlin ) summary(fit) # Royston-Parmar model with 3 degrees of freedom fit <- mlsurv( formula = Surv(stime, died) ~ trt, distribution = "rp", df = 3, data = pbc.merlin ) summary(fit) ## Not run: # Flexible parametric model on the log-hazard scale with fractional polynomials fit <- mlsurv( formula = Surv(stime, died) ~ trt, distribution = "loghazard", powers = c(0, 1), rcs = FALSE, data = pbc.merlin ) summary(fit) ## End(Not run)
# Weibull model library(survival) data("pbc.merlin", package = "merlin") fit <- mlsurv( formula = Surv(stime, died) ~ trt, distribution = "weibull", data = pbc.merlin ) summary(fit) # Royston-Parmar model with 3 degrees of freedom fit <- mlsurv( formula = Surv(stime, died) ~ trt, distribution = "rp", df = 3, data = pbc.merlin ) summary(fit) ## Not run: # Flexible parametric model on the log-hazard scale with fractional polynomials fit <- mlsurv( formula = Surv(stime, died) ~ trt, distribution = "loghazard", powers = c(0, 1), rcs = FALSE, data = pbc.merlin ) summary(fit) ## End(Not run)
This data is from the Mayo Clinic trial in primary biliary cirrhosis (PBC) of the liver conducted between 1974 and 1984. A total of 424 PBC patients, referred to Mayo Clinic during that ten-year interval met eligibility criteria for the randomized placebo controlled trial of the drug D-penicillamine, but only the first 312 cases in the data set participated in the randomized trial. Therefore, the data here are for the 312 patients with largely complete data.
data(pbc) data(pbc.merlin)
data(pbc) data(pbc.merlin)
A data frame with 1945 observations on the following 20 variables:
id
patients identifier; in total there are 312 patients.
years
number of years between registration and the earlier of death, transplantation, or study analysis time.
status
a factor with levels alive
, transplanted
and dead
.
drug
a factor with levels placebo
and D-penicil
.
age
at registration in years.
sex
a factor with levels male
and female
.
year
number of years between enrollment and this visit date, remaining values on the line of data refer to this visit.
ascites
a factor with levels No
and Yes
.
hepatomegaly
a factor with levels No
and Yes
.
spiders
a factor with levels No
and Yes
.
edema
a factor with levels No edema
(i.e. no edema and no diuretic therapy for edema), edema no diuretics
(i.e. edema present without diuretics, or edema resolved by diuretics), and edema despite diuretics
(i.e. edema despite diuretic therapy).
serBilir
serum bilirubin in mg/dl.
serChol
serum cholesterol in mg/dl.
albumin
albumin in mg/dl.
alkaline
alkaline phosphatase in U/liter.
SGOT
SGOT in U/ml.
platelets
platelets per cubic ml/1000.
prothrombin
prothrombin time in seconds.
histologic
histologic stage of disease.
status2
a numeric vector with the value 1 denoting if the patient was dead, and 0 if the patient was alive or transplanted.
An object of class data.frame
with 1945 rows and 25 columns.
pbc.merlin
is a version of the pbc
dataset in merlin
format.
pbc
.
Fleming T, Harrington D. Counting Processes and Survival Analysis. 1991; New York: Wiley.
Therneau T, Grambsch P. Modeling Survival Data: Extending the Cox Model. 2000; New York: Springer-Verlag.
predictions following the fit of a merlin model
## S3 method for class 'merlin' predict( object, stat = "eta", type = "fixedonly", predmodel = 1, causes = NULL, at = NULL, contrast = NULL, ... )
## S3 method for class 'merlin' predict( object, stat = "eta", type = "fixedonly", predmodel = 1, causes = NULL, at = NULL, contrast = NULL, ... )
object |
merlin model object |
stat |
specifies which prediction, which can be one of:
|
type |
the type of prediction, either:
|
predmodel |
specifies which model to obtain predictions from; default is |
causes |
is for use when calculating predictions from a competing risks |
at |
specify covariate values for prediction. Fixed values of covariates should be specified in a list e.g. at = c("trt" = 1, "age" = 50). |
contrast |
specifies the values of a covariate to be used when comparing statistics,
such as when using the |
... |
other options |
Emma C. Martin, Alessandro Gasparini and Michael J. Crowther
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.
library(merlin) data(pbc.merlin, package = "merlin") # Linear fixed-effects model mod <-merlin(model = list(logb ~ year), family = "gaussian", data = pbc.merlin) predict(mod,stat="eta",type="fixedonly")
library(merlin) data(pbc.merlin, package = "merlin") # Linear fixed-effects model mod <-merlin(model = list(logb ~ year), family = "gaussian", data = pbc.merlin) predict(mod,stat="eta",type="fixedonly")
merlin
FitsPrint the coefficients from a merlin
fit.
## S3 method for class 'merlin' print(x, digits = max(3L, getOption("digits") - 3L), ...)
## S3 method for class 'merlin' print(x, digits = max(3L, getOption("digits") - 3L), ...)
x |
An object of class |
digits |
The number of significant digits to use when printing. |
... |
Not used. |
mlrcs
FitsPrint the coefficients from a mlrsc
fit.
## S3 method for class 'mlrcs' print(x, digits = max(3L, getOption("digits") - 3L), simplify = TRUE, ...)
## S3 method for class 'mlrcs' print(x, digits = max(3L, getOption("digits") - 3L), simplify = TRUE, ...)
x |
An object of class |
digits |
The number of significant digits to use when printing. |
simplify |
Should non-interpretable coefficients be hidden (e.g. splines and flexible polynomials terms)? Defaults to TRUE. |
... |
Not used. |
mlsurv
FitsPrint the coefficients from a mlsurv
fit.
## S3 method for class 'mlsurv' print(x, digits = max(3L, getOption("digits") - 3L), simplify = TRUE, ...)
## S3 method for class 'mlsurv' print(x, digits = max(3L, getOption("digits") - 3L), simplify = TRUE, ...)
x |
An object of class |
digits |
The number of significant digits to use when printing. |
simplify |
Should non-interpretable coefficients be hidden (e.g. splines and flexible polynomials terms)? Defaults to TRUE. |
... |
Not used. |
Simulated 3-level survival data
data(sim3)
data(sim3)
A data frame...
merlin
FitsThese functions are all methods for class merlin
or summary.merlin
objects.
## S3 method for class 'merlin' summary(object, sig = 0.95, ...) ## S3 method for class 'summary.merlin' print(x, digits = max(3, getOption("digits") - 3), ...)
## S3 method for class 'merlin' summary(object, sig = 0.95, ...) ## S3 method for class 'summary.merlin' print(x, digits = max(3, getOption("digits") - 3), ...)
object |
An object of class |
sig |
Significancy level for confidence intervals. Defaults to 0.95. |
... |
Not used. |
x |
An object of class |
digits |
The number of significant digits to use when printing. |
mlrcs
FitsThese functions are all methods for class mlrcs
or summary.mlrcs
objects.
## S3 method for class 'mlrcs' summary(object, sig = 0.95, ...) ## S3 method for class 'summary.mlrcs' print(x, digits = max(3, getOption("digits") - 3), ...)
## S3 method for class 'mlrcs' summary(object, sig = 0.95, ...) ## S3 method for class 'summary.mlrcs' print(x, digits = max(3, getOption("digits") - 3), ...)
object |
An object of class |
sig |
Significancy level for confidence intervals. Defaults to 0.95. |
... |
Not used. |
x |
An object of class |
digits |
The number of significant digits to use when printing. |
mlsurv
FitsThese functions are all methods for class mlsurv
or summary.mlsurv
objects.
## S3 method for class 'mlsurv' summary(object, sig = 0.95, ...) ## S3 method for class 'summary.mlsurv' print(x, digits = max(3, getOption("digits") - 3), simplify = TRUE, ...)
## S3 method for class 'mlsurv' summary(object, sig = 0.95, ...) ## S3 method for class 'summary.mlsurv' print(x, digits = max(3, getOption("digits") - 3), simplify = TRUE, ...)
object |
An object of class |
sig |
Significancy level for confidence intervals. Defaults to 0.95. |
... |
Not used. |
x |
An object of class |
digits |
The number of significant digits to use when printing. |
simplify |
Should non-interpretable coefficients be hidden (e.g. splines and flexible polynomials terms)? Defaults to TRUE. |
merlin
Model ObjectReturns the variance-covariance matrix of all estimated parameters of a fitted merlin
model.
## S3 method for class 'merlin' vcov(object, ...) ## S3 method for class 'summary.merlin' vcov(object, ...)
## S3 method for class 'merlin' vcov(object, ...) ## S3 method for class 'summary.merlin' vcov(object, ...)
object |
An object of class |
... |
Not used. |
mlrcs
Model ObjectReturns the variance-covariance matrix of all estimated parameters of a fitted mlrcs
model.
## S3 method for class 'mlrcs' vcov(object, ...) ## S3 method for class 'summary.mlrcs' vcov(object, ...)
## S3 method for class 'mlrcs' vcov(object, ...) ## S3 method for class 'summary.mlrcs' vcov(object, ...)
object |
An object of class |
... |
Not used. |
mlsurv
Model ObjectReturns the variance-covariance matrix of all estimated parameters of a fitted mlsurv
model.
## S3 method for class 'mlsurv' vcov(object, ...) ## S3 method for class 'summary.mlsurv' vcov(object, ...)
## S3 method for class 'mlsurv' vcov(object, ...) ## S3 method for class 'summary.mlsurv' vcov(object, ...)
object |
An object of class |
... |
Not used. |