-
Notifications
You must be signed in to change notification settings - Fork 0
/
README.Rmd
89 lines (61 loc) · 6.7 KB
/
README.Rmd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
---
output: github_document
---
<!-- README.md is generated from README.Rmd. Please edit that file -->
```{r, include = FALSE}
knitr::opts_chunk$set(
collapse = TRUE,
comment = "#>",
out.width = "100%"
)
```
# 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](#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 {#reproducibility}
To guarantee the reproducibility of the results, the R-package`targets` 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](https://github.com/ropensci/targets) or the [user manual](https://books.ropensci.org/targets/). 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](https://rstudio.github.io/renv/articles/renv.html). 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](https://www.docker.com/) or
[rOpenSci Labs tutorial](https://jsta.github.io/r-docker-tutorial/).
### Run the Analysis
To reproduce the analysis:
1. Download the repository on your local machine
```{bash, eval = FALSE}
git clone https://github.com/ClaudioZandonella/Attachment
```
1. 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.
1. Run `renv::restore()` to install the project's dependencies (have a coffee, it takes some time).
1. 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()`
1. 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()`.
1. 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](https://support.rstudio.com/hc/en-us/articles/200532247-Weaving-Rnw-Files-in-the-RStudio-IDE)). Note that, as usual for LaTeX files, the first run will fail. Run again to obtain the actual output.
1. 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
```{bash, eval = FALSE}
docker build -t attachment .
```
> It is important to build the image before running the analysis
Next, you can run the container using
```{bash, eval = FALSE}
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.