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.
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 factorsI was able to make it work by changing the lines of your code where you handle non-numeric modx/mod2 by adding
ordered = Fto the factor line.Original:
Fix:
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.