逻辑回归中连续变量的交互作用图

3
我使用逻辑回归模型拟合了连续预测变量之间的交互作用。我在R中使用sjPlot包中的plot_model()函数来获取这些交互作用图,并且我无法弄清楚该函数如何将体积分为2个因子。
require(ISLR)
require(sjPlot)

m1=glm(Direction ~ Lag1 + Lag4* Volume ,data=Smarket,family ="binomial" )

plot_model(m1,type = "int",colors =rainbow(3))

enter image description here

0.36和3.15分别对应最小和最大音量。

有人能帮我解释一下这个图吗?

还有其他绘制逻辑回归交互图的方法吗?

谢谢。

1个回答

2
交互作用发生在两个连续变量之间。该图使用 Lag4 作为 x 轴变量,然后选择一些 Volume 的值来展示在不同 Volume 值下,DirectionLag4 之间的关系如何变化。默认情况下,选择 Volume 的最小值和最大值。您可以使用 mdrt.values 参数来显示 Volume 的中位数和四分位数或 Volume 的均值和标准差(请参阅帮助以获取其他选项)。例如:
theme_set(theme_classic()) # Set ggplot theme

plot_model(m1, type="int", colors=rainbow(3), mdrt.values="quart")
plot_model(m1, type="int", colors=rainbow(3), mdrt.values="meansd")

enter image description here

另一种选择是热力图,它允许您在x和y轴上绘制交互变量,并使用颜色表示“Direction”等于“Up”的概率。例如:
# Create grid of Lag1 and Volume values for prediction
pred.dat = expand.grid(Lag1 = median(Smarket$Lag1),
                       Lag4 = seq(min(Smarket$Lag4), max(Smarket$Lag4), length=100),
                       Volume = seq(min(Smarket$Volume), max(Smarket$Volume), length=100))

# Add predictions
pred.dat$Direction = predict(m1, newdata=pred.dat, type="response")

# Plot heatmap
ggplot(pred.dat, aes(Lag4, Volume, fill=Direction)) + 
  geom_tile() +
  scale_fill_gradient2(low="red", mid="white", high="blue", 
                       midpoint=median(pred.dat$Direction)) +
  labs(title='Probability of Direction="Up"',
       fill="Probability")

上面的图表代表了下面热力图中等值线的Volume。例如,当Volume为1.12(上图左侧的红线)时,您可以在下面的热力图中看到颜色从蓝色变为白色再到红色,表示随着Lag4的增加,Direction="Up"的概率逐渐减小,就像我们在上面的图中看到的一样。

enter image description here


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接