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 trying to use interact_plot function from the interactions package to visualize a 3-way interaction with survey data (svyglm object).
When I plot the following:
m <- svyglm(a ~ b * c * d, design)
interact_plot(m, pred = c, modx = d, mod2 = b)
Model m works and I can get an interaction plot. When I try adding a covariate (factor variable e below) to my model m:
n <- svyglm(a ~ b * c * d + e, design)
interact_plot(n, pred = c, modx = d, mod2 = b)
I cannot get the interact plot to run. I keep getting the error message: “contrasts can be applied only to factors with 2 or more levels”.
I have already checked for missing values in model n and I made sure that I have enough levels in the factor variable e, but still keep getting the error.
Any help in finding a solution is much appreciated.
Edit: Reproducible example
library(survey)
library(interactions)
data(api) #loading built-in dataset api
plot1 above works. Now what I need is to add factor covariates to model l, like comp.imp. When I do that, I get the following error when I try interact_plot:
l2 <- svyglm(snum ~ stype * sch.wide * api99 + comp.imp, family= gaussian, rclus2)
interact_plot(l2, pred = api99 , modx = stype, mod2 = sch.wide)
Error in `contrasts<-`(`*tmp*`, value = contr.funs[1 + isOF[nn]]) :
contrasts can be applied only to factors with 2 or more levels
When I substitute the factor comp.imp for a numerical api00 variable
I have the same issue. First I thought it was related to this issue: scaled variables. But the error persisted. I checked the data: No NAs, the variables in the moderation are scaled metric measurements, not factor variables. The lmer-model itself runs fine. Any solutions available?
I am trying to use
interact_plot
function from the interactions package to visualize a 3-way interaction with survey data (svyglm object).When I plot the following:
Model m works and I can get an interaction plot. When I try adding a covariate (factor variable e below) to my model m:
I cannot get the interact plot to run. I keep getting the error message:
“contrasts can be applied only to factors with 2 or more levels”.
I have already checked for missing values in model
n
and I made sure that I have enough levels in the factor variablee
, but still keep getting the error.Any help in finding a solution is much appreciated.
Edit: Reproducible example
Building model with interaction
plot1
above works. Now what I need is to add factor covariates to model l, likecomp.imp
. When I do that, I get the following error when I tryinteract_plot
:When I substitute the factor
comp.imp
for a numericalapi00
variableIt also works and I can get the interaction plot to work.
The text was updated successfully, but these errors were encountered: