I am running an ordinal logistic regression in R and running into trouble when I include dummy variables. My model works great with my first set of predictors. Next I want to add dummy variables for each of the years represented in my dataset.
I created the dummy variables with
car:recode in this manner (one statement like this for each of the 11 years)
fsd$admityear2000 <- recode(fsd$ApplicationYear ,"2000=1;else=0")
The lrm model is specified as follows
library(Design) ddist<- datadist(fsd) options(datadist='ddist') m4 <- lrm(Outcome ~ relGPA + mcAvgGPA + Interview_Z + WorkHistory_years + GMAT + UGI_Gourman + admityear1999 + admityear2000 + admityear2001 + admityear2002 + admityear2003 + admityear2004 + admityear2005 + admityear2006 + admityear2007 + admityear2008 + admityear2009, data=fsd)
(sorry for all of the other random variables, but I don't want to introduce confusion by changing my code)
I get the error
singular information matrix in lrm.fit (rank= 22 ). Offending variable(s): admityear2009 admityear2000 admityear1999 Error in lrm(Outcome ~ relGPA + mcAvgGPA + Interview_Z + WorkHistory_years + : Unable to fit model using “lrm.fit”
I understand that including all options of a dummy variable over-defines the model, but I get the error whether I include all 11 years or just 10.
I found a suggestion here to set the penalty parameter of
lrm to a small positive value. Setting it to 1 or 5 changes the error such that it only names one of the variables as offending. The error doesn't go away even with
I'm pretty new to R, but loving the freedom so far. Thanks for any help!
Responses and Lessons
- Factors are awesome and I can't believe I didn't notice them earlier. Man that cleans up my code a lot. Thanks!
- My DV, 'Outcome' is indeed ordinal and after making it a factor(), I also made it ordered().
- The str() command is also awesome and this is what my data now looks like (with some of the non-relevant variables omitted)
str(fsd) Outcome : Ord.factor w/ 3 levels "0"<"1"<"2" relGPA : num mcAvgGPA : num admitschool : Factor w/ 4 levels "1","2","3","4" appyear : Factor w/ 11 levels "1999","2000",..
- both lrm() and polr() now run successfully, and they both deal with appyear by dropping some values of the factor. lrm() drops 1999, 2000, and 2001 while polr() just drops 1999 and 2000. lrm() gives no warnings while polr() says "design appears to be rank-deficient, so dropping some coefs." This is an improvement, but I still don't understand why more than one value needs to be dropped. xtabs shows that there isn't full seperation right?
xtabs(~fsd$appyear + fsd$Outcome) fsd$Outcome fsd$appyear 0 1 2 1999 1207 123 418 2000 1833 246 510 2001 1805 294 553 2002 1167 177 598 2003 4070 158 1076 2004 2803 106 1138 2005 3749 513 2141 2006 4429 519 2028 2007 6134 670 1947 2008 7446 662 1994 2009 4411 86 1118