[R] ordered factor and unordered factor
Peng Yu
pengyu.ut at gmail.com
Tue Nov 10 03:39:27 CET 2009
Why the contrast matrices are different for order and unordered factored?
On Mon, Nov 9, 2009 at 1:12 PM, Greg Snow <Greg.Snow at imail.org> wrote:
> Mostly it is a conceptual difference. An unordered factor is one where there is no inherent order to the levels, examples:
>
> Color of car
> Race
> Nationality
> Sex
> State/Country of birth
> Etc.
>
> In the above, the order of the levels could be changed without it really changing the meaning (think of the order of bars in a bar chart). We may want to print/plot in some specific order such as alphabetic for easy lookup or based on the summary values of another vector for nice looking plots, but there is no overriding reason why we would order color as blue/green/red vs. green/red/blue, etc.
>
> Ordered factors have some natural order, for example maybe you are studying a drug and have doses labeled as Low, Medium, and High. It makes the most sense to print and plot in that order rather than alphabetically (High, Low, Medium). Any continuous variable that has been cut into categories (best not to do this, but if done) has a natural order. Survey questions where you response can range from strongly disagree to strongly agree are usually ordered (but there may be disagreement on what the correct ordering is).
>
> In R the most apparent effects of using ordered vs. factor is in how they print out and how some modeling functions default to handling them (the default contrasts for ordered factors is different, rpart treats ordered factors differently).
>
> Hope this helps,
>
> --
> Gregory (Greg) L. Snow Ph.D.
> Statistical Data Center
> Intermountain Healthcare
> greg.snow at imail.org
> 801.408.8111
>
>
>> -----Original Message-----
>> From: r-help-bounces at r-project.org [mailto:r-help-bounces at r-
>> project.org] On Behalf Of Peng Yu
>> Sent: Sunday, November 08, 2009 4:28 PM
>> To: r-help at stat.math.ethz.ch
>> Subject: [R] ordered factor and unordered factor
>>
>> I don't understand under what situation ordered factor rather than
>> unordered factor should be used. Could somebody give me some examples?
>> What are the implications of order vs. unordered factors? Could
>> somebody recommend a textbook to me?
>>
>> ______________________________________________
>> R-help at 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.
>
More information about the R-help
mailing list