Package 'mvna'

Title: Nelson-Aalen Estimator of the Cumulative Hazard in Multistate Models
Description: Computes the Nelson-Aalen estimator of the cumulative transition hazard for arbitrary Markov multistate models <ISBN:978-0-387-68560-1>.
Authors: Arthur Allignol
Maintainer: Arthur Allignol <[email protected]>
License: MIT + file LICENSE
Version: 2.0.1
Built: 2024-11-07 03:10:42 UTC
Source: https://github.com/cran/mvna

Help Index


Pregnancies exposed to coumarin derivatives

Description

Outcomes of pregnancies exposed to coumarin derivatives. The aim is to investigate whether exposition to coumarin derivatives increases the probability of spontaneous abortions. Apart from spontaneous abortion, pregnancy may end in induced abortion or live birth. Moreover, data are left-truncated as women usually enter the study several weeks after conception.

Usage

data(abortion)

Format

A data frame with 1186 observations on the following 5 variables.

id

Identification number

entry

Entry times into the cohort

exit

Event times

group

Group. 0: control, 1: exposed to coumarin derivatives

cause

Cause of failure. 1: induced abortion, 2: life birth, 3: spontaneous abortion

Source

Meiester, R. and Schaefer, C (2008). Statistical methods for estimating the probability of spontaneous abortion in observational studies – Analyzing pregnancies exposed to coumarin derivatives. Reproductive Toxicology, 26, 31–35

Examples

data(abortion)

Lines method for 'mvna' objects

Description

Lines method for mvna objects.

Usage

## S3 method for class 'mvna'
lines(x, tr.choice, col = 1, lty, conf.int = FALSE,
      level = 0.95, var.type = c("aalen", "greenwood"),
      ci.fun = c("log", "linear", "arcsin"), ci.col = col,
      ci.lty = 3, ...)

Arguments

x

An object of class mvna.

tr.choice

A character vector of the form c("from to", "from to") specifying which transitions should be displayed. By default, all the transition hazards are plotted.

col

A vector of colours. Default is black.

lty

A vector of line types. Default is 1:number of transitions.

conf.int

Logical. Indicates whether to display pointwise confidence interval. Default is FALSE.

level

Level of the confidence interval. Default is 0.95.

var.type

Specifies the variance estimator that should be used to compute the confidence interval. One of "aalen" or "greenwood". Default is "aalen".

ci.fun

Specifies the transformation applied to the confidence interval. Choices are "linear", "log", "arcsin". Default is "log".

ci.col

Colours of the confidence interval lines. By default, ci.col equals col.

ci.lty

Line types for the confidence intervals. Default is 3.

...

Further arguments for lines.

Value

No value returned.

Author(s)

Arthur Allignol, [email protected]

See Also

mvna, plot.mvna

Examples

data(sir.adm)

## data set transformation
data(sir.adm) 
id <- sir.adm$id
from <- sir.adm$pneu
to <- ifelse(sir.adm$status==0,"cens",sir.adm$status+1)
times <- sir.adm$time
dat.sir <- data.frame(id,from,to,time=times)

## Possible transitions
tra <- matrix(ncol=4,nrow=4,FALSE)
tra[1:2,3:4] <- TRUE

na.pneu <- mvna(dat.sir,c("0","1","2","3"),
                tra,"cens")

plot(na.pneu, tr.choice = c("0 2"), conf.int = TRUE,
     col = 1, lty = 1, legend = FALSE)

lines(na.pneu, tr.choice = c("1 2"), conf.int = TRUE,
      col = 2, lty = 1)

Nelson-Aalen estimator in multistate models

Description

This function computes the multivariate Nelson-Aalen estimator of the cumulative transition hazards in multistate models, that is, for each possible transition, it computes an estimate of the cumulative hazard.

Usage

mvna(data, state.names, tra, cens.name)

Arguments

data

A data.frame of the form data.frame(id,from,to,time) or (id,from,to,entry,exit)

id:

patient id

from:

the state from where the transition occurs

to:

the state to which a transition occurs

time:

time when a transition occurs

entry:

entry time in a state

exit:

exit time from a state

This data.frame is transition-oriented, i.e. it contains one row per transition, and possibly several rows per patient. Specifying an entry and exit time permits to take into account left-truncation.

state.names

A vector of character giving the states names.

tra

A quadratic matrix of logical values describing the possible transitions within the multistate model.

cens.name

A character giving the code for censored observations in the column to of data. If there is no censored observations in your data, put NULL.

