Hi all, I am trying to do a ordered probit regression using polr(), replicating a result from SAS.>polr(y ~ x, dat, method='probit')suppose the model is y ~ x, where y is a factor with 3 levels and x is a factor with 5 levels, To get coefficients, SAS by default use the last level as reference, R by default use the first level (correct me if I was wrong), The result I got is a mixture, using first and last for different variables. I tried relevel, reorder, contrasts, but no success. I found what really matters is>options(contrasts = c("contr.treatment", "contr.poly"))or>options(contrasts = c("contr.SAS", "contr.poly"))so I guess I can set "contrasts= a list of contrasts" for each variables in polr(), but I cannot successfuly set the contrasts, what is the syntax? Is there a better way to do this? Thank you very much, Tian [[alternative HTML version deleted]]
Gregor Gorjanc
2006-Aug-17 06:30 UTC
[R] Setting contrasts for polr() to get same result of SAS
T Mu <muster <at> gmail.com> writes:> > Hi all, > > I am trying to do a ordered probit regression using polr(), replicating a > result from SAS. > > >polr(y ~ x, dat, method='probit') > > suppose the model is y ~ x, where y is a factor with 3 levels and x is a > factor with 5 levels, > > To get coefficients, SAS by default use the last level as reference, R by > default use the first level (correct me if I was wrong),Yes.> I tried relevel, reorder, contrasts, but no success. I found what really > matters isI am sure those can help but you need to be carefull to "reorder" levels that the order is the same in SAS and R.> >options(contrasts = c("contr.treatment", "contr.poly")) > > or > > >options(contrasts = c("contr.SAS", "contr.poly"))You can also set contrasts directly to factors via contrasts(x) <- contr.SAS where x is your factor. You can also set different contrasts to different factors. Gregor