显示交互术语影响的替代方法

时间:2018-04-04 18:05:03

标签: r regression

这是关于结果沟通的问题。主要是我想知道两种连续变量的交互项的影响的替代方法。

我有以下结果

my_scale <- function(...) as.numeric(scale(...))

iris_scaled <- iris %>% 
  mutate_at(vars(-Species), my_scale)

ex <- lm(Sepal.Length ~ (Sepal.Width + Petal.Length)^2, data = iris_scaled)

GGally::ggcoef(ex, conf.level = 0.90, exclude_intercept = TRUE) + 
  ggtitle("Interaction of sepal width and petal length associated with 
smaller sepal length") +
  theme_classic()

enter image description here

在上面的图片中,我可以看到互动词与结果之间的联系,但在与持怀疑态度的听众交谈时 - 或者证明与自己的关系时 - 我想知道是否有其他方式可以表现出来交互术语确实存在。

例如,我可以设想某人质疑与以下

的互动的情况
iris_scaled %>% 
  mutate(interaction = Sepal.Width * Petal.Length) %>% 
  ggplot(aes(y = Sepal.Length, x = interaction)) +
  geom_point() +
  geom_smooth(method = lm, se = FALSE, color = "black") +
  theme_classic()

enter image description here

您如何以容易消化的方式谈论互动?

编辑 - 一些额外的统计数据

我不想让它听起来像我认为具有交互的模型比没有交互的模型更好。

请参阅下面的统计数据。

我只是想讨论可视化交互的替代方法。也许iris数据集是一个糟糕的选择,但它是第一个想到的,因为它有两个连续的变量。

> broom::glance(ex)
  r.squared adj.r.squared     sigma statistic      p.value df    logLik     AIC      BIC deviance df.residual
 0.8436057     0.8403921 0.3995096  262.5125 1.343031e-58  4 -73.18601 156.372 171.4252 23.30276         146

> ex_noint <- lm(Sepal.Length ~ Sepal.Width + Petal.Length, data = iris_scaled)
> broom::glance(ex_noint)
  r.squared adj.r.squared    sigma statistic      p.value df    logLik      AIC      BIC deviance df.residual
 0.8401778     0.8380034 0.402488  386.3862 2.933054e-59  3 -74.81209 157.6242 169.6667  23.8135         147

> anova(ex, ex_noint)
Analysis of Variance Table

Model 1: Sepal.Length ~ (Sepal.Width + Petal.Length)^2
Model 2: Sepal.Length ~ Sepal.Width + Petal.Length
  Res.Df    RSS Df Sum of Sq   F  Pr(>F)  
1    146 23.303                           
2    147 23.814 -1  -0.51075 3.2 0.07571 .
---
Signif. codes:  0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1

1 个答案:

答案 0 :(得分:2)

一种方法是将一个连续变量量化为示例箱,以显示第一个变量的斜率如何在该范围内变化。

library(broom)


  augment(
    lm(Sepal.Length ~ (Sepal.Width + Petal.Length)^2, data = iris),
    newdata = 
      expand.grid(Sepal.Width  = range(iris$Sepal.Width),
                  Petal.Length = quantile(iris$Petal.Length))
    ) %>% 
  ggplot(aes(Sepal.Width, .fitted, color = Petal.Length)) + 
  geom_line(aes(group = Petal.Length)) +
  geom_point(data = iris, aes(y = Sepal.Length)) +
  scale_color_gradient(low = "blue", high = "green") +
  theme_classic()

enter image description here

您必须非常小心地在随附的文本和标签中指出这些是条件模型预测。你还必须决定哪个是“主”变量,哪个是你正在调整的变量。看看如何扭转局面:

enter image description here

相关问题