繁体   English   中英

从线性回归中绘制均值和均值的标准误差

[英]Plotting mean and standard error of mean from linear regression

我运行了一个多元线性回归,其中pred_acc是因连续变量, emotion_predemotion_target是两个虚拟编码的自变量,分别为 0 和 1。此外,我对这两个自变量之间的相互作用感兴趣。

model <- lm(predic_acc ~ emotion_pred * emotion_target, data = data_almost_final) 
summary(model)

    Residuals:
     Min       1Q   Median       3Q      Max 
-0.66049 -0.19522  0.01235  0.19213  0.67284 

Coefficients:
                            Estimate Std. Error t value Pr(>|t|)    
(Intercept)                  0.97222    0.06737  14.432  < 2e-16 ***
emotion_pred                 0.45988    0.09527   4.827 8.19e-06 ***
emotion_target               0.24383    0.09527   2.559 0.012719 *  
emotion_pred:emotion_target -0.47840    0.13474  -3.551 0.000703 ***
---
Signif. codes:  0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1

Residual standard error: 0.2858 on 68 degrees of freedom
  (1224 Beobachtungen als fehlend gelöscht)
Multiple R-squared:  0.2555,    Adjusted R-squared:  0.2227 
F-statistic: 7.781 on 3 and 68 DF,  p-value: 0.0001536

如果需要一些背景信息:我做了一项调查,夫妻必须预测他们的伴侣偏好。 预测个体的情绪为 state 0 或 1 (emotion_pred),目标个体的情绪为 state 0 或 1 (emotion_target)。 因此,有四种组合。

现在我想 plot 回归与自变量(0,1; 1,0; 1,1; 0,0)的每个组合的均值,并添加带有均值标准误差的误差条。 我根本不知道如何做到这一点。 任何人都可以帮助我吗?

这是从我的数据中提取的:

     pred_acc  emotion_pred  emotion_target
1  1.0000000              1               0
2  1.2222222              0               1
3  0.7777778              0               0
4  1.1111111              1               1
5  1.3888889              1               1

我希望它看起来如何的草图

使用emmip库中的emmeans

model <- lm(data=d2, pred_acc ~ emotion_pred*emotion_target)

emmip(model, emotion_pred ~ emotion_target, CIs = TRUE, style = "factor")

在此处输入图像描述

如果您想更多地控制图像或只是为了获取值,您可以直接使用emmeans function:

> emmeans(model , ~ emotion_pred * emotion_target )

 emotion_pred emotion_target emmean    SE df lower.CL upper.CL
            0              0  0.778 0.196  1   -1.718     3.27
            1              0  1.000 0.196  1   -1.496     3.50
            0              1  1.222 0.196  1   -1.274     3.72
            1              1  1.250 0.139  1   -0.515     3.01

然后你可以在这个 dataframe 上使用 ggplot 来制作你喜欢的任何图表。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM