hotelling_t2#

skfda.inference.hotelling.hotelling_t2(fd1, fd2)[source]#

Compute Hotelling’s \(T^2\) statistic.

Calculates Hotelling’s \(T^2\) over two samples in skfda.representation.FData objects with sizes \(n_1\) and \(n_2\).

\[T^2 = n(\mathbf{m}_1 - \mathbf{m}_2)^\top \mathbf{W}^{1/2}( \mathbf{W}^{1/2}\mathbf{K_{\operatorname{pooled}}} \mathbf{W}^{ 1/2})^+ \mathbf{W}^{1/2} (\mathbf{m}_1 - \mathbf{m}_2),\]

where \((\cdot)^{+}\) indicates the Moore-Penrose pseudo-inverse operator, \(n=n_1+n_2\), W is Gram matrix (identity in case of discretized data), \(\mathbf{m}_1, \mathbf{m}_2\) are the means of each ample and \(\mathbf{K}_{\operatorname{pooled}}\) matrix is defined as

\[\mathbf{K}_{\operatorname{pooled}} := \cfrac{n_1 - 1}{n_1 + n_2 - 2} \mathbf{K}_{n_1} + \cfrac{n_2 - 1}{n_1 + n_2 - 2} \mathbf{K}_{n_2},\]

where \(\mathbf{K}_{n_1}\), \(\mathbf{K}_{n_2}\) are the sample covariance matrices, computed with the basis coefficients or using the discrete representation, depending on the input.

This statistic is defined in Pini, Stamm and Vantini [1].

Parameters:
  • fd1 (FData) – Object with the first sample.

  • fd2 (FData) – Object containing second sample.

Returns:

The value of the statistic.

Raises:

TypeError.

Return type:

float

Examples

>>> from skfda.inference.hotelling import hotelling_t2
>>> from skfda.representation import FDataGrid, basis
>>> fd1 = FDataGrid([[1, 1, 1], [3, 3, 3]])
>>> fd2 = FDataGrid([[3, 3, 3], [5, 5, 5]])
>>> '%.2f' % hotelling_t2(fd1, fd2)
'2.00'
>>> fd1 = fd1.to_basis(basis.FourierBasis(n_basis=3))
>>> fd2 = fd2.to_basis(basis.FourierBasis(n_basis=3))
>>> '%.2f' % hotelling_t2(fd1, fd2)
'2.00'

References