In this question and in two other recent questions (here and here) you are interested in the "slope" that represents the relation of a continuous variable, NE
, to survival in a Cox proportional hazards model. You are particularly interested in whether the relation of NE
to survival differs between sexes; furthermore, individuals might belong to either of 2 Groups, G1
and G2
. I'll assume that linearity with respect to NE
and the proportional hazards assumption are both verified. I'll ignore the random-effects term* that you included in other related questions.
Much depends on how you want to treat the group membership issue. In the example of this question,** where there is little evidence for differences in outcome with respect to Group G1
versus G2
, preliminary data exploration and subject-matter knowledge might suggest that you simply remove the Group
variable from your model. Tests of the interaction term SexM:NE
would then provide the answer to your question about sex differences with respect to the relation of NE
to survival.
If you wish to maintain the breakdown by Group
, you might consider using the anova
wrapper for the Cox model output in R to provide a single test of the SexM:NE
coefficient, combining information from both Groups. The anova
function performs a hierarchical test of coefficients in the order of entry into the model, using the equivalent of Type I sums of squares. If the data are reasonably balanced among combinations of covariates (for survival models, in terms of event numbers) then this may provide a useful test provided that you are clear about what it examines. For example, if you specified the following model:
Surv(time,status)~ NE + Sex + Group + NE:Sex + NE:Group + Sex:Group + NE:Sex:Group
then anova
would first associate as much as possible with NE
, then with Sex
, then with Group
, and then test whether the NE:Sex
interaction significantly explained any residual. Note that this is a different way of evaluating the results of the model from the treatment-contrasts summaries provided by print
or summary
that you display above, even though it is based on the same model.
If you have a particular interest in the 3-way interaction among NE
, Sex
and Group
then you will need to examine contrasts of the coefficients, similar to what you propose but with an important difference in implementation. The test you propose is equivalent to a Wald test. Examining whether there was a difference between males and females with respect to the value of the NE
coefficient in Group G2, you would test whether $\beta_{SexM:NE}+\beta_{SexM:GroupG2:NE}$ (MG2-FG2
in your question) is different from 0. As the coefficient estimates are correlated, you need the variance of a sum of correlated variables, which in this example is:
$$ \mathop{\rm var}(\beta_{SexM:NE})+\mathop{\rm var}(\beta_{SexM:GroupG2:NE}) + 2\mathop{\rm cov}(\beta_{SexM:NE},\beta_{SexM:GroupG2:NE})$$
Your proposed Z-test (based on the square root of the variance) ignores the covariance of the estimates of the coefficients, which is necessary and is provided by the corresponding off-diagonal element of the variance-covariance matrix, which you can get from the vcov
function applied to your model. If you use the rms
package, then there is a contrast
function for that package's cph
Cox models that allows tests of arbitrary contrasts, including bootstrap non-parametric tests.
One warning on this approach, however: Terry Therneau, responsible for much of the survival analysis infrastructure in R, has warned in this vignette that the apparent similarity of Cox regression models to linear regression models does not necessarily extend to tests on contrasts of coefficients. Examine those arguments carefully as you proceed.
*In another question you note that you are also evaluating a "random effect" that only has 2 levels. Treating a variable with so few levels as a random effect can be considered inadvisable.
**The model results in this question differ from those in other questions you have asked recently on the same general matter. It helps to specify the seed for the random-number generator, e.g., with set.seed()
in R, before you generate your random data, to have reproducible "random" data for demonstration.