Skip to contents

Computes the test statistic shared by the post-clustering inference functions test.clusters.hc, test.clusters.km, and test.clusters.MC: the V-norm of the difference between the means of two selected clusters, \(\|\nu^\top X\|_V = \sqrt{(\nu^\top X)^\top V^{-1} (\nu^\top X)}\), where \(\nu^\top X\) is the difference of cluster means and \(V = (\nu^\top U \nu)\,\Sigma\), with \(\nu\) the contrast vector between the two selected clusters.

Usage

test_statistic(cl, clusters, X, U, Sigma)

Arguments

cl

Integer (or factor) vector of length \(n\) giving the cluster assignment of each observation.

clusters

Integer vector of length 2 specifying the pair of clusters to compare. Both entries must be present in cl.

X

A numeric \(n \times p\) data matrix.

U

An \(n \times n\) positive-definite matrix describing the dependence structure between the rows of X.

Sigma

A \(p \times p\) positive-definite matrix describing the dependence structure between the columns of X.

Value

A numeric scalar giving the test statistic (V-norm of the difference of cluster means).

Examples

n <- 30; p <- 5
X <- matrix(rnorm(n * p), nrow = n)
cl <- rep(1:3, each = 10)
test_statistic(cl = cl, clusters = c(1, 2), X = X, U = diag(n), Sigma = diag(p))
#> [1] 2.312216