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)
Run the code above in your browser using DataLab