使用“ proportionBF”进行一样本比例测试(两个以上级别)

时间:2019-06-23 11:15:52

标签: r statistics bayesian

我想为零假设的单样本比例测试计算贝叶斯因子-

  

名义变量水平的比例不是   与理论比例不同

当存在两个比例且零假设是两个级别的可能性相同时,我知道如何使用proportionBF包中的BayesFactor来做到这一点(p = 0.5)。这等效于stats::binom.test

# frequentist test (p-value > 0.05)
broom::tidy(stats::binom.test(x = 21, n = 44, p = 0.5))
#> # A tibble: 1 x 8
#>   estimate statistic p.value parameter conf.low conf.high method
#>      <dbl>     <dbl>   <dbl>     <dbl>    <dbl>     <dbl> <chr> 
#> 1    0.477        21   0.880        44    0.325     0.633 Exact~
#> # ... with 1 more variable: alternative <chr>

# quantifying evidence in favor of null hypothesis
library(BayesFactor)
1/ proportionBF(y = 21, N = 44, p = 0.5, rscale = 0.707)

#> Bayes factor analysis
#> --------------
#> [1] Null, p=0.5 : 3.724132 ±0.02%
#> 
#> Against denominator:
#>   Alternative, p0 = 0.5, r = 0.707, p =/= p0 
#> ---
#> Bayes factor type: BFproportion, logistic

但是当存在两个以上的比例(相当于stats::chisq.test(拟合优度检验))时,我不知道如何进行此分析。

# frequentist test (p-value > 0.05)
table(mtcars$cyl)
#> 
#>  4  6  8 
#> 11  7 14
broom::tidy(stats::chisq.test(x = table(mtcars$cyl)))
#> # A tibble: 1 x 4
#>   statistic p.value parameter method                                  
#>       <dbl>   <dbl>     <dbl> <chr>                                   
#> 1      2.31   0.315         2 Chi-squared test for given probabilities

如何使用BayesFactor软件包为此测试计算贝叶斯因子?

(P.S。如果不可能,我也想知道其他可以做到这一点的软件包。)

1 个答案:

答案 0 :(得分:0)

else的作者在这里回答了这个问题: https://gist.github.com/richarddmorey/a4cd3a2051f373db917550d67131dba4