diagnostics¶
Diagnostic and utility functions for DesignMatrix.
Methods:
| Name | Description |
|---|---|
clean | Remove highly correlated columns. |
corr | Correlation between DesignMatrix columns as an Adjacency. |
vif | Compute 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) -> DesignMatrixRemove highly correlated columns.
Removes columns with correlation >= threshold. Keeps first instance of correlated pair, drops duplicates.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
dm | DesignMatrix | DesignMatrix instance. | required |
fill_na | int, float, or None | Fill NaN values before checking correlations. Default: 0. | 0 |
exclude_confounds | bool | Skip nuisance/confound columns from correlation check. Default: False. | False |
thresh | float | Correlation threshold (drop if abs(r) >= thresh). Default: 0.95. | 0.95 |
progress_bar | bool | Print dropped column names. Default: False. | False |
Returns:
| Name | Type | Description |
|---|---|---|
DesignMatrix | DesignMatrix | Cleaned matrix with highly correlated columns removed |
corr¶
corr(dm: DesignMatrix, *, metric: str = 'pearson', columns: list[str] | None = None) -> AdjacencyCorrelation 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:
| Name | Type | Description | Default |
|---|---|---|---|
dm | DesignMatrix | DesignMatrix instance. | required |
metric | str | 'pearson' (default) or 'spearman'. Spearman is computed as Pearson on column ranks. | ‘pearson’ |
columns | list of str | Subset of columns to correlate. Defaults to all columns. | None |
Returns:
| Name | Type | Description |
|---|---|---|
Adjacency | Adjacency | Similarity 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 | NoneCompute the variance inflation factor for each column.
Uses diagonal elements of inverted correlation matrix (same method as Matlab and R).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
dm | DesignMatrix | DesignMatrix instance. | required |
exclude_confounds | bool | Skip nuisance/confound columns. Default: True. | True |
Returns:
| Type | Description |
|---|---|
ndarray | None | np.ndarray: VIF values for each included column. Returns None if the correlation matrix is singular (perfect collinearity detected). |