axe-coxph {butcher}R Documentation

Axing a coxph.

Description

Axing a coxph.

Usage

## S3 method for class 'coxph'
axe_env(x, verbose = FALSE, ...)

## S3 method for class 'coxph'
axe_data(x, verbose = FALSE, ...)

Arguments

x

A model object.

verbose

Print information each time an axe method is executed. Notes how much memory is released and what functions are disabled. Default is FALSE.

...

Any additional arguments related to axing.

Details

The survival::coxph() model is unique in how it uses environments in its components, and butchering such an object can behave in surprising ways in any environment other than the global environment (such as when wrapped in a function). We do not recommend that you use butcher() with a coxph object anywhere other than the global environment.

Do this:

my_coxph_func <- function(df) {
    coxph(Surv(time, status) ~ x + strata(covar), df)
}
## in global environment only:
butcher(my_coxph_func(df))

Do not do this:

my_coxph_func <- function(df) {
    res <- coxph(Surv(time, status) ~ x + strata(covar), df)
    ## no:
    butcher(res)
}

## will not work correctly:
my_coxph_func(df)

Value

Axed coxph object.

Examples


library(survival)

example_data <-
  tibble::tibble(
    time = rpois(1000, 2) + 1,
    status = rbinom(1000, 1, .5),
    x = rpois(1000, .5),
    covar = rbinom(1000, 1, .5)
  )

example_data

make_big_model <- function() {
  boop <- runif(1e6)
  coxph(Surv(time, status) ~ x + strata(covar), example_data)
}

res <- make_big_model()

weigh(res)
weigh(butcher(res))


[Package butcher version 0.3.4 Index]