Details

This functions computes the Nelson-Aalen estimator as described in Anderson et al. (1993), along with the two variance estimators described in eq. (4.1.6) and (4.1.7) of Andersen et al. (1993) at each transition time.

Value

Returns a list named after the possible transitions, e.g. if we define a multistate model with two possible transitions: from state 0 to state 1, and from state 0 to state 2, the returned list will have two parts named "0 1" and "0 2". Each part contains a data.frame with columns:

na

Nelson-Aalen estimates at each transition times.

var.aalen

Variance estimator given in eq. (4.1.6) of Andersen et al. (1993).

var.greenwood

Variance estimator given in eq. (4.1.7) of Andersen et al. (1993).

time

The transition times.

The list also contains:

time

All the event times.

n.risk

A matrix giving the number at individual at risk in the transient states just before an event.

n.event

An array which gives the number of transitions at each event times.

n.cens

A matrix giving the number a censored observations at each event times.

state.names

The same as in the function call.

cens.name

The same as in the function call.

trans

A data frame, with columns from and to, that gives the possible transitions.

Note

The variance estimator (4.1.6) may overestimate the true variance, and the one defined eq. (4.1.7) may underestimate the true variance (see Klein (1991) and Andersen et al. (example IV.1.1, 1993)), especially with small sample set. Klein (1991) recommends the use of the variance estimator of eq. (4.1.6, "aalen") because he found it to be less biased.

Author(s)

Arthur Allignol, [email protected]

References

Andersen, P.K., Borgan, O., Gill, R.D. and Keiding, N. (1993). Statistical models based on counting processes. Springer Series in Statistics. New York, NY: Springer.

Beyersmann J, Allignol A, Schumacher M: Competing Risks and Multistate Models with R (Use R!), Springer Verlag, 2012 (Use R!)

Klein, J.P. Small sample moments of some estimators of the variance of the Kaplan-Meier and Nelson-Aalen estimators. Scandinavian Journal of Statistics, 18:333–340, 1991.

See Also

sir.adm,sir.cont

Examples

data(sir.cont)

# Modification for patients entering and leaving a state
# at the same date
sir.cont <- sir.cont[order(sir.cont$id, sir.cont$time), ]
for (i in 2:nrow(sir.cont)) {
  if (sir.cont$id[i]==sir.cont$id[i-1]) {
    if (sir.cont$time[i]==sir.cont$time[i-1]) {
      sir.cont$time[i-1] <- sir.cont$time[i-1] - 0.5
    }
  }
}

# Matrix of logical giving the possible transitions
tra <- matrix(ncol=3,nrow=3,FALSE)
tra[1, 2:3] <- TRUE
tra[2, c(1, 3)] <- TRUE

# Computation of the Nelson-Aalen estimates
na <- mvna(sir.cont,c("0","1","2"),tra,"cens")

# plot
if (require(lattice))
xyplot(na)

### example with left-truncation
data(abortion)

# Data set modification in order to be used by mvna
names(abortion) <- c("id", "entry", "exit", "from", "to")
abortion$to <- abortion$to + 1

## computation of the matrix giving the possible transitions
tra <- matrix(FALSE, nrow = 5, ncol = 5)
tra[1:2, 3:5] <- TRUE

na.abortion <- mvna(abortion, as.character(0:4), tra, NULL)

plot(na.abortion, tr.choice = c("0 4", "1 4"),
     curvlab = c("Control", "Exposed"),
     bty = "n", legend.pos = "topleft")

Plot method for a mvna object

Description

Plot method for an object of class mvna. This function plots estimates of the cumulative transition hazards in one panel.

Usage

## S3 method for class 'mvna'
plot(x, tr.choice, xlab = "Time",
     ylab = "Cumulative Hazard", col = 1, lty, xlim, ylim,
     conf.int = FALSE, level = 0.95,
     var.type = c("aalen", "greenwood"),
     ci.fun = c("log", "linear", "arcsin"),
     ci.col = col, ci.lty = 3,
     legend = TRUE, legend.pos, curvlab, legend.bty = "n", ...)

Arguments

x

An object of class mvna.

tr.choice

A character vector of the form c("from to","from to") specifying which transitions should be plotted. Default, all the cumulative transition hazards are plotted.

xlab

x-axis label. Default is "Time".

ylab

y-axis label. Default is "Cumulative Hazard".

col

Vector of colour. Default is black.

lty

Vector of line type. Default is 1:number of transitions

