survMisc (version 0.5.4)

COV: covariance matrix for survival data

Description

covariance matrix for survival data

Usage

COV(x, ...)

# S3 method for ten COV(x, ..., reCalc = FALSE)

# S3 method for stratTen COV(x, ..., reCalc = FALSE)

# S3 method for numeric COV(x, ..., n, ncg)

Arguments

x

A numeric vector of number of events, \(e_t\). These are assumed to be ordered by discrete times.

A method is available for objects of class ten.

...

Additional arguments (not implemented).

reCalc

Recalcuate the values? If reCalc=FALSE (the default) and the ten object already has the calculated values stored as an attribute, the value of the attribute is returned directly. --Arguments for the numeric method:

n

number at risk (total).

ncg

number at risk, per covariate group. If there are \(2\) groups, this can be given as a vector with the number at risk for group \(1\).

If there are \(\geq 2\) groups, it is a matrix with one column for each group.

Value

An array.

The first two dimensions = the number of covariate groups \(K\), \(k = 1, 2, \ldots K\). This is the square matrix below.

The third dimension is the number of observations (discrete time points). To calculate this, we use x (= \(e_t\) below) and \(n_1\), the number at risk in covariate group \(1\).

Where there are \(2\) groups, the resulting sparse square matrix (i.e. the non-diagonal elements are \(0\)) at time \(t\) has diagonal elements: $$cov_t = - \frac{n_{0t} n_{1t} e_t (n_t - e_t)}{n_t^2(n_t-1)}$$ For \(\geq 2\) groups, the resulting square matrix has diagonal elements given by: $$cov_{kkt} = \frac{n_{kt}(n_t - n_{kt}) e_t(n_t - e_t)}{ n_t^2(n_t - 1)}$$ The off diagonal elements are: $$cov_{klt} = \frac{-n_{kt} n_{lt} e_t (n_t-e_t) }{ n_t^2(n_t-1)}$$

Details

Gives variance-covariance matrix for comparing survival data for two or more groups.

Inputs are vectors corresponding to observations at a set of discrete time points for right censored data, except for \(n1\), the no. at risk by predictor.

This should be specified as a vector for one group, otherwise as a matrix with each column corresponding to a group.

See Also

Called by comp

The name of the function is capitalized to distinguish it from:

?stats::cov

Examples

Run this code
# NOT RUN {
## Two covariate groups
## K&M. Example 7.2, pg 210, table 7.2 (last column).
# }
# NOT RUN {
data("kidney", package="KMsurv")
k1 <- with(kidney,
           ten(Surv(time=time, event=delta) ~ type))
COV(k1)[COV(k1) > 0]
# }
# NOT RUN {
## Four covariate groups
## K&M. Example 7.6, pg 217.
# }
# NOT RUN {
data("larynx", package="KMsurv")
l1 <- ten(Surv(time, delta) ~ stage, data=larynx)
rowSums(COV(l1), dims=2)
# }
# NOT RUN {
## example of numeric method
## Three covariate groups
## K&M. Example 7.4, pg 212.
# }
# NOT RUN {
data("bmt", package="KMsurv")
b1 <- asWide(ten(Surv(time=t2, event=d3) ~ group, data=bmt))
rowSums(b1[, COV(x=e, n=n, ncg=matrix(data=c(n_1, n_2, n_3), ncol=3))], dims=2)
# }

Run the code above in your browser using DataLab