Last data update: 2014.03.03

R: Compares different scores in different regression objects.
forestplotCombineRegrObjR Documentation

Compares different scores in different regression objects.

Description

Creates a composite from different regression objects into one forestplot where you can choose the variables of interest to get an overview and easier comparison.

Usage

forestplotCombineRegrObj(regr.obj, variablesOfInterest.regexp, reference.names,
  rowname.fn, estimate.txt, exp = xlog, add_first_as_ref = FALSE,
  ref_txt = "ref.", ref_labels = c(), digits = 1, is.summary, xlab, zero,
  xlog, ...)

Arguments

regr.obj

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

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.

reference.names

Additional reference names to be added to each model

rowname.fn

A function that takes a rowname and sees if it needs beautifying. The function has only one parameter the coefficients name and should return a string or expression.

estimate.txt

The text of the estimate, usually HR for hazard ratio, OR for odds ratio

exp

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

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.

ref_txt

Text instead of estimate number

ref_labels

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

digits

Number of digits to use for the estimate output

is.summary

A vector indicating by TRUE/FALSE if the value is a summary value which means that it will have a different font-style

xlab

x-axis label

zero

Indicates what is zero effect. For survival/logistic fits the zero is 1 while in most other cases it's 0.

xlog

If TRUE, x-axis tick marks are to follow a logarithmic scale, e.g. for logistic regressoin (OR), survival estimates (HR), poisson regression etc. Note: This is an intentional break with the original forestplot function as I've found that exponentiated ticks/clips/zero effect are more difficult to for non-statisticians and there are sometimes issues with rounding the tick marks properly.

...

Passed to forestplot

See Also

Other forestplot wrappers: forestplotRegrObj

Examples

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)

Results


R version 3.3.1 (2016-06-21) -- "Bug in Your Hair"
Copyright (C) 2016 The R Foundation for Statistical Computing
Platform: x86_64-pc-linux-gnu (64-bit)

R is free software and comes with ABSOLUTELY NO WARRANTY.
You are welcome to redistribute it under certain conditions.
Type 'license()' or 'licence()' for distribution details.

R is a collaborative project with many contributors.
Type 'contributors()' for more information and
'citation()' on how to cite R or R packages in publications.

Type 'demo()' for some demos, 'help()' for on-line help, or
'help.start()' for an HTML browser interface to help.
Type 'q()' to quit R.

> library(Greg)
Loading required package: forestplot
Loading required package: grid
Loading required package: magrittr
Loading required package: Gmisc
Loading required package: Rcpp
Loading required package: htmlTable
> png(filename="/home/ddbj/snapshot/RGM3/R_CC/result/Greg/forestplotCombineRegrObj.Rd_%03d_medium.png", width=480, height=480)
> ### Name: forestplotCombineRegrObj
> ### Title: Compares different scores in different regression objects.
> ### Aliases: forestplotCombineRegrObj
> 
> ### ** Examples
> 
> 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)
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, round.POSIXt, trunc.POSIXt, units

Loading required package: SparseM

Attaching package: 'SparseM'

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

    backsolve

> 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)
> 
> 
> 
> 
> 
> dev.off()
null device 
          1 
>