mvtsa.representation.PCAModel#

class mvtsa.representation.PCAModel(n_components=0.95, center=True, scale=False, lags=0)[source]#

Bases: object

Principal component model with monitoring statistics.

Parameters:
n_componentsint, float or str

Retained components (see resolve_n_components()).

centerbool

Subtract the mean before the eigen-decomposition. With False the model describes the data about the origin, which makes the \(T^2\) statistic sensitive to the drift of the operating point.

scalebool

Divide every variable by its standard deviation (correlation PCA).

lagsint

Number of lags: if positive, the model is a dynamic PCA model fitted to the lag-extended matrix (mvtsa.preprocessing.dynamize()).

Attributes:
mean_, scale_arrays (n,)
eigenvalues_array (n,)

All eigenvalues of the covariance matrix, in decreasing order.

components_array (n, p)

Loadings: the retained eigenvectors as columns.

n_components_int
explained_variance_ratio_array (p,)

Examples

>>> rng = np.random.default_rng(0)
>>> t = rng.normal(size=(200, 1))
>>> X = np.hstack([t, 2 * t, -t]) + 0.01 * rng.normal(size=(200, 3))
>>> PCAModel(0.99).fit(X).n_components_
1
contributions(X, statistic='Q')[source]#

Contribution of every variable to \(Q\) or \(T^2\) at every sample (columns refer to the possibly lagged variables).

control_limits(alpha=0.01)[source]#

Upper control limits of \(T^2\) (F distribution) and \(Q\) (Jackson and Mudholkar, 1979) at significance alpha.

q_statistic(X)[source]#

Squared prediction error \(Q(t)=\lVert z_t-UU^{\mathsf T}z_t\rVert^2\).

reconstruct(X)[source]#

Reconstruction in the original units (of the possibly lagged matrix).

similarity(other, kind='krzanowski')[source]#

PCA similarity factor between two fitted models (see krzanowski_similarity(), lambda_similarity()).

t2_statistic(X, scaled=True)[source]#

Hotelling \(T^2\). With scaled=False the unscaled squared norm of the scores is returned (the form used by Bankó, 2015).

transform(X)[source]#

Scores (T', p).

Examples using mvtsa.representation.PCAModel#

PCA models: T², Q and similarity factors

PCA models: T², Q and similarity factors