Skip to contents

This function estimates the hazard ratios between arms when an interaction variable is given with specific values.

Usage

estimate_coef(
  variable,
  given,
  lvl_var,
  lvl_given,
  coef,
  mmat,
  vcov,
  conf_level = 0.95
)

Arguments

variable, given

Names of two variable in interaction. We seek the estimation of the levels of variable given the levels of given

lvl_var, lvl_given

corresponding levels has given by levels.

coef

Numeric of estimated coefficients.

mmat

A name numeric filled with 0 used as template to obtain the design matrix.

vcov

Variance-covariance matrix of underlying model.

conf_level

Single numeric for the confidence level of estimate intervals.

Value

A list of matrix (one per level of variable) with rows corresponding to the combinations of variable and given, with columns:

coef_hat

Estimation of the coefficient

coef_se

Standard error of the estimation.

hr

Hazard ratio.

lcl,ucl

lower/upper confidence limit of the hazard ratio

Details

Given the cox regression investigating the effect of Arm (A, B, C; reference A) and Sex (F, M; reference Female). The model is abbreviated: y ~ Arm + Sex + Arm x Sex. The cox regression estimates the coefficients along with a variance-covariance matrix for:

  • b1 (arm b), b2 (arm c),

  • b3 (sex m),

  • b4 (arm b: sex m), b5 (arm c: sex m)

Given that I want an estimation of the Hazard Ratio for arm C/sex M, the estimation will be given in reference to arm A/Sex M by exp(b2 + b3 + b5)/ exp(b3) = exp(b2 + b5), therefore the interaction coefficient is given by b2 + b5 while the standard error is obtained as $1.96 * sqrt(Var b2 + Var b5 + 2 * covariance (b2,b5))$ for a confidence level of 0.95.

Examples

library(dplyr)
library(scda)
library(survival)

ADSL <- synthetic_cdisc_data("latest")$adsl
ADSL <- ADSL %>%
  filter(SEX %in% c("F", "M"))

ADTTE <- synthetic_cdisc_data("latest")$adtte %>%
  filter(PARAMCD == "PFS")
ADTTE$ARMCD <- droplevels(ADTTE$ARMCD)
ADTTE$SEX <- droplevels(ADTTE$SEX)

mod <- coxph(
  formula = Surv(time = AVAL, event = 1 - CNSR) ~ (SEX + ARMCD)^2,
  data = ADTTE
)

mmat <- stats::model.matrix(mod)[1, ]
mmat[!mmat == 0] <- 0

# Internal function - estimate_coef
if (FALSE) {
estimate_coef(
  variable = "ARMCD", given = "SEX", lvl_var = "ARM A", lvl_given = "M",
  coef = stats::coef(mod), mmat = mmat, vcov = stats::vcov(mod), conf_level = .95
)
}