Skip to content

Evaluating informative hypotheses with equality and inequality constraints: A tutorial using the Bayes factor via the encompassing prior approach [Supplemental Material]

License

Notifications You must be signed in to change notification settings

ClaudioZandonella/Attachment

Repository files navigation

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/.

Project Structure

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 used renv 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 files
    • Targets-workflow.R the workflow of the analysis
    • Targets-analysis.R script to run the analysis with targets
  • Data/ - includes the data used in the analyses
  • Documents/ - includes all the scripts and utility files for the creation of the outputs. In particular,
    • Bookdown/ - the Supplemental Material available online
    • Paper/ - the pre-print version of the article
  • R/ - includes all the .R scripts with the functions used in the analyses
    • Targets-utils.R functions used to load results of the analysis
  • docs/ - includes bookdown outputs used to build the GitHub Pages site
  • renv/ - utility folder used by renv

Reproducibility

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.

Run the Analysis

To reproduce the analysis:

  1. Download the repository on your local machine

    git clone https://github.com/ClaudioZandonella/Attachment
  2. 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.

  3. Run renv::restore() to install the project’s dependencies (have a coffee, it takes some time).

  4. Now the required packages are installed. Restart the R session (command/ctrl + shift + f10) so devtools::load_all() is automatically run to load all functions used in the analysis defined in the R/ folder and required packages are loaded (according to .Rprofile).

    Note that also source("Analysis/Utils_targets.R") is automatically run to load targets utilities functions (functions to load analysis results). You can also use the shortcut Ctrl/Cmd + Shift + L to run devtools::load_all()

  5. Open Analysis/Analysis_targets.R and run each line (one by one) to run the analysis using targets. First, the analysis plan is checked (available at Analysis/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 with tar_load_all().

  6. To compile the pre-print version of the article (possible after the analysis), open Documents/Paper/Paper.Rnw and compile the file using knitr and pdfLaTeX (see project options). Note that, as usual for LaTeX files, the first run will fail. Run again to obtain the actual output.

  7. To compile the Supplemental Material, run make_my_book(). The resulting output is saved in the docs/ folder.

Docker

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.

About

Evaluating informative hypotheses with equality and inequality constraints: A tutorial using the Bayes factor via the encompassing prior approach [Supplemental Material]

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published