Converts a summary() object produced by Hmisc or by rms packages to a tidy data frame ready to be `pander`ed (e.g. printed on a word document after knitting the source (with `knitr`).

tidy_summary(x, ..., digits = 3L)

# S3 method for summary.formula.reverse
tidy_summary(x, ..., digits = 3L)

# S3 method for summary.rms
tidy_summary(x, ..., digits = 3L)

Arguments

x

an object used to select a method, output of some summary by Hmisc.

...

further arguments passed to or from other methods

digits

number of significant digits to use (default 3L).

Value

a [tibble][tibble::tibble-package]

Methods (by class)

  • tidy_summary(summary.formula.reverse): Tidies a summary reverse output from the summary.formula called with method = "reverse".

  • tidy_summary(summary.rms): Convert the output of the summary.rms into a data frame, reporting only the Hazard Ratio with the .95 CI and the incremental step (for continuous variables) reference (for categorical variables) for which the Hazard is referred to (i.e. without \(\beta\)s, Low, High, S.E. and Type).

Note

The output is supposed to be used as input to [pander][pander::pander], and contains few otherwise messy characters included for an optimal (pander) formatting.

to see the options you can pass to ... for a custom print, see the print section in summary.formula.

Examples

# \donttest{
  library(Hmisc)
  my_summary <- summary(Species ~ ., data = iris, method = "reverse")
  tidy_summary(my_summary)
#> # A tibble: 4 × 4
#>   `&nbsp;`     `setosa \n(N=50)`   `versicolor \n(N=50)` `virginica \n(N=50)`
#>   <chr>        <chr>               <chr>                 <chr>               
#> 1 Sepal.Length "4.800/5.000/5.200" "5.600/5.900/6.300"   "6.225/6.500/6.900" 
#> 2 Sepal.Width  "3.200/3.400/3.675" "2.525/2.800/3.000"   "2.800/3.000/3.175" 
#> 3 Petal.Length "1.400/1.500/1.575" "4.000/4.350/4.600"   "5.100/5.550/5.875" 
#> 4 Petal.Width  "   0.2/0.2/0.3"    "   1.2/1.3/1.5"      "   1.8/2.0/2.3"    
# }
# \donttest{
  library(rms)
  options(datadist = "dd")
  n <- 1000L
  set.seed(731L)
  age <- 50L + 12L * rnorm(n)
  sex <- factor(sample(c("Male", "Female"), n,
    rep = TRUE,
    prob = c(.6, .4)
  ))
  cens <- 15L * runif(n)
  h <- .02 * exp(.04 * (age - 50L) + .8 * (sex == "Female"))
  dt <- -log(runif(n)) / h
  e <- ifelse(dt <= cens, 1L, 0L)
  dt <- pmin(dt, cens)

  dd <- datadist(age, sex)

  S <- survival::Surv(dt, e)
  f <- rms::cph(S ~ age + sex)
#> Error in Design(data, formula, specials = c("strat", "strata")): dataset dd not found for options(datadist=)


  my_summary <- summary(f)
#> Error in eval(expr, envir, enclos): object 'f' not found
  tidy_summary(my_summary)
#> # A tibble: 4 × 4
#>   `&nbsp;`     `setosa \n(N=50)`   `versicolor \n(N=50)` `virginica \n(N=50)`
#>   <chr>        <chr>               <chr>                 <chr>               
#> 1 Sepal.Length "4.800/5.000/5.200" "5.600/5.900/6.300"   "6.225/6.500/6.900" 
#> 2 Sepal.Width  "3.200/3.400/3.675" "2.525/2.800/3.000"   "2.800/3.000/3.175" 
#> 3 Petal.Length "1.400/1.500/1.575" "4.000/4.350/4.600"   "5.100/5.550/5.875" 
#> 4 Petal.Width  "   0.2/0.2/0.3"    "   1.2/1.3/1.5"      "   1.8/2.0/2.3"    
# }