xlim

Limits of x-axis for the plot

ylim

Limits of y-axis for the plot

conf.int

Logical. Whether to display pointwise confidence intervals. Default is FALSE.

level

Level of the pointwise confidence intervals. Default is 0.95.

var.type

A character vector specifying the variance that should be used to compute the pointwise confidence intervals. Choices are "aalen" or "greenwood". Default is "aalen".

ci.fun

One of "log", "linear" or "arcsin". Indicates which transformation to apply to the confidence intervals.

ci.col

Colour for the confidence intervals. By default, the colour specified by col is used.

ci.lty

Line type for the confidence intervals. Default is 3.

legend

A logical specifying if a legend should be added

legend.pos

A vector giving the legend's position. See legend for further details.

curvlab

A character or expression vector to appear in the legend. Default is the name of the transitions.

legend.bty

Box type for the legend.

...

Further arguments for plot method.

Details

This plot method permits to draw several cumulative transition hazards on the same panel.

Value

No value returned

Author(s)

Arthur Allignol [email protected]

See Also

mvna

Examples

data(sir.cont)

# Modification for patients entering and leaving a state
# at the same date
sir.cont <- sir.cont[order(sir.cont$id, sir.cont$time), ]
for (i in 2:nrow(sir.cont)) {
  if (sir.cont$id[i]==sir.cont$id[i-1]) {
    if (sir.cont$time[i]==sir.cont$time[i-1]) {
      sir.cont$time[i-1] <- sir.cont$time[i-1] - 0.5
    }
  }
}

tra <- matrix(ncol=3,nrow=3,FALSE)
tra[1, 2:3] <- TRUE
tra[2, c(1, 3)] <- TRUE

na.cont <- mvna(sir.cont,c("0","1","2"),tra,"cens")

plot(na.cont, tr.choice=c("0 2", "1 2"))

Calculates Nelson-Aalen estimates at specified time-points

Description

This function gives the Nelson-Aalen estimates at time-points specified by the user.

Usage

## S3 method for class 'mvna'
predict(object, times, tr.choice, level = 0.95,
        var.type = c("aalen", "greenwood"),
        ci.fun = c("log", "linear", "arcsin"), ...)

Arguments

object

An object of class mvna

times

Time-points at which one wants the estimates

tr.choice

A vector of character giving for which transitions one wants estimates. By default, the function will give the Nelson-Aalen estimates for all transitions.

level

Level of the pointwise confidence intervals. Default is 0.95.

var.type

Variance estimator displayed and used to compute the pointwise confidence intervals. One of "aalen" or "greenwood". Default is "aalen".

ci.fun

Which transformation to apply for the confidence intervals. Choices are "linear", "log" or "arcsin". Default is "log".

...

Other arguments to predict

Value

Returns a list named after the possible transitions, e.g. if we define a multistate model with two possible transitions: from state 0 to state 1, and from state 0 to state 2, the returned list will have two parts named "0 1" and "0 2". Each part contains a data.frame with columns:

times

Time points specified by the user.

na

Nelson-Aalen estimates at the specified times.

var.aalen or var.greenwood

Depending on what was specified in var.type.

lower

Lower bound of the pointwise confidence intervals.

upper

Upper bound.

Author(s)

Arthur Allignol, [email protected]

References

Andersen, P.K., Borgan, O., Gill, R.D. and Keiding, N. (1993). Statistical models based on counting processes. Springer Series in Statistics. New York, NY: Springer.

See Also

mvna, summary.mvna

Examples

data(sir.cont)

# Modification for patients entering and leaving a state
# at the same date
sir.cont <- sir.cont[order(sir.cont$id, sir.cont$time), ]
for (i in 2:nrow(sir.cont)) {
  if (sir.cont$id[i]==sir.cont$id[i-1]) {
    if (sir.cont$time[i]==sir.cont$time[i-1]) {
      sir.cont$time[i-1] <- sir.cont$time[i-1] - 0.5
    }
  }
}

# Matrix of logical giving the possible transitions
tra <- matrix(ncol=3,nrow=3,FALSE)
tra[1, 2:3] <- TRUE
tra[2, c(1, 3)] <- TRUE

# Computation of the Nelson-Aalen estimates
na <- mvna(sir.cont,c("0","1","2"),tra,"cens")

# Using predict
predict(na,times=c(1,5,10,15))

Print method for 'mvna' object

Description

