Skip to content

Commit 3ba3bdf

Browse files
committed
final polish
1 parent 0c9eebc commit 3ba3bdf

File tree

8 files changed

+34
-522
lines changed

8 files changed

+34
-522
lines changed

README.md

Lines changed: 34 additions & 136 deletions
Original file line numberDiff line numberDiff line change
@@ -1,136 +1,50 @@
11
# Hierarchical-Interoception
22

3-
This repository contains the complete analysis pipeline for hierarchical psychometric function modeling applied to intero & exteroceptive tasks.
4-
The project implements Bayesian hierarchical models for analyzing Heart Rate Discrimination Task (HRDT) and Respiratory Resistance Sensitivity Task (RRST) data,
5-
with comprehensive power analysis and interactive visualization tools.
3+
This repository is the companion of our pre-print "Hierarchical Bayesian Modelling of Interoceptive Psychophysics" (https://doi.org/10.1101/2025.08.27.672360).
4+
In this pre-print, we introduce hierarchical psychometric function models for the analysis of interoceptive psychophysics data, more specifically for the Heart Rate Discrimination Task (HRDT) and Respiratory Resistance Sensitivity Task (RRST).
5+
We validate these models (parameter and model recovery analysis), fit them to a large dataset to derive normative priors for simulations and future studies, and run a power analysis examining how different design and analysis choices influence our ability to reliably detect various effect sizes.
6+
All the data and code used to prepare this manuscript is available on this repository.
67

7-
## Table of Contents
8+
In addition to the pre-print, we also provide ressources to facilitate the adoption of hierarchical modelling by researchers who work with HRDT or RRST data.
9+
One of these is a R markdown file demonstrating how to implement and interpet these models, using the well documented BRMS library.
10+
Another is a shiny app which researchers can use to explore the results of our power analysis, e.g. to justify sample size of future studies.
811

9-
1. [Technical Details of the Hierarchical Model](#technical-details-of-the-hierarchical-model)
12+
## Table of Contents
13+
1. [Structure of the repository](#structure-of-the-repository)
1014
2. [Using the BRMS Demo](#using-the-brms-demo)
1115
3. [Shiny App Deployment and Usage](#shiny-app-deployment-and-usage)
16+
3. [Dependencies](#dependencies)
17+
3. [Citation](#citation)
18+
3. [Contact](#contact)
1219

13-
## Technical Details of the Hierarchical Model
14-
15-
### Model Formulation
16-
17-
The hierarchical model implements a psychometric function with three key parameters:
18-
19-
1. **Threshold (α)**: The stimulus intensity at which the probability of correct response is 0.5
20-
2. **Slope (β)**: The steepness of the psychometric function, indicating sensitivity
21-
3. **Lapse rate (λ)**: The upper (1-$\lambda$) and lower asymptotes.
22-
23-
### Mathematical Framework
24-
25-
The psychometric function is defined as:
26-
27-
$$P(response) = \lambda + (1 - 2\lambda) \cdot \left(0.5 + 0.5 \cdot \text{erf}\left(\frac{\beta \cdot (x - \alpha)}{\sqrt{2}}\right)\right)$$
28-
29-
Where:
30-
- $x$ is the stimulus intensity
31-
- $\alpha$ is the threshold
32-
- $\beta$ is the slope (constrained to be positive)
33-
- $\lambda$ is the lapse rate (constrained to [0, 0.5])
34-
- $\text{erf}$ is the error function
35-
36-
### Hierarchical Structure
37-
38-
The model implements a three-level hierarchy:
39-
40-
1. **Group-level parameters**: Population means and variances for each parameter
41-
2. **Subject-level parameters**: Individual deviations from group means
42-
3. **Trial-level observations**: Binary responses to stimulus presentations
43-
44-
### Stan Implementation
45-
46-
The model is implemented in Stan with the following key components:
20+
## Structure of the repository
4721

4822
```
49-
// Group-level parameters
50-
vector[N] gm; // Group means for all parameters
51-
vector<lower = 0>[N] tau_u; // Between-participant varability
52-
matrix[N, S] z_expo; // Participant deviations
53-
54-
// Individual psychometric parameters
55-
vector[S] alpha_int = (gm[1] + (tau_u[1] * z_expo[1,]))';
56-
vector[S] beta_int = (gm[2] + (tau_u[2] * z_expo[2,]))';
57-
vector[S] lapse = (inv_logit(gm[3] + (tau_u[3] * z_expo[3,])) / 2)';
58-
```
59-
60-
### Prior Specifications
61-
62-
We recommend using our empirically informed priors derived from the ~500 subject study these can be added in the stancode as follows::
63-
```
64-
gm[1] ~ normal(-8.67, 5.2); //group mean threshold
65-
gm[2] ~ normal(-2.3,0.2); //group mean slope (log)
66-
gm[3] ~ normal(-4.32, 0.29); //group mean lapse rate (logit)
67-
23+
Hierarchical-Interoception/
24+
├── analysis/ # Model comparison for the HRDT
25+
├── app & demo/ # BRMS demo and Shiny app
26+
├── data/ # Raw data files
27+
├── figures/ # Generated figures
28+
├── figures_scripts/ # Figure generation scripts
29+
├── results/ # Analysis results and power analysis
30+
├── scripts/ # Utility functions and main scripts
31+
├── simulated_data/ # Simulated datasets (model recovery and power analysis)
32+
└── stanmodels/ # Stan model definitions (VMP-data refit, poweranalysis and model recovery)
6833
```
6934

70-
7135
## Using the BRMS Demo
7236

73-
The `apps & wrappers/BRMS demo.Rmd` provides a complete workflow for data simulation and analysis:
37+
The `app & demo/BRMS demo.Rmd` provides a complete workflow for data simulation and analysis for both the HRDT and RRST, including:
7438

75-
1. **Data Simulation**: Generate synthetic data with known parameters
76-
2. **Model Specification**: Define the hierarchical psychometric function
77-
3. **Model Fitting**: Fit using BRMS with Stan backend
78-
4. **Model Diagnostics**: Check convergence and sampling quality
39+
1. **Data simulation**: Generate synthetic data with known parameters
40+
2. **Model specification**: Define the hierarchical psychometric function
41+
3. **Model fitting**: Fit using BRMS with Stan backend
42+
4. **Model diagnostics**: Check convergence and sampling quality
7943
5. **Model interpretation**: Extract posterior distributions and credible intervals
44+
5. **Results reporting**: Sample text showing how one could report the results in a scientific paper
45+
5. **Results visualization**: Generates a series of plots that can be added to a scientific manuscript to illustrate the results
8046

81-
Below we show the general workflow of the demo. We first simulate data from the following parameters
82-
83-
```r
84-
# Design parameters
85-
n_subj_HRDT <- 50
86-
n_rep_HRDT <- 30
87-
x_seq_HRDT <- rep(seq(-40, 40, 5), n_rep_HRDT)
88-
89-
# Group-level parameters
90-
mu_alpha_HRDT <- -8.6
91-
sd_alpha_HRDT <- 11.6
92-
mu_beta_HRDT <- -2.3
93-
sd_beta_HRDT <- 0.3
94-
mu_lambda_HRDT <- -4.2
95-
sd_lambda_HRDT <- 2
96-
```
97-
98-
Then specifying the model in brms:
99-
100-
101-
```r
102-
bff_HRDT = bf(
103-
y|trials(n) ~ (inv_logit(lambda) / 2 +
104-
(1-inv_logit(lambda)) *
105-
(0.5 + 0.5 * erf(exp(beta)*(x-alpha)/(sqrt(2))))),
106-
alpha ~ condition + (condition | subj),
107-
beta ~ condition + (condition | subj),
108-
lambda ~ (1 | subj),
109-
nl = TRUE,
110-
family = binomial(link = "identity")
111-
)
112-
```
113-
114-
Running this model on the simulated data:
115-
116-
```r
117-
fit_eip_HRDT <- brm(
118-
bff_HRDT,
119-
data = sim_data_HRDT,
120-
chains = 4,
121-
cores = 4,
122-
seed = seed,
123-
backend = "cmdstan",
124-
warmup = 2000,
125-
iter = 4000,
126-
control = list(
127-
adapt_delta = 0.9,
128-
max_treedepth = 10
129-
),
130-
prior = empirically_informed_priors_HRDT
131-
)
132-
```
133-
47+
The code can easily be recycled to analyze your own data.
13448

13549
## Shiny App Deployment and Usage
13650

@@ -156,9 +70,7 @@ Either enter this in the R-console
15670
```r
15771
shiny::runApp("apps & wrappers/shiny app.R")
15872
```
159-
or go to the "apps & wrappers" directory and run the `shiny app.R` script
160-
161-
73+
or go to the "app & demo" directory and run the `shiny app.R` script
16274

16375
### App Usage
16476

@@ -183,21 +95,6 @@ or go to the "apps & wrappers" directory and run the `shiny app.R` script
18395
2. **Submit Query**: Get precise power estimates for above
18496
3. **View Results**: See power for hierarchical, simple t-test, and uncertainty propagation methods
18597

186-
## File Structure
187-
188-
```
189-
Hierarchical-Interoception/
190-
├── Analysis/ # Model comparison for the HRDT
191-
├── apps & wrappers/ # BRMS demo and Shiny app
192-
├── Data/ # Raw data files
193-
├── figures/ # Generated figures
194-
├── figures_scripts/ # Figure generation scripts
195-
├── results/ # Analysis results and power analysis
196-
├── scripts/ # Utility functions and main scripts
197-
├── simulated_data/ # Simulated datasets (model recovery and power analysis)
198-
└── stanmodels/ # Stan model definitions (VMP-data refit, poweranalysis and model recovery)
199-
```
200-
20198
## Dependencies
20299

203100
### Stan Installation
@@ -215,7 +112,8 @@ cmdstanr::install_cmdstan()
215112
If you use this code in your research, please cite:
216113

217114
```
218-
Courtin, A.S., & Fischer Ehmsen, J. (2025). Hierarchical Bayesian modeling of interoceptive psychometric functions. https://doi.org/10.1101/2025.08.27.672360
115+
Arthur S. Courtin, Jesper Fischer Ehmsen, Leah Banellis, Francesca Fardo, Micah Allen
116+
bioRxiv 2025.08.27.672360; doi: https://doi.org/10.1101/2025.08.27.672360
219117
```
220118

221119
## Contact
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.

0 commit comments

Comments
 (0)