prettyCoxph: Nicer outputs from coxph model fits

View source: R/prettyCoxph.R

prettyCoxphR Documentation

Nicer outputs from coxph model fits

Description

Formats the coxph (or coxphf) model outputs into a prettier display.

Usage

prettyCoxph(
  input.formula,
  input.d,
  ref.grp = NULL,
  use.firth = 1,
  check.ph = FALSE,
  plot.ph = TRUE,
  ph.test.plot.filename = NULL,
  ...
)

Arguments

input.formula

a formula object, with the response on the left of a ~ operator, and the terms on the right. The response must be a survival object as returned by the Surv function.

input.d

data.frame containing the variables in input.formula

ref.grp

a named array indicating reference group(s) for any variables in the cox model. this parameter will be ignored if not applicable, e.g. for continuous variable

use.firth

if set to -1, Firth's correction is applied using coxphf. The default value is 1, which uses coxph.

check.ph

if TRUE, checks the proportional hazard assumption.

plot.ph

if TRUE (default), the PH residual plot is graphed.

ph.test.plot.filename

character string for filename of residual plot, including file extension. If NULL (default), plots to console. Otherwise plot is saved to disk.

...

additional arguments to coxph or coxphf

Details

The original fit call is returned, along with other useful statistics. If Firth is called, we first determine if the percentage of censored cases is large enough to use Firth.

Value

A list with elements

output

A character matrix showing the hazard ratio, confidence bounds, and p-value for each coefficient. If check.ph = TRUE, the last column shows the results of the PH test, otherwise it reads "NOT CALCULATED" for every coefficient.

fit

The fit output call returned from coxph or coxphf

n

The number of observations used in the fit

nevent

The number of events used in the fit

ph.test

The rho, Chi-squared statistic, and p-value for each coefficient. Not shown if check.ph = FALSE

used.firth

logical; if TRUE, Firth's correction was applied using coxphf

Author(s)

Samuel Leung, Derek Chiu

Examples

library(survival)
# Base output
test1 <- list(time = c(4, 3, 1, 1, 2, 2, 3),
status = c(1, 1, 1, 0, 1, 1, 0),
x = c(0, 2, 1, 1, 1, 0, 0),
sex = c(0, 0, 0, 0, 1, 1, 1))
coxph(Surv(time, status) ~ x + strata(sex), test1)

# Pretty output
prettyCoxph(Surv(time, status) ~ x + strata(sex), test1)

# x is now a factor
test1$x <- factor(test1$x)
prettyCoxph(Surv(time, status) ~ x + strata(sex), test1)

# Releveled reference group
prettyCoxph(Surv(time, status) ~ x + strata(sex), test1, ref.grp =
setNames("2", "x"))

# Use Firth's correction
prettyCoxph(Surv(time, status) ~ x + strata(sex), test1, use.firth = -1)

TalhoukLab/biostatUtil documentation built on April 14, 2025, 4:15 a.m.