cox_regression_inter {tern} | R Documentation |
Cox regression helper function for interactions
Description
Test and estimate the effect of a treatment in interaction with a covariate. The effect is estimated as the HR of the tested treatment for a given level of the covariate, in comparison to the treatment control.
Usage
h_coxreg_inter_effect(x, effect, covar, mod, label, control, ...)
## S3 method for class 'numeric'
h_coxreg_inter_effect(x, effect, covar, mod, label, control, at, ...)
## S3 method for class 'factor'
h_coxreg_inter_effect(x, effect, covar, mod, label, control, data, ...)
## S3 method for class 'character'
h_coxreg_inter_effect(x, effect, covar, mod, label, control, data, ...)
h_coxreg_extract_interaction(effect, covar, mod, data, at, control)
h_coxreg_inter_estimations(
variable,
given,
lvl_var,
lvl_given,
mod,
conf_level = 0.95
)
Arguments
x |
( |
effect |
( |
covar |
( |
mod |
( |
label |
( |
control |
( |
... |
see methods. |
at |
( |
data |
( |
variable , given |
( |
lvl_var , lvl_given |
( |
conf_level |
( |
Details
Given the cox regression investigating the effect of Arm (A, B, C; reference A) and Sex (F, M; reference Female) and the model being abbreviated: y ~ Arm + Sex + Arm: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)
The estimation of the Hazard Ratio for arm C/sex M is given in reference to arm A/Sex M by exp(b2 + b3 + b5)/ exp(b3) = exp(b2 + b5). The interaction coefficient is deduced by b2 + b5 while the standard error is obtained as $sqrt(Var b2 + Var b5 + 2 * covariance (b2,b5))$.
Value
-
h_coxreg_inter_effect()
returns adata.frame
of covariate interaction effects consisting of the following variables:effect
,term
,term_label
,level
,n
,hr
,lcl
,ucl
,pval
, andpval_inter
.
-
h_coxreg_extract_interaction()
returns the result of an interaction test and the estimated values. If no interaction,h_coxreg_univar_extract()
is applied instead.
-
h_coxreg_inter_estimations()
returns a list of matrices (one per level of variable) with rows corresponding to the combinations ofvariable
andgiven
, 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.
-
Functions
-
h_coxreg_inter_effect()
: S3 generic helper function to determine interaction effect. -
h_coxreg_inter_effect(numeric)
: Method fornumeric
class. Estimates the interaction with anumeric
covariate. -
h_coxreg_inter_effect(factor)
: Method forfactor
class. Estimate the interaction with afactor
covariate. -
h_coxreg_inter_effect(character)
: Method forcharacter
class. Estimate the interaction with acharacter
covariate. This makes an automatic conversion tofactor
and then forwards to the method for factors. -
h_coxreg_extract_interaction()
: A higher level function to get the results of the interaction test and the estimated values. -
h_coxreg_inter_estimations()
: Hazard ratio estimation in interactions.
Note
Automatic conversion of character to factor does not guarantee results can be generated correctly. It is therefore better to always pre-process the dataset such that factors are manually created from character variables before passing the dataset to
rtables::build_table()
.
Examples
library(survival)
set.seed(1, kind = "Mersenne-Twister")
# Testing dataset [survival::bladder].
dta_bladder <- with(
data = bladder[bladder$enum < 5, ],
data.frame(
time = stop,
status = event,
armcd = as.factor(rx),
covar1 = as.factor(enum),
covar2 = factor(
sample(as.factor(enum)),
levels = 1:4,
labels = c("F", "F", "M", "M")
)
)
)
labels <- c("armcd" = "ARM", "covar1" = "A Covariate Label", "covar2" = "Sex (F/M)")
formatters::var_labels(dta_bladder)[names(labels)] <- labels
dta_bladder$age <- sample(20:60, size = nrow(dta_bladder), replace = TRUE)
plot(
survfit(Surv(time, status) ~ armcd + covar1, data = dta_bladder),
lty = 2:4,
xlab = "Months",
col = c("blue1", "blue2", "blue3", "blue4", "red1", "red2", "red3", "red4")
)
mod <- coxph(Surv(time, status) ~ armcd * covar1, data = dta_bladder)
h_coxreg_extract_interaction(
mod = mod, effect = "armcd", covar = "covar1", data = dta_bladder,
control = control_coxreg()
)
mod <- coxph(Surv(time, status) ~ armcd * covar1, data = dta_bladder)
result <- h_coxreg_inter_estimations(
variable = "armcd", given = "covar1",
lvl_var = levels(dta_bladder$armcd),
lvl_given = levels(dta_bladder$covar1),
mod = mod, conf_level = .95
)
result