[R] Contrasts in coxph

John Fox j|ox @end|ng |rom mcm@@ter@c@
Tue Apr 6 19:13:24 CEST 2021


Dear John,

It's not clear to me exactly what you have in mind, but 
car::linearHypothesis(), multcomp::glht(), and the emmeans package work 
with Cox models. I expect there are functions in other packages that 
will work too.

Here's an example, surely simpler than what you have in mind, but you 
can probably adapt it:

------------------ snip -----------------

 > library("survival")
 > library("car")
Loading required package: carData
 > mod.allison <- coxph(Surv(week, arrest) ~
+                        fin + age + race + wexp + mar + paro + prio,
+                      data=Rossi)
 > mod.allison
Call:
coxph(formula = Surv(week, arrest) ~ fin + age + race + wexp +
     mar + paro + prio, data = Rossi)

                    coef exp(coef) se(coef)      z       p
finyes         -0.37942   0.68426  0.19138 -1.983 0.04742
age            -0.05744   0.94418  0.02200 -2.611 0.00903
raceother      -0.31390   0.73059  0.30799 -1.019 0.30812
wexpyes        -0.14980   0.86088  0.21222 -0.706 0.48029
marnot married  0.43370   1.54296  0.38187  1.136 0.25606
paroyes        -0.08487   0.91863  0.19576 -0.434 0.66461
prio            0.09150   1.09581  0.02865  3.194 0.00140

Likelihood ratio test=33.27  on 7 df, p=2.362e-05
n= 432, number of events= 114
 >
 > linearHypothesis(mod.allison, "finyes")
Linear hypothesis test

Hypothesis:
finyes = 0

Model 1: restricted model
Model 2: Surv(week, arrest) ~ fin + age + race + wexp + mar + paro + prio

   Res.Df Df  Chisq Pr(>Chisq)
1    426
2    425  1 3.9306    0.04742 *
---
Signif. codes:  0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
 >
 > library("multcomp")
Loading required package: mvtnorm
Loading required package: TH.data
Loading required package: MASS

Attaching package: ‘TH.data’

The following object is masked from ‘package:MASS’:

     geyser

 > summary(glht(mod.allison, "finyes=0"))

	 Simultaneous Tests for General Linear Hypotheses

Fit: coxph(formula = Surv(week, arrest) ~ fin + age + race + wexp +
     mar + paro + prio, data = Rossi)

Linear Hypotheses:
             Estimate Std. Error z value Pr(>|z|)
finyes == 0  -0.3794     0.1914  -1.983   0.0474 *
---
Signif. codes:  0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
(Adjusted p values reported -- single-step method)

 >
 > library(emmeans)
 > pairs(emmeans(mod.allison, ~ fin))
  contrast estimate    SE  df z.ratio p.value
  no - yes    0.379 0.191 Inf 1.983   0.0474

------------------ snip -----------------

Results are averaged over the levels of: race, wexp, mar, paro
Results are given on the log (not the response) scale.

John Fox, Professor Emeritus
McMaster University
Hamilton, Ontario, Canada
web: https://socialsciences.mcmaster.ca/jfox/

On 2021-04-05 11:28 p.m., Sorkin, John wrote:
> I would like to define contrasts on the output of a coxph function. It appears that the contrast function from the contrast library does not have a method defined that will allow computation of contrasts on a coxph object.
> 
> How does one define and evaluate contrasts for a cox model?
> 
> Thank you,
> John
> 
> John David Sorkin M.D., Ph.D.
> Professor of Medicine
> Chief, Biostatistics and Informatics
> University of Maryland School of Medicine Division of Gerontology and Geriatric Medicine
> Baltimore VA Medical Center
> 10 North Greene Street
> GRECC (BT/18/GR)
> Baltimore, MD 21201-1524
> (Phone) 410-605-7119
> (Fax) 410-605-7913 (Please call phone number above prior to faxing)
> 
> 
> ______________________________________________
> R-help using r-project.org mailing list -- To UNSUBSCRIBE and more, see
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>



More information about the R-help mailing list