解释回归模型中的互动

时间:2015-11-11 04:05:56

标签: r regression lm interaction

我希望这是一个简单的问题。

我有一个实验设计,我从两组中测量一些反应(让我们说血压):对照组和受影响组,两组都给予三种治疗:t1,t2,t3。数据在任何意义上都不是配对的。

以下是一个示例数据:

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)))

我感兴趣的是量化每种治疗对受影响组相对于对照组的影响。我如何对此进行建模,比如使用线性模型(例如R中的lm)?

我错误地认为:

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

相当于:

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

不是我需要的?我认为在这个模型中治疗:组相互作用项与所有基线组和基线治疗测量的平均值相关。

因此我认为这个模型:

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

是我需要的,但是它量化了治疗和组间相互作用的每个组合术语:治疗t1:组控制治疗t1:组受影响治疗2:组控制治疗2:组受影响治疗3:组控制治疗3:受影响组

也许这个模型:

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

是正确的吗?

虽然除了量化治疗和受影响的相互作用项的每种组合之外,它还量化了每种治疗的效果。我不确定在这个模型中,每个治疗和受组影响的交互术语的基线是什么。

帮助将不胜感激。

另外,我们说我进行了第四次治疗,这实际上是两种治疗方法的组合,比如说t1 + t3,我不知道他们的综合效果的期望是什么:加法/减法或协同作用。有什么办法可以合并吗?

2 个答案:

答案 0 :(得分:2)

你的第一个规格没问题。

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 

第一个系数7.460表示当参与者同时接受t1治疗并受到影响时发生的影响。从左到右,第二个系数5.081表示参与者同时接受t2治疗和受影响等...

因此,例如,当参与者使用t2治疗并且在对照中效果为5.081 + 2.384。

如果我进行此分析,我会保留截距。

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  

现在,第二个系数从左到右表示用t2治疗的参与者的影响,并且相对于用t1治疗的患者和受影响的参与者。要看到这个通知7.460 - 2.378 = 5.081(第一个规范中的第二个系数)。我喜欢这种方法,因为它可以更容易地解释相对效果。

所有人都说@MrFlick是对的。这是交叉验证的问题。

答案 1 :(得分:2)

交互术语告诉您组之间的差异取决于治疗,即受影响和控制之间的差异对于t1,t2和t3是不同的。

我会对截距进行建模。

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

在获得重要的互动期后,我会使用t.tests进一步调查并帮助解释。

可以看出,相互作用是由t2相对于其他因素的较大影响所驱动的。

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))

enter image description here