为什么 R 和 PROCESS 会呈现不同的中介模型结果(一个重要,另一个不重要)?

发布于 2025-01-20 11:34:19 字数 934 浏览 2 评论 0原文

作为刚刚开始R的新来者,我对调解分析的结果感到困惑。

我的模型很简单:iv't1incivi',调解器't1envied',dv't2psrb'。我使用过程在SPSS中运行了相同的模型,但是结果在过程中并不重要。但是,间接效果在R中很重要。由于我对R不太熟悉,您能帮我看看我的代码是否有任何问题?并告诉我为什么结果在R中很重要,但在SPSS中却不重要。谢谢一堆!!!

我在R:

X预测M

apath <- lm(T1Envied~T1Incivi, data=dat)
summary(apath)

X和M中的代码预测

bpath <- lm(T2PSRB~T1Envied+T1Incivi, data=dat)
summary(bpath)

间接效果的引导

getindirect <- function(dataset,random){
  d=dataset[random,]
  apath <- lm(T1Envied~T1Incivi, data=d)
  bpath <- lm(T2PSRB~T1Envied+T1Incivi, data=dat)
  indirect <- apath$coefficients["T1Incivi"]*bpath$coefficients["T1Envied"]
  return(indirect)
}
library(boot)
set.seed(6452234)
Ind1 <- boot(data=dat,
             statistic=getindirect,
             R=5000)

boot.ci(Ind1, 
        conf = .95,
        type = "norm")`*PSRB as outcome*

As a newcomer who just gets started in R, I am confused about the result of the mediation analysis.

My model is simple: IV 'T1Incivi', Mediator 'T1Envied', DV 'T2PSRB'. I ran the same model in SPSS using PROCESS, but the result was insignificant in PROCESS; however, the indirect effect is significant in R. Since I am not that familiar with R, could you please help me to see if there is anything wrong with my code? And tell me why the result is significant in R but not in SPSS?Thanks a bunch!!!

My code in R:

X predict M

apath <- lm(T1Envied~T1Incivi, data=dat)
summary(apath)

X and M predict Y

bpath <- lm(T2PSRB~T1Envied+T1Incivi, data=dat)
summary(bpath)

Bootstrapping for indirect effect

getindirect <- function(dataset,random){
  d=dataset[random,]
  apath <- lm(T1Envied~T1Incivi, data=d)
  bpath <- lm(T2PSRB~T1Envied+T1Incivi, data=dat)
  indirect <- apath$coefficients["T1Incivi"]*bpath$coefficients["T1Envied"]
  return(indirect)
}
library(boot)
set.seed(6452234)
Ind1 <- boot(data=dat,
             statistic=getindirect,
             R=5000)

boot.ci(Ind1, 
        conf = .95,
        type = "norm")`*PSRB as outcome*

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

月野兔 2025-01-27 11:34:19

在您的函数 getindirect 中,所有线性回归都应基于 d 中新整理的数据。
然而,有一行

bpath <- lm(T2PSRB~T1Envied+T1Incivi, data=dat)

错误地引用了变量 dat,实际上不应在此函数中使用该变量。仅此一点就可以解释不一致的结果。

In your function getindirect all linear regressions should be based on the freshly shuffled data in d.
However there is the line

bpath <- lm(T2PSRB~T1Envied+T1Incivi, data=dat)

that makes the wrong reference to the variable dat which should really not be used within this function. That alone can explain incoherent results.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文