[R] Contrasts in coxph
David Winsemius
dw|n@em|u@ @end|ng |rom comc@@t@net
Wed Apr 7 03:01:07 CEST 2021
On 4/5/21 8:28 PM, 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?
I suspect that you are hoping for post-hoc pairwise contrasts. If that's
the case, then the multcomp package's glht is generally very capable. It
has three examples in its vignette the involve survivla models. The last
one constructs a categorical variable for age. That's not a procedure
that I endorse, but it may have been done for illustration of a method
and would therefore be free of sin.
library(multcomp) # console output follows
> if (require("survival") && require("MASS")) {
+ ### construct 4 classes of age
+ Melanoma$Cage <- factor(sapply(Melanoma$age, function(x){if( x <=
25 ) return(1)
+ if( x > 25 & x <= 50 ) return(2)
+ if( x > 50 & x <= 75 ) return(3)
+ if( x > 75 & x <= 100) return(4) }
+ ))
+ }
> summary(Melanoma)
time status sex age year
thickness
Min. : 10 Min. :1.00 Min. :0.0000 Min. : 4.00 Min.
:1962 Min. : 0.10
1st Qu.:1525 1st Qu.:1.00 1st Qu.:0.0000 1st Qu.:42.00 1st
Qu.:1968 1st Qu.: 0.97
Median :2005 Median :2.00 Median :0.0000 Median :54.00 Median
:1970 Median : 1.94
Mean :2153 Mean :1.79 Mean :0.3854 Mean :52.46 Mean
:1970 Mean : 2.92
3rd Qu.:3042 3rd Qu.:2.00 3rd Qu.:1.0000 3rd Qu.:65.00 3rd
Qu.:1972 3rd Qu.: 3.56
Max. :5565 Max. :3.00 Max. :1.0000 Max. :95.00 Max.
:1977 Max. :17.42
ulcer Cage
Min. :0.000 1: 14
1st Qu.:0.000 2: 73
Median :0.000 3:104
Mean :0.439 4: 14
3rd Qu.:1.000
Max. :1.000
> cm <- coxph(Surv(time, status == 1) ~ Cage, data = Melanoma)
> ### specify all pair-wise comparisons among levels of "Cage"
> cm.glht <- glht(cm, mcp(Cage = "Tukey"))
> cm.glht
General Linear Hypotheses
Multiple Comparisons of Means: Tukey Contrasts
Linear Hypotheses:
Estimate
2 - 1 == 0 -0.2889
3 - 1 == 0 0.1910
4 - 1 == 0 1.0742
3 - 2 == 0 0.4800
4 - 2 == 0 1.3631
4 - 3 == 0 0.8832
--
David.
>
> 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