runehaubo / ordinal

R package ordinal: Regression Models for Ordinal Data
Other
34 stars 12 forks source link

How can I establish the reference category in an ordered DV? #19

Closed davidcanarte closed 2 years ago

davidcanarte commented 5 years ago

I am using a multinomial DV measuring provision of social support. This variable was originally constructed as 0 = No support, 1 = One Support, 2 = Multiplex support. I factored "No Support", "One Support" and "Multiplex Support" before running the regressions with clmm(). However, I remember that in STATA one can establish a reference with baseoutcome(). How can I do this with the ordinal package?

bbolker commented 5 years ago

By default, R will order factors alphabetically, so it will put "Multiplex Support" as the first level (probably not what you want). Probably the best way to handle this is to be explicit when you create the factor, e.g.

support <- factor(support_val, levels=c("No Support", "One Support", "Multiplex support"))

(if levels are provided, the factor levels are in the order explicitly given. Note that the values must exactly match those in the vector, e.g. including capitalization. Or if you're starting from a variable coded 0/1/2, you could use

support  <- factor(support_val, levels=0:2,
                  labels=c("No Support", "One Support", "Multiplex support")

You can also use the relevel() function to reset just the first level in a factor (moving all other levels back as appropriate), but this might lead to other levels being in a non-sensible order. The forcats package has a variety of additional utilities for working with factors, if you like the tidyverse.

davidcanarte commented 5 years ago

Thank you! I will do this and try again!

David Cañarte Ph.D. Candidate Department of Sociology and Criminology University of Florida dcanarte@ufl.edumailto:dcanarte@ufl.edu

On Jul 22, 2019, at 5:23 PM, Ben Bolker notifications@github.com<mailto:notifications@github.com> wrote:

By default, R will order factors alphabetically, so it will put "Multiplex Support" as the first level (probably not what you want). Probably the best way to handle this is to be explicit when you create the factor, e.g.

support <- factor(support_val, levels=c("No Support", "One Support", "Multiplex support"))

(if levels are provided, the factor levels are in the order explicitly given. Note that the values must exactly match those in the vector, e.g. including capitalization. Or if you're starting from a variable coded 0/1/2, you could use

support <- factor(support_val, levels=0:2, labels=c("No Support", "One Support", "Multiplex support")

The forcats package has a variety of additional utilities for working with factors, if you like the tidyverse.

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHubhttps://urldefense.proofpoint.com/v2/url?u=https-3A__github.com_runehaubo_ordinal_issues_19-3Femail-5Fsource-3Dnotifications-26email-5Ftoken-3DAHVG3YVQOIX3A2Q22GXY6PDQAYQLTA5CNFSM4IE5DH3KYY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOD2RGSTA-23issuecomment-2D513960268&d=DwMCaQ&c=sJ6xIWYx-zLMB3EPkvcnVg&r=MvzsRAgzzSX194v0V7MkPQ&m=VgmOe0ZkWTGZ8mUmCe5tfWtD9VpjZIdG3NOcWT_3H4k&s=jqu3ZL-S3A5Od4RZhTcHf8yvNZNteFzb4LlSjDxW98Y&e=, or mute the threadhttps://urldefense.proofpoint.com/v2/url?u=https-3A__github.com_notifications_unsubscribe-2Dauth_AHVG3YSPKUEZOAMOUBAS5ELQAYQLTANCNFSM4IE5DH3A&d=DwMCaQ&c=sJ6xIWYx-zLMB3EPkvcnVg&r=MvzsRAgzzSX194v0V7MkPQ&m=VgmOe0ZkWTGZ8mUmCe5tfWtD9VpjZIdG3NOcWT_3H4k&s=Q8lkltRnnV-Yqsb2ljnqox5EJ5R56sr8QQ7AOGBXn2A&e=.

bbolker commented 5 years ago

For what it's worth, this question is a pretty general R-related one, not specific to the ordinal package. In the future you might look for solutions on StackOverflow (or the general r-help mailing list, although that has a rather scary reputation). For what it's worth, the R users' mailing list at UF is also quite active and very friendly (http://www.r-gators.com/listserv/).