hypothesis: Test hypotheses and compute evidence ratios from posterior...

View source: R/hypothesis.R

hypothesisR Documentation

Test hypotheses and compute evidence ratios from posterior draws

Description

Evaluates one or more hypothesis expressions against the posterior draws of a smoothbp_fit object, returning posterior probabilities and evidence ratios.

Usage

hypothesis(object, hypotheses, ci = 0.95, ...)

Arguments

object

A smoothbp_fit object.

hypotheses

A character vector of hypothesis strings.

ci

Width of the credible interval (0 < ci < 1). Default 0.95.

...

Unused.

Value

An object of class c("smoothbp_hypothesis", "data.frame") with one row per hypothesis and columns:

Hypothesis

The original hypothesis string.

Estimate

Posterior mean of the contrast.

Est.Error

Posterior SD of the contrast.

CI.lower, CI.upper

Credible interval bounds.

P(H)

Posterior probability of the hypothesis.

Evid.Ratio

Evidence ratio P(H)/(1-P(H)).

Star

Informal star coding based on the evidence ratio.

Hypothesis syntax

Write hypotheses as character strings using exact parameter names as they appear in fit$param_names (e.g. "b2_(Intercept)", "omega_(Intercept)"). No backtick-quoting is needed; the function handles special characters internally.

Two forms are accepted:

Directional

An expression containing >, <, >=, or <=. The hypothesis is evaluated as a contrast: the left-hand side minus the right-hand side (direction-adjusted), and P(H \mid \text{data}) is the proportion of posterior draws satisfying the condition. Examples: "b2_(Intercept) > 0", "omega_(Intercept) < 4", "b2_(Intercept) - b1_(Intercept) > 0".

Contrast

A numeric expression without a comparison operator. The function summarises the posterior distribution of the derived quantity and reports P(\text{expression} > 0) as the directional probability. Example: "b2_(Intercept) - b1_(Intercept)".

Point-null hypotheses (==) are not supported because they require the Savage-Dickey density ratio; use bayestestR::rope() for interval-based equivalence testing instead.

Evidence ratio interpretation

ER = \frac{P(H \mid \text{data})}{1 - P(H \mid \text{data})}

An ER of 19 corresponds to P(H) = 0.95; ER = 1 means the posterior is equally split. Star codes: *** ER > 99, ** ER > 19, * ER > 3.

Examples

## Not run: 
# Is the change in slope positive?
hypothesis(fit, "b2_(Intercept) > 0")

# Does the change-point fall before time 4?
hypothesis(fit, "omega_(Intercept) < 4")

# Multiple hypotheses at once
hypothesis(fit, c(
  "b2_(Intercept) > 0",
  "omega_(Intercept) < 4",
  "b2_(Intercept) - b1_(Intercept) > 0"
))

# Posterior summary of a contrast (no comparison operator)
hypothesis(fit, "b2_(Intercept) - b1_(Intercept)")

## End(Not run)


smoothbp documentation built on June 14, 2026, 9:06 a.m.