Skip to contents

Produces a tibble that is sorted by stratum and time. Included in this is only the times at which one or more event occurs. The output dataset contains Stratum, tte (time-to-event), at risk count and count of events at the specified tte sorted by Stratum and tte.

Usage

tensurv(x, txval)

Arguments

x

a tibble with no missing values and contain variables

  • Stratum: Stratum

  • Treatment: Treatment group

  • tte: Observed time

  • event: Binary event indicator, 1 represents event, 0 represents censoring

txval

value in the input Treatment column that indicates treatment group value.

Value

A tibble grouped by Stratum and sorted within strata by tte. Remain rows with at least one event in the population, at least one subject is at risk in both treatment group and control group. Other variables in this represent the following within each stratum at each time at which one or more events are observed:

  • events: Total number of events

  • n_event_tol: Total number of events at treatment group

  • n_risk_tol: Number of subjects at risk

  • n_risk_trt: Number of subjects at risk in treatment group

  • S: Left-continuous Kaplan-Meier survival estimate

  • o_minus_e: In treatment group, observed number of events minus expected number of events. The expected number of events is estimated by assuming no treatment effect with hypergeometric distribution with parameters total number of events, total number of events at treatment group and number of events at a time. (Same assumption of log-rank test under the null hypothesis)

  • var_o_minus_e: variance of o_minus_e under the same assumption.

Details

The function only considered two group situation.

The tie is handled by the Breslow's Method.

Examples

library(dplyr)
library(tibble)

# example 1
x <- tibble(Stratum = c(rep(1, 10),rep(2, 6)),
            Treatment = rep(c(1, 1, 0, 0), 4),
            tte = 1:16,
            event= rep(c(0, 1), 8))
tensurv(x, txval = 1)
#> # A tibble: 6 × 9
#> # Groups:   Stratum [2]
#>   Stratum events n_event_tol   tte n_risk_tol n_risk_trt     S o_minus_e var_o…¹
#>     <dbl>  <dbl>       <dbl> <int>      <dbl>      <int> <dbl>     <dbl>   <dbl>
#> 1       1      1           1     2          9          5 1         0.444   0.247
#> 2       1      1           0     4          7          4 0.889    -0.571   0.245
#> 3       1      1           1     6          5          3 0.762     0.4     0.24 
#> 4       1      1           0     8          3          2 0.610    -0.667   0.222
#> 5       2      1           0    12          5          2 1        -0.4     0.24 
#> 6       2      1           1    14          3          1 0.8       0.667   0.222
#> # … with abbreviated variable name ¹​var_o_minus_e

# example 2
x <- simPWSurv(n = 400)
y <- cutDataAtCount(x, 150) %>% tensurv(txval = "Experimental")
# weighted logrank test (Z-value and 1-sided p-value)
z <- sum(y$o_minus_e) / sqrt(sum(y$var_o_minus_e))
c(z, pnorm(z))
#> [1] -0.9488133  0.1713578