getModelData4Forestplot: Get model data

Description Usage Arguments Examples

View source: R/getModelData4Forestplot.R

Description

A helper function for forestplotCombineRegrObj(). Extracts the data from the regression model fits and returns a list with model data gathered by the function prGetFpDataFromFit()

Usage

1
2
3
4
5
6
7
getModelData4Forestplot(
  regr.obj,
  exp = TRUE,
  variablesOfInterest.regexp,
  ref_labels,
  add_first_as_ref
)

Arguments

regr.obj

A list with all the fits that have variables that are to be identified through the regular expression

exp

Report in exponential form. Default true since the function was built for use with survival models.

variablesOfInterest.regexp

A regular expression identifying the variables that are of interest of comparing. For instance it can be "(score|index|measure)" that finds scores in different models that should be compared.

ref_labels

If add_first_as_ref is TRUE then this vector is used for the model fits.

add_first_as_ref

If you want that the first variable should be reference for that group of variables. The ref is a variable with the estimate 1 or 0 depending if exp() and the confidence interval 0.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
org.par <- par("ask" = TRUE)

# simulated data to test
set.seed(10)
ftime <- rexp(200)
fstatus <- sample(0:1, 200, replace = TRUE)
cov <- data.frame(
  x1 = runif(200),
  x2 = runif(200),
  x3 = runif(200)
)

library(rms)
ddist <- datadist(cov)
options(datadist = "ddist")

fit1 <- cph(Surv(ftime, fstatus) ~ x1 + x2, data = cov)
fit2 <- cph(Surv(ftime, fstatus) ~ x1 + x3, data = cov)

forestplotCombineRegrObj(
  regr.obj = list(fit1, fit2),
  variablesOfInterest.regexp = "(x2|x3)",
  reference.names = c("First model", "Second model"),
  new_page = TRUE
)

modifyNameFunction <- function(x) {
  if (x == "x1") {
    return("Covariate A")
  }

  if (x == "x2") {
    return(expression(paste("My ", beta[2])))
  }

  return(x)
}

forestplotCombineRegrObj(
  regr.obj = list(fit1, fit2),
  variablesOfInterest.regexp = "(x2|x3)",
  reference.names = c("First model", "Second model"),
  rowname.fn = modifyNameFunction,
  new_page = TRUE
)

par(org.par)

Example output

Loading required package: forestplot
Loading required package: grid
Loading required package: magrittr
Loading required package: checkmate
Loading required package: Gmisc
Loading required package: Rcpp
Loading required package: htmlTable
Loading required package: Hmisc
Loading required package: lattice
Loading required package: survival
Loading required package: Formula
Loading required package: ggplot2

Attaching package: 'Hmisc'

The following objects are masked from 'package:base':

    format.pval, units

Loading required package: SparseM

Attaching package: 'SparseM'

The following object is masked from 'package:base':

    backsolve

Greg documentation built on July 1, 2020, 6:59 p.m.