In a Cox model, the baseline hazard takes the place of an intercept. Try the following: dummy <- rnorm(nrow(goodexp)) testfit <- lm(dummy ~ ExpTemp + Stability + Period, data=goodexp, x=T)
Now look at testfit$x, which is the design matrix for the linear model with an intercept. Examination of it will first of all clarify for you exactly what dummy variable coding was used for the model. If this X matrix is singular, the coxph fit will be singular in exactly the same way and at the same place. If you regress the last column of testfit$x on the others you should get a perfect fit, given the output below. Other than the intercept the X matrix within coxph is the same as that for lm; the "intercept" is still there in the form of a baseline hazard, it just cannot be summarized as a single coefficient. (All R modeling functions use the same internal routine to generate the design matrix.) My guess is that the row sums of testfit$x are constant, but that's just a guess. Terry Therneau PS -- use the spacebar more when showing an example. It makes it a lot easier for the rest of us to read. On 01/24/2013 05:00 AM, r-help-requ...@r-project.org wrote: > Thank you for the suggestions. > > Just to clarify, my first question was more on what actual coding I > should be using to indicate a nested variable when using the coxph() > function. I asked this after consulting several times with a local > statistician, but unfortunately neither of us are very familiar with > R. > > After further consultation, I have changed the design to a 2*2 design > (2 levels of ExpTemp and Stability each) with blocking (Period). I am > still getting the "x matrix deemed to be singular" error. > >> > LOEmod3alt=coxph(LOE.fit~ExpTemp+Stability+Period,data=goodexp) > Warning message: > In coxph(LOE.fit ~ ExpTemp + Stability + Period, data = goodexp) : > X matrix deemed to be singular; variable 5 >> > summary(LOEmod3alt) > Call: > coxph(formula = LOE.fit ~ ExpTemp + Stability + Period, data = goodexp) > > n= 184, number of events= 105 > > coef exp(coef) se(coef) z Pr(>|z|) > ExpTemp -3.17825 0.04166 0.53105 -5.985 2.17e-09 *** > StabilityStatic -0.84129 0.43115 0.20470 -4.110 3.96e-05 *** > PeriodB 1.06794 2.90937 0.22859 4.672 2.98e-06 *** > PeriodC 1.23853 3.45054 0.58457 2.119 0.0341 * > PeriodD NA NA 0.00000 NA NA > --- > Signif. codes: 0 ?***? 0.001 ?**? 0.01 ?*? 0.05 ?.? 0.1 ? ? 1 > > exp(coef) exp(-coef) lower .95 upper .95 > ExpTemp 0.04166 24.0047 0.01471 0.118 > StabilityStatic 0.43115 2.3194 0.28866 0.644 > PeriodB 2.90937 0.3437 1.85877 4.554 > PeriodC 3.45054 0.2898 1.09723 10.851 > PeriodD NA NA NA NA > > Concordance= 0.833 (se = 0.03 ) > Rsquare= 0.591 (max possible= 0.995 ) > Likelihood ratio test= 164.4 on 4 df, p=0 > Wald test = 111.1 on 4 df, p=0 > Score (logrank) test = 179.9 on 4 df, p=0 > >> > with(redo, table(LOEStatusfull, Period,ExpTemp)) > , , ExpTemp = FIVE > > Period > LOEStatusfull A B C D > 0 42 0 35 0 > 1 4 0 11 0 > > , , ExpTemp = FOUR > > Period > LOEStatusfull A B C D > 0 0 0 0 2 > 1 0 46 0 44 > > As best as I can tell, none of my variables are collinear. Are there > any other suggestions of how to deal with this error, or any more > information I can provide to help understand why I would be getting > this? > > Thank you for your time and your help, > > Katie > > O [[alternative HTML version deleted]] ______________________________________________ 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.