Skip to article frontmatterSkip to article content
Site not loading correctly?

This may be due to an incorrect BASE_URL configuration. See the MyST Documentation for reference.

diagnostics

diagnostics

Diagnostic and utility functions for DesignMatrix.

Methods:

NameDescription
cleanRemove highly correlated columns.
corrCorrelation between DesignMatrix columns as an Adjacency.
vifCompute the variance inflation factor for each column.

Classes

Methods

clean

clean(dm: DesignMatrix, *, fill_na: int | float | None = 0, exclude_confounds: bool = False, thresh: float = 0.95, progress_bar: bool = False) -> DesignMatrix

Remove highly correlated columns.

Removes columns with correlation >= threshold. Keeps first instance of correlated pair, drops duplicates.

Parameters:

NameTypeDescriptionDefault
dmDesignMatrixDesignMatrix instance.required
fill_naint, float, or NoneFill NaN values before checking correlations. Default: 0.0
exclude_confoundsboolSkip nuisance/confound columns from correlation check. Default: False.False
threshfloatCorrelation threshold (drop if abs(r) >= thresh). Default: 0.95.0.95
progress_barboolPrint dropped column names. Default: False.False

Returns:

NameTypeDescription
DesignMatrixDesignMatrixCleaned matrix with highly correlated columns removed

corr

corr(dm: DesignMatrix, *, metric: str = 'pearson', columns: list[str] | None = None) -> Adjacency

Correlation between DesignMatrix columns as an Adjacency.

Returns the column-by-column correlation matrix wrapped in an nltools Adjacency (matrix_type='similarity') so it composes with the rest of the similarity-matrix tooling (.plot(), MDS, etc.). The Adjacency stores only the off-diagonal entries — self-correlation isn’t a meaningful edge — so the unit diagonal is implicit; DesignMatrix.plot(method='corr') restores it for display.

Parameters:

NameTypeDescriptionDefault
dmDesignMatrixDesignMatrix instance.required
metricstr'pearson' (default) or 'spearman'. Spearman is computed as Pearson on column ranks.‘pearson’
columnslist of strSubset of columns to correlate. Defaults to all columns.None

Returns:

NameTypeDescription
AdjacencyAdjacencySimilarity matrix whose labels are the included column names.
Note

Constant columns (e.g. the .nl_poly_0 intercept) have zero variance and yield NaN correlations.

vif

vif(dm: DesignMatrix, exclude_confounds: bool = True) -> np.ndarray | None

Compute the variance inflation factor for each column.

Uses diagonal elements of inverted correlation matrix (same method as Matlab and R).

Parameters:

NameTypeDescriptionDefault
dmDesignMatrixDesignMatrix instance.required
exclude_confoundsboolSkip nuisance/confound columns. Default: True.True

Returns:

TypeDescription
ndarray | Nonenp.ndarray: VIF values for each included column. Returns None if the correlation matrix is singular (perfect collinearity detected).