Evaluating Informative Hypotheses with Equality and Inequality Constraints: A Tutorial Using the Bayes Factor via the Encompassing Prior Approach
In this repository we collect all the materials of the study “Evaluating informative hypotheses with equality and inequality constraints: A tutorial using the Bayes factor via the encompassing prior approach”. The paper aims to provide a clear and detailed description of the Bayes factor with the encompassing prior approach considering an applied example regarding attachment theory.
The pre-print version of the article is available at https://psyarxiv.com/6kc5u. The Supplemental Material with all the analyses is available at https://claudiozandonella.github.io/Attachment/.
The project structure is based on the traditional R-package project structure, but the repository is not meant to be installed as a package (see Section Reproducibility on how to run the analyses). R-package project structure, however, allows us to get advantage of some functionalities:
DESCRIPTION
file is used to track project metadata and manage project dependencies (note that we also usedrenv
for package dependencies, see Section below)devtools::load_all()
allows to easily load all functions defined to run the analysis (note that we followed the functional programming paradigm, see Section below)
Moreover, the analysis workflow is managed using targets
(see Section
below) and include other (non-standard) folders to organize the
scripts for the analysis and for the produced outputs (i.e., paper and
supplemental material).
The actual repository folder structure is:
Analysis/
that includes the filesTargets-workflow.R
the workflow of the analysisTargets-analysis.R
script to run the analysis withtargets
Data/
- includes the data used in the analysesDocuments/
- includes all the scripts and utility files for the creation of the outputs. In particular,Bookdown/
- the Supplemental Material available onlinePaper/
- the pre-print version of the article
R/
- includes all the.R
scripts with the functions used in the analysesTargets-utils.R
functions used to load results of the analysis
docs/
- includesbookdown
outputs used to build the GitHub Pages siterenv/
- utility folder used byrenv
To guarantee the reproducibility of the results, the R-packagetargets
is used to manage the analysis workflow and to enhance the readability
and transparency of the analysis. To know more about targets
consider
the official Git-hub page or the
user manual. Summarizing, using
targets
the user defines the plan of the analysis where each step in
the analysis is defined through functions. Functions can be
appropriately defined to obtain desired targets (i.e., R-output with
results of interests) and they are declared in the file
Targets-workflow.R
. Subsequently, targets
manages the whole analysis
recognizing the dependency structure of the different targets. When any
change is made to the code targets
evaluates the analysis and updates
the results. Following the functional programming paradigm (i.e.,
defining functions for each step of the analysis) allows us to avoid
“coping and paste” in the code, makes debugging easier, and
facilitates the reading of the code.
Moreover, the R-package renv
is used to manage the dependencies of the
R-packages used in the analysis. The renv
package allows to create an
isolated, portable, and reproducible environment where the analyses are
run. To know more about renv
consider the official
documentation.
However, renv
is limited as it can not handle different R versions.
To overcome this issue, we also provide a Dockerfile
to build a Docker
image with R version 4.1.0. To know more about Docker see official
documentation or rOpenSci Labs
tutorial.
To reproduce the analysis:
-
Download the repository on your local machine
git clone https://github.com/ClaudioZandonella/Attachment
-
Open the R project by double-clicking the file
Attachment.Rproj
you can find in the project main directory. A new R-studio session will open. -
Run
renv::restore()
to install the project’s dependencies (have a coffee, it takes some time). -
Now the required packages are installed. Restart the R session (
command
/ctrl
+shift
+f10
) sodevtools::load_all()
is automatically run to load all functions used in the analysis defined in theR/
folder and required packages are loaded (according to.Rprofile
).Note that also
source("Analysis/Utils_targets.R")
is automatically run to loadtargets
utilities functions (functions to load analysis results). You can also use the shortcutCtrl/Cmd + Shift + L
to rundevtools::load_all()
-
Open
Analysis/Analysis_targets.R
and run each line (one by one) to run the analysis usingtargets
. First, the analysis plan is checked (available atAnalysis/Targets-workflow.R
). Next, the analysis targets are computed. Finally, the analysis results are loaded and briefly presented.Note that you can access the analysis targets using the functions
targets::tar_load(<name_target>)
, or load all the results withtar_load_all()
. -
To compile the pre-print version of the article (possible after the analysis), open
Documents/Paper/Paper.Rnw
and compile the file usingknitr
andpdfLaTeX
(see project options). Note that, as usual for LaTeX files, the first run will fail. Run again to obtain the actual output. -
To compile the Supplemental Material, run
make_my_book()
. The resulting output is saved in thedocs/
folder.
To run the analysis in a Docker container, first, download the
repository on your local machine. Next, build the image according to the
Dockerfile
present in the project main directory, using
docker build -t attachment .
It is important to build the image before running the analysis
Next, you can run the container using
docker run --rm -p 8787:8787 -e PASSWORD="<your-PW>" attachment
Now, open the folder Attachment/
and run the analysis following the
instructions above from step 2.