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]]
Therneau, Terry M., Ph.D.
2021-Sep-03 16:37 UTC
[R] coxph means not equal to means of model matrix
See ?coxph, in particular the new "nocenter" option. Basically, the "mean" component is used to center later computations.? This can be critical for continuous variables, avoiding overflow in the exp function, but is not necessary for 0/1 covariates.?? The fact that the default survival curve would be for a sex of .453, say, was off-putting to many. Terry T. On 9/3/21 11:01 AM, Bond, Stephen wrote:> > 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]]