computeLogrankZ {safestats}R Documentation

Helper function to computes the logrank statistic for 'Surv' objects of type "right" and "counting" with the hypergeometric variance.

Description

This function was created to complement survdiff from the 'survival' package, which is restricted to 'Surv' objects of type "right". Most likely survdiff is much faster

Usage

computeLogrankZ(
  survObj,
  group,
  computeZ = TRUE,
  computeExactE = FALSE,
  theta0 = 1,
  thetaS = NULL,
  ...
)

Arguments

survObj

a Surv object that is either of type

group

a grouping factor with 2 levels

computeZ

logical. If TRUE computes the logrank z-statistic. Default is TRUE.

computeExactE

logical. If TRUE computes one-sided exact logrank e-value. Default is FALSE.

theta0

numeric > 0 used only for the e-value, i.e., if computeExactE is TRUE. Default is 1.

thetaS

numeric > 0 used only for the e-value, i.e., if computeExactE is TRUE. Default is NULL.

...

further arguments to be passed to or from methods.

Value

Returns a list containing at least the following components:

nEvents

the number of events.

z

the observed logrank statistic.

oMinEVector

vector of observed minus expected.

varVector

vector of hypergeometric variances.

stopTimeVector

vector at which the events occurred.

Examples

data <- generateSurvData(nP = 5,
                         nT = 5,
                         lambdaP = 0.03943723,
                         lambdaT = 0.5*0.03943723,
                         endTime = 40,
                         seed = 2006)

survObj <- survival::Surv(data$time, data$status)

survObj <- survival::Surv(data$time, data$status)

result <- computeLogrankZ(survObj, data$group)
result$z
sqrt(survival::survdiff(survObj~data$group)$chisq)

[Package safestats version 0.8.7 Index]