library('forest')
library('knitr')
knitr::opts_chunk$set(
  fig.width = 8, fig.height = 6, message = FALSE, eval = TRUE
)

intro

library('survival')
lung2 <- within(lung, {
  sex <- factor(sex, 1:2, c('Male', 'Female'))
  ph.ecog <- factor(ph.ecog, 0:2)
  ph.ecog2 <- factor(ph.ecog, 0:2, ordered = TRUE)
})

mod <- coxph(Surv(time, status) ~ age + sex + ph.ecog2, lung2)
clean <- cleanfp(mod)
clean_ref <- add_reference(clean, c('Age (years)', 'Sex',
                                    'ECOG performance score'))
# clean_ref <- add_reference(clean)
prep_list <- prepare_forest(clean_ref)

plot(prep_list)

examples

survival::coxph

library('survival')
mod <- coxph(Surv(time, status) ~ age + factor(sex) + rx, colon)
forest(mod)
forest(mod, plotArgs = list(show_conf = TRUE, xlim = c(0, 2)))

coxphf::coxphf

Note: add the data argument

library('coxphf')
mod <- coxphf(Surv(time, status) ~ age + factor(sex) + rx, colon)
forest(mod, data = colon, plotArgs = list(show_conf = TRUE, xlim = c(0, 2)))

stats::glm

mod <- glm(vs ~ factor(gear) + mpg, mtcars, family = 'binomial')
forest(mod)
forest(mod, plotArgs = list(show_conf = TRUE))

logistf::logistf

Note: add the data argument

library('logistf')
mod <- logistf(vs ~ factor(gear) + factor(am), mtcars)
forest(mod, data = mtcars)
forest(mod, data = mtcars, plotArgs = list(show_conf = TRUE, logx = TRUE))

stats::fisher.test

Note: add the data argument

mod <- mtcars
mod[] <- lapply(mod, function(x) +grepl('1|4', x))
forest(mpg ~ ., mod, plotArgs = list(xlim = c(0, 20), show_conf = TRUE))

cmprsk::crr

Note: add the formula and data arguments.

library('cmprsk')
mod <- with(transplant, {
  crr(futime, as.integer(event) - 1,
      cov1 = cbind(age, model.matrix(~ sex + abo)[, -1, drop = FALSE]))
})
forest(mod, ~ age + sex + abo, transplant)

cmprsk2::crr2

library('cmprsk2')
mod <- crr2(Surv(futime, event(censored) == death) ~ age + sex + abo, transplant)
forest(mod, header = c('Age at dx', 'Sex', 'Blood type'))

install

# install.packages('devtools')
devtools::install_github('raredd/forest', build_vignettes = TRUE)

session

within.list(utils::sessionInfo(), loadedOnly <- NULL)


raredd/forest documentation built on Feb. 19, 2024, 9:22 p.m.