[R] coxph means not equal to means of model matrix

Bond, Stephen Stephen@Bond @end|ng |rom c|bc@com
Fri Sep 3 18:01:35 CEST 2021


Hi,

Please, help me understand what is happening with the means of a Cox model?
I have:
R version 4.0.2 (2020-06-22) -- "Taking Off Again"
Copyright (C) 2020 The R Foundation for Statistical Computing
Platform: x86_64-w64-mingw32/x64 (64-bit)

getOption("contrasts")
        unordered           ordered
"contr.treatment"      "contr.poly"

According to the help  coxph.object has a component holding the means of the X (model.matrix). This does not hold any more.
```
library(survival)
test1 <- list(time=c(4,3,1,1,2,2,3),
                   status=c(1,1,1,0,1,1,0),
                   x=c(0,2,1,1,1,0,0),
                   sex=factor(c(0,0,0,0,1,1,1)))
m1 <- coxph(Surv(time, status) ~ x + sex, test1)
m1$means
##        x      sex1
## 0.7142857 0.0000000
colMeans(model.matrix(m1))
##         x      sex1
## 0.7142857 0.4285714

```
Will new observations be scored using the zero mean from the object?? Is this just a reporting change where $means shows the reference level and no longer the mean of the model matrix??

Thanks everybody



	[[alternative HTML version deleted]]



More information about the R-help mailing list