fit_pwexp: Piecewise exponential survival estimation

View source: R/fit_pwexp.R

fit_pwexpR Documentation

Piecewise exponential survival estimation

Description

Computes survival function, density function, -2*log-likelihood based on input dataset and intervals for piecewise constant failure rates. Initial version assumes observations are right censored or events only.

Usage

fit_pwexp(
  srv = Surv(time = Ex1delayedEffect$month, event = Ex1delayedEffect$evntd),
  intervals = array(3, 3)
)

Arguments

srv

input survival object (see Surv); note that only 0 = censored, 1 = event for Surv

intervals

Vector containing positive values indicating interval lengths where the exponential rates are assumed. Note that a final infinite interval is added if any events occur after the final interval specified.

Value

A matrix with rows containing interval length, estimated rate, -2*log-likelihood for each interval.

Examples

# use default arguments for delayed effect example dataset (Ex1delayedEffect)
library(survival)

# example 1
rateall <- fit_pwexp()
rateall

# example 2
# Estimate by treatment effect
rate1 <- with(subset(Ex1delayedEffect, trt == 1), fit_pwexp(Surv(month, evntd)))
rate0 <- with(subset(Ex1delayedEffect, trt == 0), fit_pwexp(Surv(month, evntd)))

rate1
rate0
rate1$rate/rate0$rate

# chi-square test for (any) treatment effect (8 - 4 parameters = 4 df)
pchisq(sum(rateall$m2ll) - sum(rate1$m2ll + rate0$m2ll),
       df = 4,
       lower.tail = FALSE)

# compare with logrank
survdiff(formula = Surv(month, evntd) ~ trt, data = Ex1delayedEffect)

# example 3
# simple model with 3 rates same for each for 3 months,
# different for each treatment after months
rate1a <- with(subset(Ex1delayedEffect, trt == 1), fit_pwexp(Surv(month, evntd), 3))
rate0a <- with(subset(Ex1delayedEffect, trt == 0), fit_pwexp(Surv(month, evntd), 3))
rate1a$rate/rate0a$rate

m2ll0 <- rateall$m2ll[1] + rate1a$m2ll[2] + rate0a$m2ll[2]
m2ll1 <- sum(rate0$m2ll) + sum(rate1$m2ll)

# as a measure of strength, chi-square examines improvement in likelihood
pchisq(m2ll0-m2ll1, df = 5, lower.tail=FALSE)


keaven/simtrial documentation built on April 17, 2023, 4:03 a.m.