代码之家  ›  专栏  ›  技术社区  ›  Alex

显示交互项影响的替代方法

  •  0
  • Alex  · 技术社区  · 8 年前

    这是一个关于结果交流的问题。我主要想知道两个连续变量相互作用项的效果的其他沟通方式。

    我有以下结果

    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 dataset是一个糟糕的选择,但它是第一个出现在脑海中的,因为它有两个连续变量。

    > 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 回复  |  直到 8 年前
        1
  •  2
  •   Brian    8 年前

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

    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