Re: [R] coxph: how to define interaction terms?
On Oct 29, 2013, at 4:38 AM, rm wrote: > 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 > > You should go to the R-help Archive to see what the vast majority of readers of this mailing list are seeing. https://stat.ethz.ch/pipermail/r-help/2013-October/362203.html > > 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. > __ "R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html"; ^^ And you should read both the fine posting guide and the messages that Nabble suppresses in its effort to masquerade as Rhelp. "and provide commented, minimal, self-contained, reproducible code." -- David Winsemius Alameda, CA, USA __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] coxph: how to define interaction terms?
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. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] coxph: how to define interaction terms?
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. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] coxph: how to define interaction terms?
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. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.