Skip to content

Confusion about coxph and Helmert contrasts

2 messages · Christian Lederer, Peter Dalgaard

#
Hi,

perhaps this is a stupid question, but i need some help about
Helmert contrasts in the Cox model.


I have a survival data frame with an unordered factor `group'
with levels 0 ... 5.
Calculating the Cox model with Helmert contrasts, i expected that
the first coefficient would be the same as if i had used treatment 
contrasts, but this is not true.
I this a error in reasoning, or is it possible, that both contrasts use
a different ordering of the levels?
I am confused about the fact, that coefficients for different levels are 
calculated, depending on weather i include level 0 or not:

If level 0 is included, with both contrasts coxph calculates 
coefficients for group 1 ... group 5.
But if i exclude level 0, coxph calculates coeffficients for
group 2 ... 5 with treatment and coefficients for group 1 ... 4 using
helmert:

 > options(contrasts = c("contr.treatment", "contr.poly"))
 > cox.t <- coxph(Surv(time,cens) ~ as.factor(group), data=data)
 > options(contrasts = c("contr.helmert", "contr.poly"))
 > cox.h <- coxph(Surv(time,cens) ~ as.factor(group), data=data)
 > cox.t$coefficients
as.factor(group)1 as.factor(group)2 as.factor(group)3 as.factor(group)4
        -0.4301351         0.2078431        -0.0694138         0.3442058
as.factor(group)5
         0.1368716
 > cox.h$coefficients
as.factor(group)1 as.factor(group)2 as.factor(group)3 as.factor(group)4
      -0.215067529       0.140970216       0.001170877       0.083426449
as.factor(group)5
       0.021061935

 > data <- data[data$group > 0,]
 > options(contrasts = c("contr.treatment", "contr.poly"))
 > cox.t <- coxph(Surv(time,cens) ~ as.factor(group), data=data)
 > options(contrasts = c("contr.helmert", "contr.poly"))
 > cox.h <- coxph(Surv(time,cens) ~ as.factor(group), data=data)
 > cox.t$coefficients
as.factor(group)2 as.factor(group)3 as.factor(group)4 as.factor(group)5
         0.6399999         0.3612753         0.7762236         0.5688559
 > cox.h$coefficients
as.factor(group)1 as.factor(group)2 as.factor(group)3 as.factor(group)4
        0.31999997        0.01375844        0.11061629        0.02489624

A am absolutely confused; any help is welcome.

Christian :-)
#
christianlederer at t-online.de (Christian Lederer) writes:
.....
You are not the first... Probably the best way of becoming less
confused is to look at the contrast matrices:
2 3 4 5
1 0 0 0 0
2 1 0 0 0
3 0 1 0 0
4 0 0 1 0
5 0 0 0 1
[,1] [,2] [,3] [,4]
1   -1   -1   -1   -1
2    1   -1   -1   -1
3    0    2   -1   -1
4    0    0    3   -1
5    0    0    0    4

These give the coefficient matrices for mapping from regression
coefficients to individual group levels (determined up to an additive
constant of course). Staring long enough at these you'll realize
that the first treatment contrast is the difference between gr1 and
gr2 but the first Helmert contr. is *half* that difference, etc.