Logistic回归中连续变量的交互图

时间:2019-09-06 03:23:23

标签: r plot logistic-regression interaction sjplot

我用连续预测变量之间的相互作用拟合了逻辑回归模型。

我在R中的county_rows <- sqldf(sprintf("select * from county_rows where 'date' LIKE '%s%%'", year)) 包中使用了plot_model()函数来获取此交互作用图,而我无法弄清楚该函数如何将体积归为2个因素。

sjPlot

enter image description here

0.36和3.15分别对应于最小和最大体积。

有人可以帮我解释这个情节吗?

还有其他方法可以绘制此交互关系图以进行逻辑回归吗?

谢谢

1 个答案:

答案 0 :(得分:1)

相互作用是在两个连续变量之间。该图使用Lag4作为x轴变量,然后选取Volume的几个值以显示DirectionLag4之间的关系如何随x的不同而变化。 Volume。默认情况下,选择Volume的最小值和最大值。您可以使用Volume自变量来显示Volume的中位数和四分位数或mdrt.values的均值和标准差(有关其他选项,请参见帮助)。例如:

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(上面左侧图中的红线)时,您可以在下面的热图中看到颜色从蓝色变为白色到红色,这表示Direction="Up"的概率降低为{正如上图所示,{1}}增加了。

enter image description here