Skip to content
Prev 387714 / 398502 Next

Contrasts in coxph

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:
Message-ID: <04ed429b-e395-adb8-b643-de6df730d614@mcmaster.ca>
In-Reply-To: <24118_1617679737_1363Suiw018542_MN2PR03MB51678A76DFF4A1CA8D7D8A03E2769@MN2PR03MB5167.namprd03.prod.outlook.com>