lifelines icon indicating copy to clipboard operation
lifelines copied to clipboard

Formula in docs

Open CamDavidsonPilon opened this issue 4 years ago • 9 comments

there should not be a subscript i in the Xbar i on for Cox time varying formula.

Originally posted by @CamDavidsonPilon in https://github.com/CamDavidsonPilon/lifelines/discussions/1191#discussioncomment-200656

CamDavidsonPilon avatar Dec 12 '20 19:12 CamDavidsonPilon

Also https://lifelines.readthedocs.io/en/latest/Survival%20Regression.html#cox-s-proportional-hazard-model

CamDavidsonPilon avatar Dec 23 '20 16:12 CamDavidsonPilon

I have a question, why should I subtract the mean value in the Cox time varying formula? image For example, in this example, the actual mean value of var1 should be 0.3, but when calculating the matrix mean this value becomes 0.2. What is the actual meaning of the matrix mean?

Cryptojoyz avatar May 26 '23 10:05 Cryptojoyz

Subtracting the mean, or any value really, doesn't change the final inference. We subtract the mean internally for stability reasons during fitting.

Screenshot 2023-05-26 at 8 09 37 AM

CamDavidsonPilon avatar May 26 '23 12:05 CamDavidsonPilon

Thank you for your answer, but in results containing interaction items, this can cause interpretation headaches.For example, image β3 means the coefficient when prio takes 0, but after subtracting the mean, prio takes 0 means that prio is actually equal to the mean, then this mean should preferably have a practical meaning, while the mean of the matrix has no practical counterpart, which is just a value in mathematics.

Cryptojoyz avatar May 26 '23 12:05 Cryptojoyz

Subtracting the mean happens internally after all the interactions have been done. If you want to use interactions, you should use the forumla= kwarg.

CamDavidsonPilon avatar May 26 '23 13:05 CamDavidsonPilon

Sorry, I don't quite understand what is meant by subtracting the mean after the interaction term occurs, I used the equation below for the fit and when the results are interpreted, I would like to know if the value of X4 minus the mean is 0 or the original value of X4 is 0 when X4 takes 0?

ctv.fit(base_df, id_col="id", event_col="event", start_col="start", stop_col="stop", show_progress=True, formula="X1+X2+X3*X4") If it is similar to linear regression, then X3*X4 should actually be the (X3 - X3bar) * (X4 - X4bar) ?

Cryptojoyz avatar May 26 '23 14:05 Cryptojoyz

Am I to understand that subtracting the mean is doing the centering? If I have centered the matrix (subtracted the mean) before fitting, is subtracting the mean invalid?

Cryptojoyz avatar May 26 '23 14:05 Cryptojoyz

X1+X2+X3*X4 goes in, and then we subtract the mean of each column.

If I have centered the matrix (subtracted the mean) before fitting, is subtracting the mean invalid?

I don't think it's invalid - it doesn't change the results (the Cox coefficients are the same whether I demean or not)! But if you centered before, and you have interaction terms, then your interpretation will change.

However if you are doing probability prediction, that's different.

CamDavidsonPilon avatar May 26 '23 16:05 CamDavidsonPilon

Thank you so much!I'm much clearer!By the way,

there should not be a subscript i in the Xbar i on for Cox time varying formula.

subscript i is still in the Xbar in the latest document.

Cryptojoyz avatar May 26 '23 17:05 Cryptojoyz