[R] Setting contrasts for polr() to get same result of SAS

Gregor Gorjanc gregor.gorjanc at bfro.uni-lj.si
Thu Aug 17 08:30:35 CEST 2006


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 is

I 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



More information about the R-help mailing list