Interpreting interactions in a regression model

杀马特。学长 韩版系。学妹 提交于 2019-12-02 01:35:31

The interaction term tells you that the difference between groups is dependent on treatment, that is, that the difference between affected and control is not the same for t1, t2 and t3.

I would model the intercept though.

lm(response ~ group + treatment + group:treatment, data=df)

After getting a significant interaction term I would use t.tests to further investigate and to help with interpretation.

As can be seen the interaction is driven by the larger effect of t2 relative to the others.

library(data.table)
library(dplyr)
library(ggplot2)

set.seed(1)
df <- data.frame(response = c(rnorm(5,10,1),rnorm(5,10,1),rnorm(5,10,1),rnorm(5,7,1),rnorm(5,5,1),rnorm(5,10,1)),
             group = as.factor(c(rep("control",15),rep("affected",15))),
             treatment = as.factor(rep(c(rep("t1",5),rep("t2",5),rep("t3",5)),2)))

# t tests of the desired comparisons to see if there is a difference and get 95% confidence intervals
t.test(df$response[df$treatment=="t1"] ~ df$group[df$treatment=="t1"])
t.test(df$response[df$treatment=="t2"] ~ df$group[df$treatment=="t2"])
t.test(df$response[df$treatment=="t3"] ~ df$group[df$treatment=="t3"])

# plot 95% C.I.
ci_plot <- matrix(nrow=3, ncol=3)
ci_plot <- as.data.frame(ci_plot)
colnames(ci_plot) <- c("treatment", "lci", "uci")

ci_plot[,1] <- c("t1", "t2", "t3")
ci_plot[,3] <- c(t.test(df$response[df$treatment=="t1"] ~ df$group[df$treatment=="t1"])$conf.int[1],
             t.test(df$response[df$treatment=="t2"] ~ df$group[df$treatment=="t2"])$conf.int[1],
             t.test(df$response[df$treatment=="t3"] ~ df$group[df$treatment=="t3"])$conf.int[1])
ci_plot[,4] <- c(t.test(df$response[df$treatment=="t1"] ~ df$group[df$treatment=="t1"])$conf.int[2],
             t.test(df$response[df$treatment=="t2"] ~ df$group[df$treatment=="t2"])$conf.int[2],
             t.test(df$response[df$treatment=="t3"] ~ df$group[df$treatment=="t3"])$conf.int[2])

ggplot(ci_plot, aes(x=treatment, y=uci)) +
    geom_errorbar(aes(ymin=uci, ymax=lci), width=0.5, position=position_dodge(0.9), weight=0.5) +
    xlab("Treatment") +
    ylab("Change in mean relative to control (95% C.I.)") +
    theme_bw() +
    theme(panel.border = element_blank(),
          panel.grid.major = element_blank(),
          panel.grid.minor = element_blank(),
          axis.line = element_line(colour = "black"),
          axis.text.x = element_text(angle = 90, hjust = 1))

Your first specification is fine.

lm(response ~  0 + treatment * group, data = df)

Call:
lm(formula = response ~ 0 + treatment * group, data = df)

Coefficients:
         treatmentt1               treatmentt2               treatmentt3  
               7.460                     5.081                     9.651  
        groupcontrol  treatmentt2:groupcontrol  treatmentt3:groupcontrol  
               2.670                     2.384                    -2.283 

The first coefficient, 7.460, represents the effect that occurs when a participant is both treated with t1 and affected. Going from left to right, the second coefficient, 5.081, represents when a participant is both treated with t2 and affected, etc...

So for example, when a participant is treated with t2 and in the control the effect is 5.081 + 2.384.

If I were doing this analysis, I would keep the intercept.

Call:
lm(formula = response ~ treatment * group, data = df)

Coefficients:
         (Intercept)               treatmentt2               treatmentt3  
               7.460                    -2.378                     2.192  
        groupcontrol  treatmentt2:groupcontrol  treatmentt3:groupcontrol  
               2.670                     2.384                    -2.283  

Now the second coefficient, going from left to right, represents the effect of participants treated with t2 and affected relative to participants treated with t1 and affected. To see this notice that 7.460 - 2.378 = 5.081 (the second coefficient in the first specification). I like this approach because it makes it easier to interpret the relative effects.

That all being said @MrFlick is right. This is a question for Cross Validation.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!