Hide missing/NA interaction terms from sjPlot::plot_model()
of2 opened this issue · comments
Hi Daniel!
I am trying to generate plots of interaction terms from a linear model
There is some missingness in my categorical predictor variables - for instance, not every "region_new" is present for every "state" - so there will be some NA interaction terms, for example from the model summary:
stateACT:region_newRegional NA NA NA NA
stateNT:region_newCities NA NA NA NA
stateACT:region_newRemote NA NA NA NA
stateTAS:region_newRemote NA NA NA NA
stateVIC:region_newRemote NA NA NA NA
stateACT:region_newVery remote NA NA NA NA
stateTAS:region_newVery remote NA NA NA NA
stateVIC:region_newVery remote NA NA NA NA
This is because there is no data for "Regional" areas in the state "ACT", no "Cities" in state "NT", etc
However, when I use the function sjPlot::plot_model(..., type = 'int') as below, it plots predicted values for the interaction of stateACT:region_newRegional (and other interactions that should be missing/NA), while my expectation is that it should be empty/missing as seen in the selected model results summary above
writing_lm <- lm(writing ~ (year + state + region_new + grade)^2, data = scores_df)
summary(writing_lm)
plot_model(writing_lm, type = "int",colors = "Set1")
^ Plot generated with some predicted interaction terms that should be missing
Is there a way that I can tell sjPlot::plot_model to ignore/not to plot predicted values for these terms where it should be missing? I have not been able to figure out a good answer from reading the package documentation
Maybe there is a better/more tailored way to do this using the ggeffects() package?
I have also posted this on StackOverflow here: https://stackoverflow.com/questions/69623961/hide-missing-na-interaction-terms-from-sjplotplot-model
Thanks so much in advance for your help & advice!
Owen
Do you have a reproducible example?