conflict_mahalanobis: Multivariate prior-data conflict via Mahalanobis distance

View source: R/conflict_mahalanobis.R

conflict_mahalanobisR Documentation

Multivariate prior-data conflict via Mahalanobis distance

Description

Tests joint prior-data conflict across two correlated endpoints using the Mahalanobis distance. Under the null (no conflict) the squared distance follows a chi-squared distribution with degrees of freedom equal to the number of endpoints.

Usage

conflict_mahalanobis(
  prior_means,
  prior_cov,
  obs_means,
  obs_cov,
  alpha = 0.05,
  labels = NULL
)

Arguments

prior_means

Numeric vector of length k. Prior means for each endpoint.

prior_cov

k x k numeric matrix. Prior covariance matrix.

obs_means

Numeric vector of length k. Observed data means.

obs_cov

k x k numeric matrix. Observed data covariance (Var/n for each diagonal; Cov/n for off-diagonal).

alpha

Numeric. Significance level for the chi-squared test. Default 0.05.

labels

Character vector of length k. Endpoint labels for output.

Details

Assumptions: This test assumes that the prior and observed summary statistics are approximately multivariate Normal. For proportion endpoints (e.g. response rates), transform to the log-odds scale before entering means and variances. For hazard ratios, use the log scale. Results may be unreliable if the Normal approximation is poor (e.g. for small samples with extreme proportions).

Current limitation: The function is designed for bivariate (k = 2) endpoints. While it will accept k > 2, the Shiny interface currently only exposes two endpoints. Support for k >= 3 is a planned extension.

Distribution family: The Mahalanobis approach is distribution-agnostic at the summary statistic level – it does not require a specific prior family (Beta, Normal, etc.). Any continuous prior whose mean and covariance can be extracted is supported.

Value

A named list of class bayprior_conflict_mv with components:

mahal_distance

Mahalanobis distance D.

mahal_D2

Squared distance D^2.

pvalue

Chi-squared p-value (df = p).

df

Degrees of freedom (number of endpoints, p).

conflict_flag

Logical. TRUE if pvalue < alpha.

marginal_z

Named numeric vector of per-parameter marginal z-scores (difference standardised by the marginal predictive SD).

interpretation

Character. Plain-language summary.

labels

Endpoint labels.

alpha

The significance level used.

References

Mahalanobis, P. C. (1936). On the generalised distance in statistics. Proceedings of the National Institute of Sciences of India, 2, 49–55.

Examples

pm   <- c(0.35, 0.60)
pcov <- matrix(c(0.010, 0.003, 0.003, 0.015), 2, 2)
om   <- c(0.55, 0.58)
ocov <- matrix(c(2e-4, 4e-5, 4e-5, 2e-4), 2, 2)
conflict_mahalanobis(pm, pcov, om, ocov, labels = c("Response rate", "OS rate"))


bayprior documentation built on Aug. 27, 2026, 1:09 a.m.