<img src="man/figures/logo_BFpack.png" width = 850 />
#
[![CRAN
Version](http://www.r-pkg.org/badges/version/BFpack)](https://cran.r-project.org/package=BFpack)
[![Downloads](https://cranlogs.r-pkg.org/badges/BFpack)](https://cran.r-project.org/package=BFpack)
[![R-CMD-check](https://github.com/jomulder/BFpack/workflows/R-CMD-check/badge.svg)](https://github.com/jomulder/BFpack/actions)
<!-- Insert codecov badge here -->
[![Contributor
Covenant](https://img.shields.io/badge/Contributor%20Covenant-v2.0%20adopted-ff69b4.svg)](https://www.contributor-covenant.org/version/2/0/code_of_conduct.html)
The `R` package **BFpack** contains a set of functions for exploratory
hypothesis testing (e.g., equal vs negative vs postive) and confirmatory
hypothesis testing (with equality and/or order constraints) using Bayes
factors and posterior probabilities under commonly used statistical
models, including (but not limited to) Bayesian t testing, (M)AN(C)OVA,
multivariate/univariate linear regression, correlation analysis,
multilevel analysis, or generalized linear models (e.g., logistic
regression). The main function `BF` needs a fitted model (e.g., an
object of class `lm` for a linear regression model) and (optionally) the
argument `hypothesis`, a string which specifies a set of equality/order
constraints on the parameters. By applying the function
`get_estimates`on a fitted model, the names of the parameters are
returned on which constrained hypotheses can be formulated. Bayes
factors and posterior probabilities are computed for the hypotheses of
interest.
## Installation
Install the latest release version of `BFpack` from CRAN:
``` r
install.packages("BFpack")
```
The current developmental version can be installed with
``` r
if (!requireNamespace("remotes")) {
install.packages("remotes")
}
remotes::install_github("jomulder/BFpack")
```
## Example analyses
Below several example analyses are provided using **BFpack**.
### Bayesian t testing
First a classical one sample t test is executed on the test value
\(&mu = 5\) on the `therapeutic` data (part of `BFpack`). Here a right one-tailed classical test is executed:
``` r
ttest1 <- bain::t_test(therapeutic, alternative = "greater", mu = 5)
```
The `t_test` function is part of the **bain** package. The function is
equivalent to the standard `t.test` function with the addition that the
returned object contains additional output than the standard `t.test`
function.
To perform a Bayesian t test plug the fitted object into the `BF`
function.
``` r
library(BFpack)
BF1 <- BF(ttest1)
```
This executes an exploratoory ('exhaustive') test around the null value: `H1: mu = 5`
versus `H2: mu < 5` versus `H3: mu > 5` assuming equal prior
probabilities for `H1`, `H2`, and `H3` of 1/3. The output presents the
posterior probabilities for the three hypotheses.
The same test would be executed when the same hypotheses are explicitly
specified using the `hypothesis` argument.
``` r
hypothesis <- "mu = 5; mu < 5; mu > 5"
BF(ttest1, hypothesis = hypothesis)
```
When testing hypotheses via the `hypothesis` argument, the output also
presents an `Evidence matrix` containing the Bayes factors between the
hypotheses.
The argument `prior.hyp` can be used to specify different prior probabilities
for the hypotheses. For example, when the left one-tailed hypothesis is not possible
based on prior considerations (e.g., see [preprint](https://arxiv.org/abs/1911.07728)) while the precise (null) hypothesis and the right
one-tailed hypothesis are equally likely, the argument `prior.hyp` should be a vector
specifying the prior probabilities of the respective hypotheses
``` r
BF(ttest1, hypothesis = "mu = 5; mu < 5; mu > 5", prior.hyp = c(.5,0,.5))
```
### Analysis of variance
First an analysis of variance (ANOVA) model is fitted using the `aov`
fuction in `R`.
``` r
aov1 <- aov(price ~ anchor * motivation, data = tvprices)
```
Next a Bayesian test can be performed on the fitted object.
``` r
BF(aov1)
```
By default posterior probabilities are computed of whether main effects
and interaction effects are present. Alternative constrained hypotheses
can be tested on the model parameters `get_estimates(aov1)`.
### Logistic regression
An example hypothesis test is consdered under a logistic regression
model. First a logistic regression model is fitted using the `glm`
function
``` r
fit_glm <- glm(sent ~ ztrust + zfWHR + zAfro + glasses + attract + maturity +
tattoos, family = binomial(), data = wilson)
```
The names of the regression coefficients on which constrained hypotheses
can be formualted can be extracted using the `get_estimates` function.
``` r
get_estimates(fit_glm)
```
Two different hypotheses are formulated with competing equality and/or
order constraints on the parameters of interest. These hypotheses are
motivated in Mulder et al. (2019)
``` r
BF_glm <- BF(fit_glm, hypothesis = "ztrust > (zfWHR, zAfro) > 0;
ztrust > zfWHR = zAfro = 0")
summary(BF_glm)
```
By calling the `summary` function on the output object of class `BF`,
the results of the exploratory tests are presented of whether each
separate parameter is zero, negative, or positive, and the results of
the confirmatory test of the hypotheses under the `hypothesis` argument
are presented. When the hypotheses do not cover the complete parameter
space, by default the complement hypothesis is added which covers the
remaining parameter space that is not covered by the constraints under
the hypotheses of interest. In the above example, the complement
hypothesis covers the parameter space where neither `"ztrust > (zfWHR,
zAfro) > 0"` holds, nor where `"ztrust > zfWHR = zAfro = 0"` holds.
### Correlation analysis
By default `BF` performs exhaustice tests of whether the separate
correlations are zero, negative, or positive. The name of the
correlations is constructed using the names of the variables separated
by `_with_`.
``` r
set.seed(123)
cor1 <- cor_test(memory[,1:3])
BF1 <- BF(cor1)
print(BF1)
```
Constraints can also be tested between correlations, e.g., whether all
correlations are equal and positive versus an unconstrained complement.
``` r
BF2 <- BF(cor1, hypothesis = "Del_with_Im = Wmn_with_Im = Wmn_with_Del > 0")
print(BF2)
```
### Univariate/Multivariate multiple regression
For a univariate regression model, by default an exhaustive test is
executed of whether an effect is zero, negative, or postive.
``` r
lm1 <- lm(Superficial ~ Face + Vehicle, data = fmri)
BF1 <- BF(lm1)
print(BF1)
```
Hypotheses can be tested with equality and/or order constraints on the
effects of interest. If prefered the complement hypothesis can be
omitted using the `complement` argument
``` r
BF2 <- BF(lm1, hypothesis = "Vehicle > 0 & Face < 0; Vehicle = Face = 0",
complement = FALSE)
print(BF2)
```
In a multivariate regression model hypotheses can be tested on the
effects on the same dependent variable, and on effects across different
dependent variables. The name of an effect is constructed as the name of
the predictor variable and the dependent variable separated by `_on_`.
Testing hypotheses with both constraints within a dependent variable and
across dependent variables makes use of a Monte Carlo estimate which may
take a few seconds.
``` r
lm2 <- lm(cbind(Superficial, Middle, Deep) ~ Face + Vehicle,
data = fmri)
constraint2 <- "Face_on_Deep = Face_on_Superficial = Face_on_Middle < 0 <
Vehicle_on_Deep = Vehicle_on_Superficial = Vehicle_on_Middle;
Face_on_Deep < Face_on_Superficial = Face_on_Middle < 0 < Vehicle_on_Deep =
Vehicle_on_Superficial = Vehicle_on_Middle"
set.seed(123)
BF3 <- BF(lm2, hypothesis = constraint2)
summary(BF3)
```
### Running `BF` on a named vector
The input for the `BF` function can also be a named vector containing
the estimates of the parameters of interest. In this case the error
covariance matrix of the estimates is also needed via the `Sigma`
argument, as
没有合适的资源?快使用搜索试试~ 我知道了~
BFpack可用于使用贝叶斯因子检验统计假设,贝叶.zip
共113个文件
r:64个
rd:16个
csv:12个
1.该资源内容由用户上传,如若侵权请联系客服进行举报
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
版权申诉
0 下载量 50 浏览量
2023-04-15
09:31:55
上传
评论
收藏 473KB ZIP 举报
温馨提示
BFpack可用于使用贝叶斯因子检验统计假设,贝叶.zip
资源推荐
资源详情
资源评论
收起资源包目录
BFpack可用于使用贝叶斯因子检验统计假设,贝叶.zip (113个子文件)
BFpack_init.c 1KB
CITATION 2KB
timssICC.csv 987KB
wilson.csv 65KB
sivan.csv 59KB
relevents.csv 3KB
tvprices.csv 2KB
same_location.csv 1KB
same_culture.csv 1KB
attention.csv 1KB
memory.csv 1KB
fmri.csv 800B
actors.csv 185B
therapeutic.csv 66B
DESCRIPTION 5KB
bct_continuous_final.f90 34KB
bct_prior.f90 10KB
.gitignore 120B
.gitignore 7B
vignette_BFpack.html 49KB
README.md 10KB
cran-comments.md 1KB
NEWS.md 484B
NAMESPACE 2KB
logo_BFpack.png 105KB
logo_BFpack_small.png 63KB
BF.lm.R 50KB
BFicc.R 20KB
BFmeta.R 17KB
BF_cortest.R 14KB
BFvar.R 14KB
BFttest.R 13KB
BF.ergm.R 11KB
BF_methods.R 11KB
jointuniform_measures.R 10KB
BF.default.R 8KB
BFhetcor.R 4KB
get_estimates_unique_to_BFpack.R 4KB
timssICC.r 3KB
BFpack-package.R 3KB
test_ttest.R 2KB
test_BFregression.R 2KB
wilson.r 2KB
sivan.R 2KB
test_bartlett.R 2KB
BF.summary.R 2KB
test_hetcor.R 2KB
test_application4_BF.mlm_regression.R 2KB
test_BFmlm.R 2KB
BF.print.R 2KB
cor_test.print.R 2KB
test_application7_BF.lmerMod.R 1KB
test_BFcortest.R 1KB
test_paper_fmri.R 1KB
memory.R 1KB
fmri.R 1KB
test_application5_BF.glm_BF_Gaussian.R 1KB
test_BFcoxph2.R 1KB
test_application3_BF.BF_bartlett.R 1KB
attention.R 1KB
test_application1_BF.bain_ttest.R 1012B
therapeutic.R 934B
test_BFmeta.R 927B
tvprices.R 871B
BF.coeftest.R 864B
relevents.R 807B
test_BFergm.R 804B
import_parser.R 785B
same_location.R 770B
same_culture.R 770B
actors.R 769B
test_variances.R 639B
BF.survreg.R 620B
BF.polr.R 608B
BF.zeroinfl.R 605B
BF.coxph.R 601B
test_application6_BF.mlm_correlations.R 558B
BF.glm.R 544B
test_BFglm.R 500B
test_BFcoxph.R 500B
test_BFcoeftest.R 434B
test_application2_BF.lm.R 420B
test_BFpolr.R 375B
test_BFsurvreg.R 332B
test_metafor.R 326B
test_BFzeroinfl.R 265B
helper_functions.R 206B
test_get_estimates_matrix.R 187B
vignette_BFpack.R 117B
testthat.R 73B
.Rbuildignore 144B
BF.Rd 11KB
timssICC.Rd 3KB
bartlett_test.Rd 3KB
BFpack-package.Rd 3KB
wilson.Rd 2KB
sivan.Rd 2KB
cor_test.Rd 2KB
memory.Rd 1KB
fmri.Rd 1KB
共 113 条
- 1
- 2
资源评论
快撑死的鱼
- 粉丝: 1w+
- 资源: 9154
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
最新资源
- [大模型部署]在C# Winform中使用文心一言ERNIE-3.5 4K 聊天模型
- python毕业设计-基于Django+OpenCV的二维码生成与识别系统设计与实现.zip
- python毕业设计-基于Django+OpenCV的二维码生成与识别系统设计与实现+使用说明.zip
- 基于STM32单片机空气监测系统设计源码+详细文档+配套全部资料(毕业设计).zip
- rdf0412-kcu116-pcie-c-2019-1.zip(XILINX KCU116 源码)
- 基于C#语言的winform界面火车票订票系统(源码+实验报告)
- 【华为OD部分真题及讲解】华为OD部分真题及讲解
- 基于Python+Django的京东商品比价系统源码+全部资料(毕业设计).zip
- G460 G560 Z460 Z560的最新BIOS 2.18版(无白名单)
- MetaJUI v0.4
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功