Usage

A short explanation of MULTISPATI-PCA is provided in the documentation of multispaeti.MultispatiPCA. For a more comprehensive understanding the interested reader is referred to the original publication of Dray et al. as well as a related publication by Jombart et al.

Briefly, MULTISPATI-PCA tries to maximize the product of variance and Moran’s I for each retrieved component. Components with (large) positive eigenvalues are spatially auto-correlated while (large) negative eigenvalues identify components of negative auto-correlation.

The general usage follows the patterns in sklearn.decomposition.

We first create an instance of multispaeti.MultispatiPCA specifying a connectivity matrix and optionally the desired number of components to be retrieved.

from multispaeti import MultispatiPCA

msPCA = MultispatiPCA(n_components=(30, 5), connectivity=connectivity)

In this case this would retrieve the 30 largest as well as 5 smallest eigenvalues and their respective eigenvectors.

As for e.g. sklearn.decomposition.PCA we first need to multispaeti.MultispatiPCA.fit() and than multispaeti.MultispatiPCA.transform() our data matrix X (n observations \(\times\) d features).

msPCA.fit(X)
X_transformed = msPCA.transform(X)

Alternatively, this can be achieved in one step by multispaeti.MultispatiPCA.fit_transform() which avoids redundant computation.

X_transformed = msPCA.fit_transform(X)

If only the transformed data matrix and selected components are of interest, the most efficient is to call multispaeti.multispati_pca() directly as this will avoid calculating additional statistics such as variance and Moran’s I.

from multispaeti import multispati_pca

X_transformed, components = multispati_pca(
    X, n_components=(30, 5), connectivity=connectivity
)