Print method for an object of class mvna. It prints estimates of the cumulative hazard along with estimates of the variance described in eq. (4.1.6) and (4.1.7) of Andersen et al. (1993) at several time points obtained with the quantile function.

Usage

## S3 method for class 'mvna'
print(x, ...)

Arguments

x

An object of class mvna

...

Other arguments for print method

Value

No value returned.

Author(s)

Arthur Allignol, [email protected]

See Also

mvna


Pneumonia on admission in intenive care unit patients

Description

Pneumonia status on admission for intensive care unit (ICU) patients, a random sample from the SIR-3 study.

Usage

data(sir.adm)

Format

The data contains 747 rows and 4 variables:

id:

Randomly generated patient id

pneu:

Pneumonia indicator. 0: No pneumonia, 1: Pneumonia

status

Status indicator. 0: censored observation, 1: discharged, 2: dead

time:

Follow-up time in day

age:

Age at inclusion

sex:

Sex. F for female and M for male

Source

Beyersmann, J., Gastmeier, P., Grundmann, H., Baerwolff, S., Geffers, C., Behnke, M., Rueden, H., and Schumacher, M. Use of multistate models to assess prolongation of intensive care unit stay due to nosocomial infection. Infection Control and Hospital Epidemiology, 27:493-499, 2006.

Examples

# data set transformation
data(sir.adm) 
id <- sir.adm$id
from <- sir.adm$pneu
to <- ifelse(sir.adm$status==0,"cens",sir.adm$status+1)
times <- sir.adm$time
dat.sir <- data.frame(id,from,to,time=times)

# Possible transitions
tra <- matrix(ncol=4,nrow=4,FALSE)
tra[1:2,3:4] <- TRUE

na.pneu <- mvna(dat.sir,c("0","1","2","3"),
                tra,"cens")

if(require("lattice")) {
xyplot(na.pneu,tr.choice=c("0 2","1 2","0 3","1 3"),
       aspect=1,strip=strip.custom(bg="white",
       factor.levels=c("No pneumonia on admission -- Discharge",
                       "Pneumonia on admission -- Discharge",
                       "No pneumonia on admission -- Death",
                       "Pneumonia on admission -- Death"),
       par.strip.text=list(cex=0.9)),
       scales=list(alternating=1),xlab="Days",
       ylab="Nelson-Aalen esimates")
}

Ventilation status in intensive care unit patients

Description

Time-dependent ventilation status for intensive care unit (ICU) patients, a random sample from the SIR-3 study.

Usage

data(sir.cont)

Format

A data frame with 1141 rows and 6 columns:

id:

Randomly generated patient id

from:

State from which a transition occurs

to:

State to which a transition occurs

time:

Time when a transition occurs

age:

Age at inclusion

sex:

Sex. F for female and M for male

The possible states are:

0: No ventilation

1: Ventilation

2: End of stay.

And cens stands for censored observations.

Details

This data frame consists in a random sample of the SIR-3 cohort data. It focuses on the effect of ventilation on the length of stay (combined endpoint discharge/death). Ventilation status is considered as a transcient state in an illness-death model.

The data frame is directly formated to be used with the mvna function, i.e., it is transition-oriented with one row per transition.

Source

Beyersmann, J., Gastmeier, P., Grundmann, H., Baerwolff, S., Geffers, C., Behnke, M., Rueden, H., and Schumacher, M. Use of multistate models to assess prolongation of intensive care unit stay due to nosocomial infection. Infection Control and Hospital Epidemiology, 27:493-499, 2006.

Examples

data(sir.cont)

# Matrix of possible transitions
tra <- matrix(ncol=3,nrow=3,FALSE)
tra[1, 2:3] <- TRUE
tra[2, c(1, 3)] <- TRUE

# Modification for patients entering and leaving a state
# at the same date
sir.cont <- sir.cont[order(sir.cont$id, sir.cont$time), ]
for (i in 2:nrow(sir.cont)) {
  if (sir.cont$id[i]==sir.cont$id[i-1]) {
    if (sir.cont$time[i]==sir.cont$time[i-1]) {
      sir.cont$time[i-1] <- sir.cont$time[i-1] - 0.5
    }
  }
}

# Computation of the Nelson-Aalen estimates
  na.cont <- mvna(sir.cont,c("0","1","2"),tra,"cens")

