Computes the squared Mahalanobis distance \(D^2\) together with an exact confidence interval for the population squared distance \(\Delta^2\), obtained by inverting Hotelling's \(T^2\) statistic through its (noncentral) F-distribution as in Reiser (2001). Both the one-sample setting (mean vector against a hypothesized population mean) and the two-sample setting (between-groups distance from discriminant analysis or multivariate group comparison) are supported, and either raw data or a pre-computed \(D^2\) with sample sizes can be supplied.
ci_mahalanobis(
D2 = NULL,
group_1 = NULL,
group_2 = NULL,
mu_0 = NULL,
n_1 = NULL,
n_2 = NULL,
p = NULL,
conf_level = 0.95,
alpha_lower = NULL,
alpha_upper = NULL,
...
)A one-row data.frame with columns sample_type
("one-sample" or "two-sample"), D2 (point estimate of
the squared distance), lower_limit and upper_limit (the
confidence limits on the population squared distance \(\Delta^2\)),
F_value, df_1, df_2, n_1, n_2
(NA in one-sample mode), and p.
Optional pre-computed squared Mahalanobis distance. Ignored if
group_1 is supplied.
Optional numeric matrix or data frame for the first sample (\(n_1 \times p\)). Rows are observations and columns are variables.
Optional numeric matrix or data frame for the second sample
(\(n_2 \times p\)). When NULL, the function operates in
one-sample mode against mu_0.
Optional hypothesized population mean for the one-sample case (length-\(p\) numeric vector). Defaults to a vector of zeros.
Sample size for group 1 (required when supplying D2
directly).
Sample size for group 2 (required for two-sample mode when
supplying D2 directly; leave NULL for one-sample mode).
Dimensionality (number of variables) when supplying D2
directly.
Confidence coverage for a symmetric interval (default
0.95). Set it to NULL to specify the tails directly
through alpha_lower and alpha_upper.
Optional Type I error rates for the lower and
upper tail. To use them, set conf_level = NULL and supply both
(an asymmetric or one-sided interval with coverage
1 - alpha_lower - alpha_upper); supplying either alongside a
non-NULL conf_level is an error, as in
ci_nc_F, to which they are passed.
Additional arguments passed to ci_nc_F
(for example tol).
Ken Kelley [email protected]
Definition. For a \(p\)-vector \(\mathbf{x}\) drawn from a multivariate normal with mean \(\boldsymbol{\mu}\) and covariance \(\boldsymbol{\Sigma}\), Mahalanobis's (1936) squared distance from a reference vector \(\boldsymbol{\mu}_0\) is $$\Delta^2 = (\boldsymbol{\mu} - \boldsymbol{\mu}_0)^\top \boldsymbol{\Sigma}^{-1} (\boldsymbol{\mu} - \boldsymbol{\mu}_0).$$ In the two-sample case the population distance between groups is \(\Delta^2 = (\boldsymbol{\mu}_1 - \boldsymbol{\mu}_2)^\top \boldsymbol{\Sigma}^{-1} (\boldsymbol{\mu}_1 - \boldsymbol{\mu}_2)\), assuming a common covariance. The corresponding sample estimates plug the sample means and the sample (or pooled) covariance into the same quadratic form.
Link to Hotelling's \(T^2\). Hotelling's (1931) \(T^2\) statistic is \(T^2 = n D^2\) (one sample) or \(T^2 = \{n_1 n_2 / (n_1 + n_2)\} D^2\) (two samples). Under multivariate normality $$\frac{n_1 + n_2 - p - 1}{(n_1 + n_2 - 2)\,p}\,T^2 \sim F'\!\left(p,\, n_1 + n_2 - p - 1,\; \lambda = \frac{n_1 n_2}{n_1 + n_2}\,\Delta^2\right)$$ in the two-sample case, and analogously \(\{(n - p)/[(n-1)p]\}\,T^2 \sim F'(p, n-p, n\Delta^2)\) in the one-sample case (see Anderson, 2003, Section 5.2).
Confidence interval. The CI on \(\Delta^2\) is obtained by
inverting these distributional results (Reiser, 2001): a CI on the
noncentrality parameter \(\lambda\) is constructed via
ci_nc_F and then mapped back to \(\Delta^2\) by
\(\Delta^2 = \lambda\,(n_1 + n_2)/(n_1 n_2)\) (two sample) or
\(\Delta^2 = \lambda / n\) (one sample). When the observed \(F\) is
below the lower-tail critical value of the central F-distribution at
the requested confidence level, the lower CI on \(\lambda\) (and hence
on \(\Delta^2\)) is clamped to zero, in keeping with the
ci_nc_F convention.
Bias. The plug-in estimator \(D^2\) is upward biased for \(\Delta^2\); the CI from this function is exact for \(\Delta^2\) under multivariate normality and reflects the bias structure correctly, but the point estimate reported is the standard plug-in \(D^2\).
Anderson, T. W. (2003). An Introduction to Multivariate Statistical Analysis (4th ed.). Wiley.
Hotelling, H. (1931). The generalization of Student's ratio. The Annals of Mathematical Statistics, 2(3), 360--378.
Mahalanobis, P. C. (1936). On the generalized distance in statistics. Proceedings of the National Institute of Sciences of India, 2(1), 49--55.
Reiser, B. (2001). Confidence intervals for the Mahalanobis distance. Communications in Statistics--Simulation and Computation, 30(1), 37--45. tools:::Rd_expr_doi("10.1081/SAC-100001856")
Steiger, J. H., & Fouladi, R. T. (1997). Noncentrality interval estimation and the evaluation of statistical methods. In L. L. Harlow, S. A. Mulaik, & J. H. Steiger (Eds.), What if there were no significance tests? (pp. 221--257). Mahwah, NJ: Lawrence Erlbaum.
Kelley, K. (2007). Confidence intervals for standardized effect sizes: Theory, application, and implementation. Journal of Statistical Software, 20(8), 1--24. tools:::Rd_expr_doi("10.18637/jss.v020.i08")
ci_nc_F, ci_smd,
ci_R2
Other confidence intervals for effect sizes:
ci_R2(),
ci_c(),
ci_c_ancova(),
ci_c_ancova_bp(),
ci_correlation,
ci_cv(),
ci_eta_squared(),
ci_eta_squared_generalized(),
ci_eta_squared_partial(),
ci_omega_squared(),
ci_pvaf(),
ci_rc(),
ci_reg_coef(),
ci_rmsea(),
ci_sc(),
ci_sc_ancova(),
ci_sm(),
ci_smd(),
ci_smd_c(),
ci_snr(),
ci_src(),
ci_srsnr(),
contrast_adjusted(),
plot_smd()
# Two-sample distance between the two schools of the Holzinger and
# Swineford (1939) study on a four-test cognitive battery.
battery <- c("t1_visual_perception", "t2_cubes", "t4_lozenges",
"t6_paragraph_comprehension")
g1 <- as.matrix(holzinger_swineford[
holzinger_swineford$school == "Grant-White", battery])
g2 <- as.matrix(holzinger_swineford[
holzinger_swineford$school == "Pasteur", battery])
ci_mahalanobis(group_1 = g1, group_2 = g2)
# One-sample distance: how far is the Grant-White centroid from a
# reference vector of (29, 24, 18, 9)?
ci_mahalanobis(group_1 = g1, mu_0 = c(29, 24, 18, 9))
# Pre-computed D^2 (no raw data needed): the two-school distance,
# reproduced from reported summaries.
ci_mahalanobis(D2 = 0.608, n_1 = 145, n_2 = 156, p = 4)
Run the code above in your browser using DataLab