Title: | Singular Linear Models for Longitudinal Data |
---|---|
Description: | Fits singular linear models to longitudinal data. Singular linear models are useful when the number, or timing, of longitudinal observations may be informative about the observations themselves. They are described in Farewell (2010) <doi:10.1093/biomet/asp068>, and are extensions of the linear increments model <doi:10.1111/j.1467-9876.2007.00590.x> to general longitudinal data. |
Authors: | Daniel Farewell [aut, cre] |
Maintainer: | Daniel Farewell <[email protected]> |
License: | GPL-3 |
Version: | 0.1.1 |
Built: | 2024-12-03 06:33:26 UTC |
Source: | CRAN |
The slim package fits singular linear models to longitudinal data. Singular linear models are useful when the number, or timing, of longitudinal observations may be informative about the observations themselves. They are described in Farewell (2010) <doi:10.1093/biomet/asp068>, and are extensions of the linear increments model of Diggle et al. (2007) <doi:10.1111/j.1467-9876.2007.00590.x> to general longitudinal data.
The most important function is slim, whose formula interface is similar to that of lm.
Extract Model Coefficients from Singular Linear Model
## S3 method for class 'slim' coef(object, ...)
## S3 method for class 'slim' coef(object, ...)
object |
an object of class 'slim', usually, a result of a call to 'slim'. |
... |
arguments passed to or from other methods. |
a vector of model coefficients.
This function computes the first two terms of the Laurent expansion of the inverse of a linear matrix function.
compute_laurent(V, zapsmall = TRUE)
compute_laurent(V, zapsmall = TRUE)
V |
for some integer m >= 1, an array of dimension (m, m, 2), where V[, , 1] is the intercept and V[, , 2] is the slope of the linear matrix function. |
zapsmall |
logical: should zapsmall be called on the result? Default TRUE. |
array of dimension (m, m, 2), where W[, , 1] corresponds to the exponent -1, and W[, , 2] corresponds to the exponent 0.
Confidence Intervals for Model Parameters from Singular Linear Model
## S3 method for class 'slim' confint(object, parm, level = 0.95, empirical = TRUE, ...)
## S3 method for class 'slim' confint(object, parm, level = 0.95, empirical = TRUE, ...)
object |
an object of class 'slim', usually, a result of a call to 'slim'. |
parm |
a specification of which parameters are to be given confidence intervals, either a vector of numbers or a vector of names. If missing, all parameters are considered. |
level |
the confidence level required. |
empirical |
logical indicating if empirical variances of y should be used in estimating standard errors (the default). Empirical standard errors should be used unless covariances have been well modelled. |
... |
arguments passed to or from other methods. |
A matrix (or vector) with columns giving lower and upper confidence limits for each parameter.
Longitudinal data on the renal function of 116 patients observed on up to five different occasions.
dialysis
dialysis
A data.table with 116 rows and 5 variables:
id | patient identifier, a character string |
group | treatment group identifier, a character string |
vintage | days since starting dialysis, an integer |
month | month of observation, an integer |
renalfn | renal function of the patient at that month, numeric |
This data is derived from the Global Fluid Study. This part of the study was led by Dr James Chess and Prof. Nick Topley.
Lambie, M., Chess, J. et al. (2013). Independent effects of systemic and peritoneal inflammation on peritoneal dialysis survival. J Am Soc Nephrol, 24, 2071–80.
This function computes the limiting solution to the estimating equation sum(x' V^-1 (y - x beta)) = 0 as the covariance V tends from V[, , 1] + V[, , 2] to V[, , 1].
fit_slim(x, V, y)
fit_slim(x, V, y)
x |
list of design matrices, one for each subject, all having the same number of columns. |
V |
list of covariance arrays, one for each subject, matching the dimensions of y. |
y |
list of response vectors, one for each subject. |
a list with components coefficients (the limiting solution), residuals, fitted_values, vcov_empirical and vcov_modelled.
Extract Model Fitted Values from Singular Linear Model
## S3 method for class 'slim' fitted(object, ...)
## S3 method for class 'slim' fitted(object, ...)
object |
an object of class 'slim', usually, a result of a call to 'slim'. |
... |
arguments passed to or from other methods. |
a vector of fitted values from the model fit.
This function is generic, and methods exists for character, list, function, and various model fit classes.
list_covariances(obj, t) ## S3 method for class 'character' list_covariances(obj, t) ## S3 method for class 'list' list_covariances(obj, t) ## S3 method for class 'function' list_covariances(obj, t) ## S3 method for class 'jmcmMod' list_covariances(obj, t) ## S3 method for class 'lmerMod' list_covariances(obj, t)
list_covariances(obj, t) ## S3 method for class 'character' list_covariances(obj, t) ## S3 method for class 'list' list_covariances(obj, t) ## S3 method for class 'function' list_covariances(obj, t) ## S3 method for class 'jmcmMod' list_covariances(obj, t) ## S3 method for class 'lmerMod' list_covariances(obj, t)
obj |
an R object of class character, function, or a model fit |
t |
list of vectors of observation times, one for each subject |
a list containing covariance matrices of appropriate dimensions
Model Predictions from Singular Linear Model
## S3 method for class 'slim' predict(object, newdata, ...)
## S3 method for class 'slim' predict(object, newdata, ...)
object |
an object of class 'slim', usually, a result of a call to 'slim'. |
newdata |
An optional data frame in which to look for variables with which to predict. If omitted, the fitted values are used. |
... |
arguments passed to or from other methods. |
a vector of model predictions.
'print' methods for class 'slim' and 'slim_summary'. 'print.slim_summary' differs only in its default value of 'empirical'.
## S3 method for class 'slim' print(x, empirical = TRUE, digits = max(3, getOption("digits") - 3), signif.stars = getOption("show.signif.stars"), ...) ## S3 method for class 'slim_summary' print(x, empirical = x$empirical, ...)
## S3 method for class 'slim' print(x, empirical = TRUE, digits = max(3, getOption("digits") - 3), signif.stars = getOption("show.signif.stars"), ...) ## S3 method for class 'slim_summary' print(x, empirical = x$empirical, ...)
x |
an object of class 'slim' or 'slim_summary', as appropriate. |
empirical |
logical indicating if empirical variances of y should be used in estimating standard errors (the default). Empirical standard errors should be used unless covariances have been well modelled. |
digits |
minimal number of significant digits, see
|
signif.stars |
logical. If |
... |
arguments passed to or from other methods. |
x, invisibly.
Extract Model Residuals from Singular Linear Model
## S3 method for class 'slim' residuals(object, ...)
## S3 method for class 'slim' residuals(object, ...)
object |
an object of class 'slim', usually, a result of a call to 'slim'. |
... |
arguments passed to or from other methods. |
a vector of model residuals.
Fit a singular linear model to longitudinal data.
slim(formula, data, covariance = "randomwalk", limit = ~1, contrasts = NULL)
slim(formula, data, covariance = "randomwalk", limit = ~1, contrasts = NULL)
formula |
a model formula for the fixed effects |
data |
a 'data.table' with two keys, respectively identifying subjects and observation times |
covariance |
an R object for which a 'list_covariances' method exists. Options include a character string such as "identity", "randomwalk" (the default), "brownian" or "pascal"; a list of covariance matrices; a function to be used in 'outer' and applied to the observation times; or a 'jmcmMod' or 'lmerMod' model fit. |
limit |
a one-sided model formula for the (thin) Cholesky factor of the limiting covariance matrix (default ~ 1, so the limiting covariance matrix is the matrix of ones) |
contrasts |
an optional list. See the 'contrasts.arg' argument of 'model.matrix.default'. |
an object of class 'slim'
slim_fit <- slim(renalfn ~ group + month, dialysis) summary(slim_fit) if(require("lme4")) { lmer_fit <- lmer(renalfn ~ group + month + (1 + month | id), dialysis) slim_fit <- slim(renalfn ~ 1 + group + month, dialysis, covariance = lmer_fit) summary(slim_fit) summary(slim_fit, empirical = FALSE) } if(require("jmcm")) { jmcm_fit <- jmcm(renalfn | id | month ~ group | 1, dialysis, triple = rep(2L, 3), cov.method = "mcd") slim_fit <- slim(renalfn ~ group + month, dialysis, covariance = jmcm_fit) summary(slim_fit) summary(slim_fit, empirical = FALSE) }
slim_fit <- slim(renalfn ~ group + month, dialysis) summary(slim_fit) if(require("lme4")) { lmer_fit <- lmer(renalfn ~ group + month + (1 + month | id), dialysis) slim_fit <- slim(renalfn ~ 1 + group + month, dialysis, covariance = lmer_fit) summary(slim_fit) summary(slim_fit, empirical = FALSE) } if(require("jmcm")) { jmcm_fit <- jmcm(renalfn | id | month ~ group | 1, dialysis, triple = rep(2L, 3), cov.method = "mcd") slim_fit <- slim(renalfn ~ group + month, dialysis, covariance = jmcm_fit) summary(slim_fit) summary(slim_fit, empirical = FALSE) }
Methods for Singular Linear Model Fits
object |
an object of class 'slim', usually, a result of a call to 'slim'. |
empirical |
logical indicating if empirical variances of y should be used in estimating standard errors (the default). Empirical standard errors should be used unless covariances have been well modelled. |
... |
arguments passed to or from other methods. |
'summary' method for class 'slim'.
## S3 method for class 'slim' summary(object, empirical = TRUE, ...)
## S3 method for class 'slim' summary(object, empirical = TRUE, ...)
object |
an object of class 'slim', usually, a result of a call to 'slim'. |
empirical |
logical indicating if empirical variances of y should be used in estimating standard errors (the default). Empirical standard errors should be used unless covariances have been well modelled. |
... |
arguments passed to or from other methods. |
an object with class c("slim_summary", "slim") and, in addition to the usual 'slim' components, coefficient_matrix (the matrix of estimated coefficients, standard errors, z- and p-values) and empirical (logical indicating if empirical standard errors have been used)
'vcov' method for class 'slim'.
## S3 method for class 'slim' vcov(object, empirical = TRUE, ...)
## S3 method for class 'slim' vcov(object, empirical = TRUE, ...)
object |
an object of class 'slim', usually, a result of a call to 'slim'. |
empirical |
logical indicating if empirical variances of y should be used in estimating standard errors (the default). Empirical standard errors should be used unless covariances have been well modelled. |
... |
arguments passed to or from other methods. |
a matrix of the estimated covariances between the parameter estimates.