You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I am having issues plotting interactions when including scaling/transformation/polynomials in models.
plot_model(model, type = "int") works as expected when scaling is not included in the model formula, but when scaling is included I get the following error.
model <- lme4::lmer(mpg ~ scale(hp) * wt + (1 | cyl), data = mtcars)
plot_model(model, type = "int")
Error: Some of the specified terms were not found in the model. Maybe misspelled?
I get the same error if I try to define the terms myself. plot_model(model, type = "pred") works as expected, however, which makes me think my issues may be due to how insight::find_predictors() returns predictors cleaned of scaling/transformation while insight::find_interactions() returns model interactions including scaling/transformation.
Is there another way to use type = "int" when scale or transformations are included in the model formula?
I have a reproducible example below with some notes on the outputs that I am getting. I am using R version 4.4.0, sjPLot 2.8.16, and insight 0.19.11.
Thanks for your help!
data("mtcars")
## Model without scaling predictors
model <- lme4::lmer(mpg ~ hp * wt + (1 | cyl), data = mtcars)
plot_model(model, type = "pred")
plot_model(model, type = "int")
plot_model(model, type = "int", terms = c("hp", "wt"))
# All work as expected
insight::find_predictors(model, component = "conditional", flatten = TRUE)
# Returns: "hp" "wt"
insight::find_interactions(model, component = "conditional", flatten = TRUE)
# Returns "hp:wt"
# Model with scaled predictor
model <- lme4::lmer(mpg ~ scale(hp) * wt + (1 | cyl), data = mtcars)
plot_model(model, type = "pred")
# Works as expected
plot_model(model, type = "int")
# Error: Some of the specified `terms` were not found in the model. Maybe misspelled?
plot_model(model, type = "int", terms = c("hp", "wt"))
# Error: Some of the specified `terms` were not found in the model. Maybe misspelled?
plot_model(model, type = "int", terms = c("scale(hp)", "wt"))
# Error: Some of the specified `terms` were not found in the model. Maybe misspelled?
insight::find_predictors(model, component = "conditional", flatten = TRUE)
# Returns: "hp" "wt"
insight::find_interactions(model, component = "conditional", flatten = TRUE)
# Returns: "scale(hp):wt"
The text was updated successfully, but these errors were encountered:
Thanks, probably the scale() function is not properly removed from the term-names. I'll take a look.
Alternatively, you could use the ggeffects package directly, which is internally used by sjPlot. Using ggeffects for predictions is more flexible, and the plot() method is easy to use and highly customizable (see, e.g., here and here).
Hi Daniel,
I am having issues plotting interactions when including scaling/transformation/polynomials in models.
plot_model(model, type = "int")
works as expected when scaling is not included in the model formula, but when scaling is included I get the following error.I get the same error if I try to define the terms myself.
plot_model(model, type = "pred")
works as expected, however, which makes me think my issues may be due to howinsight::find_predictors()
returns predictors cleaned of scaling/transformation whileinsight::find_interactions()
returns model interactions including scaling/transformation.Is there another way to use
type = "int"
when scale or transformations are included in the model formula?I have a reproducible example below with some notes on the outputs that I am getting. I am using
R version 4.4.0
,sjPLot 2.8.16
, andinsight 0.19.11
.Thanks for your help!
The text was updated successfully, but these errors were encountered: