在交互OLS中使用因子变量;情节麻烦

时间:2019-05-04 21:36:54

标签: r

我用三个术语创建了一个因子变量。我能够在模型中进行交互,但是插图无法识别出存在交互。 class(div)吐出“因素”。 attribute(div)吐出“ NULL”,而不是代码中显示的标签。我是r的新手,因此非常感谢您提供任何建议。

## creating a factor variable
data.i$div<-NA
data.i$div[data.i$SULLIVAN<=.297]<-"least diverse"
data.i$div[data.i$SULLIVAN>.297&data.i$SULLIVAN<=.328]<-"med diverse"
data.i$div[data.i$SULLIVAN>.328]<-"most diverse"

# create factor variable
div<-factor(data.i$div, levels = c("least diverse", "med diverse", "most 
diverse"))

## interaction model
model.int<-lm(formula = INC_VT ~ 0 + INC_PREV + NORMVOTE + DISCREP * div, 
data = data.i)

## interplot
interplot(model.int, "DISCREP", "div", plot=T, ci=0.95, hist = F)

Error in interplot.default(model.int, "DISCREP", "div", plot = T, ci = 
0.95,  : Model does not include the interaction of DISCREP and div .

0 个答案:

没有答案