Skip to contents

as.data.frame() gives one row per coefficient: the estimate (a log hazard ratio, or a hazard ratio with exponentiate = TRUE), its standard error, the Wald statistic, the two-sided p-value, and the confidence limits.

Usage

# S3 method for class 'cox_ph'
as.data.frame(
  x,
  row.names = NULL,
  optional = FALSE,
  ...,
  exponentiate = FALSE,
  conf_level = x$conf_level
)

Arguments

x

A cox_ph() fit.

row.names, optional

Unused, for compatibility with the generic.

...

Unused.

exponentiate

Give hazard ratios instead of log hazard ratios. The standard error, the statistic, and the p-value are those of the log hazard ratio either way. The default is FALSE.

conf_level

The confidence level. The default is the level the model was fit with.

Value

A data frame with the columns term, estimate, std_error, statistic, p_value, conf_low, and conf_high.

Examples

lung <- data.frame(
  time = c(306, 455, 1010, 210, 883, 1022, 310, 361, 218, 166, 170, 654, 728, 71, 567),
  status = c(2, 2, 1, 2, 2, 1, 2, 2, 2, 2, 2, 2, 2, 2, 2),
  age = c(74, 68, 56, 57, 60, 74, 68, 71, 53, 61, 57, 68, 68, 60, 57),
  sex = c(1, 1, 1, 1, 1, 1, 2, 2, 1, 1, 1, 2, 2, 1, 1)
)
fit <- cox_ph(Surv(time, status) ~ age + sex, data = lung)
as.data.frame(fit)
#>   term    estimate  std_error  statistic   p_value   conf_low  conf_high
#> 1  age -0.03712271 0.04953093 -0.7494854 0.4535647 -0.1342015 0.05995613
#> 2  sex  0.23113613 0.72224460  0.3200247 0.7489496 -1.1844373 1.64670954
as.data.frame(fit, exponentiate = TRUE, conf_level = 0.9)
#>   term  estimate  std_error  statistic   p_value  conf_low conf_high
#> 1  age 0.9635579 0.04953093 -0.7494854 0.4535647 0.8881685  1.045347
#> 2  sex 1.2600308 0.72224460  0.3200247 0.7489496 0.3841007  4.133493