Package 'slim'

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

Help Index


Singular linear models for longitudinal data.

Description

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.

Details

The most important function is slim, whose formula interface is similar to that of lm.

See Also

slim


Extract Model Coefficients from Singular Linear Model

Description

Extract Model Coefficients from Singular Linear Model

Usage

## S3 method for class 'slim'
coef(object, ...)

Arguments

object

an object of class 'slim', usually, a result of a call to 'slim'.

...

arguments passed to or from other methods.

Value

a vector of model coefficients.


Laurent Expansion of Inverse of Linear Matrix Function

Description

This function computes the first two terms of the Laurent expansion of the inverse of a linear matrix function.

Usage

compute_laurent(V, zapsmall = TRUE)

Arguments

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.

Value

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

Description

Confidence Intervals for Model Parameters from Singular Linear Model

Usage

## S3 method for class 'slim'
confint(object, parm, level = 0.95, empirical = TRUE, ...)

Arguments

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.

Value

A matrix (or vector) with columns giving lower and upper confidence limits for each parameter.


Renal Function in Three Groups of Peritoneal Dialysis Patients

Description

Longitudinal data on the renal function of 116 patients observed on up to five different occasions.

Usage

dialysis

Format

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

Source

This data is derived from the Global Fluid Study. This part of the study was led by Dr James Chess and Prof. Nick Topley.

References

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.


Fitter Function for Singular Linear Models

Description

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].

Usage

fit_slim(x, V, y)

Arguments

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.

Value

a list with components coefficients (the limiting solution), residuals, fitted_values, vcov_empirical and vcov_modelled.


Extract Model Fitted Values from Singular Linear Model

Description

Extract Model Fitted Values from Singular Linear Model

Usage

## S3 method for class 'slim'
fitted(object, ...)

Arguments

object

an object of class 'slim', usually, a result of a call to 'slim'.

...

arguments passed to or from other methods.

Value

a vector of fitted values from the model fit.


List Covariance Matrices for Every Subject

Description

This function is generic, and methods exists for character, list, function, and various model fit classes.

Usage

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)

Arguments

obj

an R object of class character, function, or a model fit

t

list of vectors of observation times, one for each subject

Value

a list containing covariance matrices of appropriate dimensions


Model Predictions from Singular Linear Model

Description

Model Predictions from Singular Linear Model

Usage

## S3 method for class 'slim'
predict(object, newdata, ...)

Arguments

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.

Value

a vector of model predictions.


Print 'slim' Objects

Description

'print' methods for class 'slim' and 'slim_summary'. 'print.slim_summary' differs only in its default value of 'empirical'.

Usage

## 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, ...)

Arguments

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 print.default.

signif.stars

logical. If TRUE, ‘significance stars’ are printed for each coefficient.

...

arguments passed to or from other methods.

Value

x, invisibly.


Extract Model Residuals from Singular Linear Model

Description

Extract Model Residuals from Singular Linear Model

Usage

## S3 method for class 'slim'
residuals(object, ...)

Arguments

object

an object of class 'slim', usually, a result of a call to 'slim'.

...

arguments passed to or from other methods.

Value

a vector of model residuals.


Fit Singular Linear Models

Description

Fit a singular linear model to longitudinal data.

Usage

slim(formula, data, covariance = "randomwalk", limit = ~1,
  contrasts = NULL)

Arguments

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'.

Value

an object of class 'slim'

Examples

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

Description

Methods for Singular Linear Model Fits

Arguments

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.


Summarizing Singular Linear Model Fits

Description

'summary' method for class 'slim'.

Usage

## S3 method for class 'slim'
summary(object, empirical = TRUE, ...)

Arguments

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.

Value

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)


Extract Variance-Covariance Matrix from a 'slim' Object

Description

'vcov' method for class 'slim'.

Usage

## S3 method for class 'slim'
vcov(object, empirical = TRUE, ...)

Arguments

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.

Value

a matrix of the estimated covariances between the parameter estimates.