Factors ordered vs. levels

后端 未结 2 530
迷失自我
迷失自我 2020-12-03 18:35

Can someone explain what is the use of the \"ordered\" parameter in R?

R says:

ordered
logical flag to determine if the levels should be

2条回答
  •  醉话见心
    2020-12-03 18:40

    Let's do some reading.

    From ?factor:

    levels an optional vector of the values that x might have taken. The default is the unique set of values taken by as.character(x), sorted into increasing order of x. Note that this set can be specified as smaller than sort(unique(x)).

    So if left unspecified, it will sort the unique values for you and treat that as the order.

    As Ben mentioned, the question of how ordered and unordered factors differ in practice is much more complicated and usually relies on a presumption that you know a reasonable amount of statistics. The documentation only says:

    Ordered factors differ from factors only in their class, but methods and the model-fitting functions treat the two classes quite differently.

    Again, as Ben mentions, many model fitting routines will treat ordered and unordered factors very differently because they have very different statistical meanings and interpretations. A detailed summary of the statistical differences is probably way beyond the scope of a StackOverflow answer.

提交回复
热议问题