if (require("lattice")) {
  xyplot(na.cont,tr.choice=c("0 2","1 2"),aspect=1,
       strip=strip.custom(bg="white",
         factor.levels=c("No ventilation -- Discharge/Death",
           "Ventilation -- Discharge/Death"),
         par.strip.text=list(cex=0.9)),
       scales=list(alternating=1),xlab="Days",
       ylab="Nelson-Aalen estimates")
}

Summary method for objects of class 'mvna'

Description

Summary method for mvna objects. The function returns a list containing the cumulative transition hazards, variance and other informations.

Usage

## S3 method for class 'mvna'
summary(object, level = 0.95,
        var.type = c("aalen", "greenwood"),
        ci.fun = c("log", "linear", "arcsin"), ...)

## S3 method for class 'mvna'
print.summary(x, ...)

Arguments

object

An object of class mvna.

level

Level of the pointwise confidence interval. Default is 0.95.

var.type

Which of the "aalen" or "greenwood" variance estimator should be displayed and used to compute the pointwise confidence intervals. Default is "aalen".

ci.fun

Which transformation to apply to the confidence intervals. One of "linear", "log", "arcsin". Default is "log".

...

Further arguments.

x

An object of class summary.mvna.

Value

Returns an object of class mvna which is a list of data frames named after the possible transitions. Each data frame contains the following columns:

time

Event times at which the cumulative hazards are estimated.

na

Estimated cumulative transition hazards.

var.aalen or var.greenwood

Variance estimates. The name depends on the var.type argument. Default will be var.aalen.

lower

Lower bound of the pointwise confidence interval.

upper

Upper bound.

n.risk

Number of individuals at risk of experiencing an event just before tt.

n.event

Number of transitions at time tt.

Author(s)

Arthur Allignol, [email protected]

See Also

mvna

Examples

data(sir.adm)

## data set transformation
data(sir.adm) 
id <- sir.adm$id
from <- sir.adm$pneu
to <- ifelse(sir.adm$status==0,"cens",sir.adm$status+1)
times <- sir.adm$time
dat.sir <- data.frame(id,from,to,time=times)

## Possible transitions
tra <- matrix(ncol=4,nrow=4,FALSE)
tra[1:2,3:4] <- TRUE

na.pneu <- mvna(dat.sir,c("0","1","2","3"),
                tra,"cens")

summ.na.pneu <- summary(na.pneu)

## cumulative hazard for 0 -> 2 transition:
summ.na.pneu$"0 2"$na

Panel plots for object of class 'mvna'

Description

xyplot function for objects of class mvna. Estimates of the cumulative hazards are plotted as a function of time for all the transitions specified by the user. The function can also plot several types of pointwise confidence interval (see Andersen et al. (1993) p.208).

Usage

## S3 method for class 'mvna'
xyplot(x, data = NULL, xlab = "Time",
       ylab = "Cumulative Hazard", tr.choice = "all",
       conf.int = TRUE, var.type = c("aalen", "greenwood"),
       ci.fun = c("log", "linear", "arcsin"), level = 0.95,
       col = c(1, 1, 1), lty = c(1, 3, 3),
       ci.type = c(1, 2), ...)

Arguments

x

An object of class mvna.

data

Useless.

xlab

x-axis label. Default is "Time".

ylab

y-axis label. Default is "Cumulative Hazard"

tr.choice

A character vector of the form c("from to","from to") specifying which transitions should be plotted. Default is "all".

conf.int

A logical whether plot pointwise confidence interval. Default is TRUE

var.type

One of "aalen" or "greenwood". Specifies which variance estimator is used to compute the confidence intervals.

ci.fun

One of "log", "linear" or "arcsin". Indicates the transformation applied to the pointwise confidence intervals. Default is "log".

level

Level of the confidence interval. Default is 0.95.

col

Vector of colour for the plot. Default is black.

lty

Vector of line type. Default is c(1, 3, 3).

ci.type

DEPRECATED

...

Other arguments for xyplot.

Value

An object of class trellis.

Note

These plots are highly customizable, see Lattice and xyplot. For example, if one want to change strip background color and the title of each strip, it can be added 'strip=strip.custom(bg="a color",factor.levels="a title","another title")'. One can use 'aspect="1"' to get the size of the panels isometric.

Author(s)

Arthur Allignol, [email protected]

References

Andersen, P.K., Borgan, O., Gill, R.D. and Keiding, N. (1993). Statistical models based on counting processes. Springer Series in Statistics. New York, NY: Springer.

Deepayan Sarkar (2006). lattice: Lattice Graphics. R package version 0.13-8.

See Also

xyplot, mvna, sir.adm,sir.cont