Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/r/74.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何使用rstanarm报告APA风格的贝叶斯线性(混合)模型?_R_Bayesian_Mixed Models_Stan_Rstan - Fatal编程技术网

如何使用rstanarm报告APA风格的贝叶斯线性(混合)模型?

如何使用rstanarm报告APA风格的贝叶斯线性(混合)模型?,r,bayesian,mixed-models,stan,rstan,R,Bayesian,Mixed Models,Stan,Rstan,我目前正在努力研究如何按照APA-6的建议报告rstanarm::stan_lmer()的输出 首先,我将在频率论方法中拟合一个混合模型,然后尝试使用贝叶斯框架进行同样的操作 以下是获取数据的可复制代码: library(tidyverse) library(neuropsychology) library(rstanarm) library(lmerTest) df <- neuropsychology::personality %>% select(Study_Level

我目前正在努力研究如何按照APA-6的建议报告
rstanarm::stan_lmer()
的输出

首先,我将在频率论方法中拟合一个混合模型,然后尝试使用贝叶斯框架进行同样的操作

以下是获取数据的可复制代码:

library(tidyverse)
library(neuropsychology)
library(rstanarm)
library(lmerTest)

df <- neuropsychology::personality %>% 
  select(Study_Level, Sex, Negative_Affect) %>% 
  mutate(Study_Level=as.factor(Study_Level),
         Negative_Affect=scale(Negative_Affect)) # I understood that scaling variables is important
为了报告这一点,我想说“我们拟合了一个线性混合模型,将负面影响作为结果变量,性别作为预测因素,研究水平作为随机效应输入。在该模型中,男性水平导致负面影响显著减少(β=-0.47,t(1321)=-7.06,p<0.001)

对吗

然后,让我们尝试使用
rstanarm
在贝叶斯框架内拟合模型:

fitB <- stan_lmer(Negative_Affect ~ Sex + (1|Study_Level),
                  data=df,
                  prior=normal(location=0, scale=1), 
                  prior_intercept=normal(location=0, scale=1),
                  prior_PD=F)
print(fitB, digits=2)
我认为than
median
是系数后验分布的中位数,
mad_sd
是标准偏差的等效值。这些参数接近于频繁者模型的贝塔和标准误差,这令人放心。但是,我不知道如何将输出形式化并用文字表达出来

此外,如果我对模型进行总结(
summary(fitB,probs=c(.025,.975),digits=2)
),我会得到后验分布的其他特征:

...
Estimates:
                                             mean     sd       2.5%     97.5% 
(Intercept)                                    0.02     0.11    -0.19     0.23
SexM                                          -0.47     0.07    -0.59    -0.34
...
像下面这样的东西好吗

“我们在贝叶斯框架内拟合了一个线性混合模型,将负面影响作为结果变量,性别作为预测因素,研究水平作为随机效应输入。系数和截距的先验值设置为正常值(平均值=0,sd=1)。在该模型中,与男性水平相关的系数后验分布特征表明负面影响减少(平均值=-0.47,标准差=0.11,95%可信区间[-0.59,-0.34])


感谢您的帮助。

以下是心理学杂志可能接受或不接受的个人观点

为了报告这一点,我想说“我们拟合了一个线性混合模型,将负面影响作为结果变量,性别作为预测因素,研究水平作为随机效应输入。在该模型中,男性水平导致负面影响显著减少(β=-0.47,t(1321)=-7.06,p<0.001)

对吗

从常客的角度来看,这被认为是正确的

从贝叶斯的角度来看,关键概念是(当然,取决于模型)

  • 真实效应小于后中值的概率为0.5,真实效应大于后中值的概率为0.5。常客倾向于将后中值视为数值最优值
  • posterior_interval
    函数在中位数周围产生可信区间,默认概率为0.9(尽管较小的数字产生更准确的边界估计)因此,你可以合理地说,真正的影响存在于这些界限之间的概率为0.9。常客倾向于将置信区间视为可信区间
  • as.data.frame
    函数将允许您访问原始绘图,因此
    mean(as.data.frame(fitB)$male>0)
    产生的概率是,在同一研究中,男性和女性的预期结果差异为正。常客倾向于将这些概率视为类似于p值
  • 对于贝叶斯方法,我会说

    我们使用马尔可夫链蒙特卡罗拟合了一个线性模型,结果变量为负面影响,预测因子为性别,截距允许根据研究水平而变化

    然后使用上述三个概念讨论估算

    fitB <- stan_lmer(Negative_Affect ~ Sex + (1|Study_Level),
                      data=df,
                      prior=normal(location=0, scale=1), 
                      prior_intercept=normal(location=0, scale=1),
                      prior_PD=F)
    print(fitB, digits=2)
    
    stan_lmer
     family:  gaussian [identity]
     formula: Negative_Affect ~ Sex + (1 | Study_Level)
    ------
    
    Estimates:
                Median MAD_SD
    (Intercept)  0.02   0.10 
    SexM        -0.47   0.07 
    sigma        0.97   0.02 
    
    Error terms:
     Groups      Name        Std.Dev.
     Study_Level (Intercept) 0.278   
     Residual                0.973   
    Num. levels: Study_Level 8 
    
    Sample avg. posterior predictive 
    distribution of y (X = xbar):
             Median MAD_SD
    mean_PPD 0.00   0.04  
    
    ------
    For info on the priors used see help('prior_summary.stanreg').
    
    ...
    Estimates:
                                                 mean     sd       2.5%     97.5% 
    (Intercept)                                    0.02     0.11    -0.19     0.23
    SexM                                          -0.47     0.07    -0.59    -0.34
    ...