I?m trying to set up Cox Proptional Hazard model with interactions between time and the covariates (which are categorical). The problem that I face is that how to define the interactions, i.e. ?x+cutStart:x?, properly. The code below illustrates the problem. R gives the error message ? X matrix deemed to be singular?, because ?x+cutStart:x? includes too many combinations of the dummies in the model. Any help is much appreciated! aml2=survSplit(aml,cut=c(10,20,30),end='time',event='status',start='start') aml2$cutStart=as.factor(aml2$start) coxph(Surv(start,time,status)~x+cutStart:x,data=aml2) -- View this message in context: http://r.789695.n4.nabble.com/coxph-how-to-define-interaction-terms-tp4679162.html Sent from the R help mailing list archive at Nabble.com.
The output is as follows. My question is how to include only the interaction terms where x is equal to "Maintained". (x has two possible values "Maintained" and "Nonmaintained".) -- View this message in context: http://r.789695.n4.nabble.com/coxph-how-to-define-interaction-terms-tp4679162p4679176.html Sent from the R help mailing list archive at Nabble.com.
Any ideas would be much appreciated; I suspect that this problem of constructing the dummies applies not only to function coxph but to other regression models in R as well. Effectively, my question is how to better control for which dummies and interactions to include in the model and which not. The following code shows a workaround. It works here reasonably well since x has only two levels, but if x has more levels, constructing the dummies manually for each level and keeping track of each of them becomes very difficult. A weird thing is that if onle replace line 4 with the problem reappears. Any idea why? A numeric (0 or 1) variable produces different interactions than a logical variable (FALSE or TRUE). -- View this message in context: http://r.789695.n4.nabble.com/coxph-how-to-define-interaction-terms-tp4679162p4679249.html Sent from the R help mailing list archive at Nabble.com.