Skip to content

sim_slopes(): Error with ordered factors #42

Description

@jzadra

I have a model with an interaction between a continuous predictor and an ordered factor predictor.

The sim_slopes() function gives the following error:
Error in relevel.ordered(dt[[modx]], ref = as.character(modxvals2[i])) : 'relevel' only for unordered factors

I was able to make it work by changing the lines of your code where you handle non-numeric modx/mod2 by adding ordered = F to the factor line.

Original:

else {
        dt[[modx]] <- factor(dt[[modx]])
        dt[[modx]] <- relevel(dt[[modx]], ref = as.character(modxvals2[i]))
        dt[[modx]] <- stats::C(dt[[modx]], "contr.treatment")
      }

Fix:

else {
        dt[[modx]] <- factor(dt[[modx]], ordered = F)
        dt[[modx]] <- relevel(dt[[modx]], ref = as.character(modxvals2[i]))
        dt[[modx]] <- stats::C(dt[[modx]], "contr.treatment")
      }

And same for mod2.

I would be curious to see if you think this will cause bad results, and if not perhaps it can be implemented? I'm guessing that the ordering doesn't matter for simple slopes.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions