Skip to main content

hypothesize: A Consistent API for Statistical Tests in R

R’s hypothesis testing functions are inconsistent—t.test() returns different structures than chisq.test(), making generic workflows painful. hypothesize provides a unified API so any test returns the same interface: p-value, test statistic, degrees of freedom.

The Problem

Different R tests return incompatible objects:

t.test(x, y)$p.value        # Works
chisq.test(x, y)$p.value    # Also works
my_custom_test(x, y)$???    # Who knows?

You can’t write generic code that works across tests.

The Solution

hypothesize defines a consistent interface:

test <- lrt(model_null, model_alt)  # Likelihood ratio test
pval(test)          # Extract p-value
test_stat(test)     # Extract test statistic
dof(test)           # Extract degrees of freedom
is_significant_at(test, 0.05)  # Boolean check

All tests—built-in or custom—implement the same generic functions.

Built on likelihood.model

The package integrates with likelihood.model, making it trivial to perform likelihood ratio tests on any model:

lrt(null_model, alternative_model)  # Automatic LRT

Also includes Wald test, Z-test, and extensibility for custom tests.

Why This Matters

Reusability: Write test-agnostic pipelines that work with any hypothesis test

Composability: Tests are objects you manipulate, not magic side effects

Extensibility: Wrap your own tests in the same interface

This is the R equivalent of generic programming—a consistent abstraction over heterogeneous implementations.

R package • Works with likelihood.modelDocumentationGitHub

Discussion