Skip to contents

tidy() gives a fitted model's estimates as a data frame, one row per term, time, or parameter. For most models it's the same table as as.data.frame(), and any arguments in ... go to that method (such as exponentiate and conf_level for cox_ph()).

Usage

# S3 method for class 'cox_ph'
tidy(x, ...)

# S3 method for class 'kaplan_meier'
tidy(x, ...)

# S3 method for class 'nelson_aalen'
tidy(x, ...)

# S3 method for class 'turnbull'
tidy(x, ...)

# S3 method for class 'aalen_johansen'
tidy(x, ...)

# S3 method for class 'multi_state'
tidy(x, ...)

# S3 method for class 'fine_gray'
tidy(x, ...)

# S3 method for class 'penalized_fine_gray'
tidy(x, ...)

# S3 method for class 'aft'
tidy(x, ...)

# S3 method for class 'parametric'
tidy(x, ...)

# S3 method for class 'piecewise_exponential'
tidy(x, ...)

# S3 method for class 'royston_parmar'
tidy(x, ...)

# S3 method for class 'aalen_additive'
tidy(x, ...)

# S3 method for class 'buckley_james'
tidy(x, ...)

# S3 method for class 'mixture_cure'
tidy(x, ...)

# S3 method for class 'ipc_ridge'
tidy(x, ...)

# S3 method for class 'cox_net'
tidy(x, ...)

# S3 method for class 'survival_tree'
tidy(x, ...)

# S3 method for class 'greenwood_test'
tidy(x, ...)

# S3 method for class 'maxcombo_test'
tidy(x, ...)

# S3 method for class 'rmst_test'
tidy(x, ...)

# S3 method for class 'cox_zph'
tidy(x, ...)

# S3 method for class 'survival_forest'
tidy(x, ...)

# S3 method for class 'competing_risk_forest'
tidy(x, ...)

# S3 method for class 'gradient_boosting_survival_analysis'
tidy(x, ...)

# S3 method for class 'survival_boost'
tidy(x, ...)

Arguments

x

A fitted model or a test result.

...

Passed to the model's as.data.frame() method, or to variable_importance() for the forests and boosting models.

Value

A data frame.

Details

What a row holds depends on the model:

See also

glance() for one row per model, and augment() for one row per observation.

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)
tidy(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
tidy(fit, exponentiate = TRUE)
#>   term  estimate  std_error  statistic   p_value  conf_low conf_high
#> 1  age 0.9635579 0.04953093 -0.7494854 0.4535647 0.8744138  1.061790
#> 2  sex 1.2600308 0.72224460  0.3200247 0.7489496 0.3059183  5.189875

tidy(kaplan_meier(Surv(time, status) ~ sex, data = lung))
#>    strata sex time n_risk n_event n_censor  estimate  std_error   conf_low
#> 1   sex=1   1   71     11       1        0 0.9090909 0.08667842 0.75413385
#> 2   sex=1   1  166     10       1        0 0.8181818 0.11629130 0.61924899
#> 3   sex=1   1  170      9       1        0 0.7272727 0.13428163 0.50644676
#> 4   sex=1   1  210      8       1        0 0.6363636 0.14504073 0.40709758
#> 5   sex=1   1  218      7       1        0 0.5454545 0.15013142 0.31803363
#> 6   sex=1   1  306      6       1        0 0.4545455 0.15013142 0.23792206
#> 7   sex=1   1  455      5       1        0 0.3636364 0.14504073 0.16640077
#> 8   sex=1   1  567      4       1        0 0.2727273 0.13428163 0.10390248
#> 9   sex=1   1  883      3       1        0 0.1818182 0.11629130 0.05190473
#> 10  sex=1   1 1010      2       0        1 0.1818182 0.11629130 0.05190473
#> 11  sex=1   1 1022      1       0        1 0.1818182 0.11629130 0.05190473
#> 12  sex=2   2  310      4       1        0 0.7500000 0.21650635 0.42593227
#> 13  sex=2   2  361      3       1        0 0.5000000 0.25000000 0.18765893
#> 14  sex=2   2  654      2       1        0 0.2500000 0.21650635 0.04579076
#> 15  sex=2   2  728      1       1        0 0.0000000         NA         NA
#>    conf_high
#> 1  1.0000000
#> 2  1.0000000
#> 3  1.0000000
#> 4  0.9947460
#> 5  0.9355006
#> 6  0.8684002
#> 7  0.7946562
#> 8  0.7158652
#> 9  0.6368947
#> 10 0.6368947
#> 11 0.6368947
#> 12 1.0000000
#> 13 1.0000000
#> 14 1.0000000
#> 15        NA