Code from: Calibrating P-values in ecology: A practical framework for integrating prior plausibility into statistical inference
Data files
Apr 08, 2026 version files 5.22 KB
-
function_code.R
2.96 KB
-
README.md
2.26 KB
Abstract
This repository contains R code implementing the p‑value calibration method presented in the associated article. The core function, min_posterior, takes a p‑value and the prior probability of the alternative hypothesis and returns the minimum posterior probability of the null hypothesis, using a Bayes factor calibration based on Sellke et al. (2001). The code includes input checks, example calls for different prior plausibilities, and a short script to visualize how the minimum posterior probability of the null changes as a function of the p‑value for a given prior. This resource is intended as a practical implementation of the theoretical framework in the paper, allowing ecologists to translate conventional p‑values into calibrated measures of evidence that explicitly incorporate prior plausibility.
Overview
This repository contains R code implementing the p-value calibration method introduced in the article: Guariento, R. D., Gripp, A., Caliman, A. (2026). Calibrating P-values in ecology: a practical framework for integrating prior plausibility into statistical inference. Oikos.
The main purpose of the code is to provide a practical tool for converting conventional p-values into minimum posterior probabilities of the null hypothesis, explicitly incorporating the prior plausibility of the alternative hypothesis.
Contents
function_code.R: R script defining the functionmin_posteriorand example usage.
Description of the function
min_posterior(p, prior_alt) computes the minimum posterior probability of the null hypothesis $$H_0$$ given:
p: a p-value from a statistical test (0 < p < 1).prior_alt: the prior probability of the alternative hypothesis $$H$$ (0 < prior_alt < 1).
Internally, the function:
- Computes the prior probability of the null as $$P(H_0) = 1 - \text{prior_alt}$$.
- Uses a Bayes factor calibration (following Sellke et al. 2001) to obtain a minimum Bayes factor in favor of the null.
- Converts prior odds into posterior odds and then into the minimum posterior probability $$P(H_0 \mid \text{data})$$.
Intended use
The code is intended for:
- Researchers and students who wish to:
- Calibrate p-values into minimum posterior probabilities of the null hypothesis.
- Explore how different choices of prior plausibility affect inference.
- Teaching and demonstration of the connection between p-values, Bayes factors, and posterior probabilities.
Example usage
In R:
r
source("function_code.R")
# Example: prior probability of the alternative = 0.5, p-value = 0.04
min_posterior(p = 0.04, prior_alt = 0.5)
# Example: long-shot hypothesis (prior_alt = 0.1), p-value = 0.01
min_posterior(p = 0.01, prior_alt = 0.1)
Data statement
No empirical data are included in this repository. The resource consists solely of executable R code for a theoretical calibration model. Users must supply their own p-values and prior probabilities.
