# neurostatx.statistics.models

*module*

[View source](https://github.com/gagnonanthony/NeuroStatX/blob/main/neurostatx/statistics/models.py#L1-L1)

## neurostatx.statistics.models.GAD7Labeler

*class*

```python
class GAD7Labeler
```

Assign GAD-7 severity labels from the seven questionnaire items.

[View source](https://github.com/gagnonanthony/NeuroStatX/blob/main/neurostatx/statistics/models.py#L536-L681)

### neurostatx.statistics.models.GAD7Labeler.fit

*method*

```python
def fit(X, y=None)
```

Label GAD-7 item scores.

Delegates to
[transform][neurostatx.statistics.models.GAD7Labeler.transform].

**Parameters**

- `X` (`pd.DataFrame`) — Item scores of shape (n_samples, 7).
- `y` (`pd.Series`) (default: `None`) — Unused target, kept for sklearn compatibility.

**Returns**

- `labels` (`pd.Series`) — Severity labels returned by ``transform``.

**Examples**

```pycon
>>> import pandas as pd
>>> from neurostatx.statistics.models import GAD7Labeler
>>> X = pd.DataFrame([[0] * 7])
>>> GAD7Labeler().fit(X).iloc[0]
'Subthreshold'
```

[View source](https://github.com/gagnonanthony/NeuroStatX/blob/main/neurostatx/statistics/models.py#L542-L574)

### neurostatx.statistics.models.GAD7Labeler.transform

*method*

```python
def transform(X)
```

Assign a GAD-7 severity label to each row.

Labels are ``Subthreshold``, ``Mild``, ``Moderate``, or ``Severe``.

**Parameters**

- `X` (`pd.DataFrame`) — Item scores of shape (n_samples, 7).

**Returns**

- `labels` (`pd.Series`) — One severity label per sample.

**Examples**

```pycon
>>> import pandas as pd
>>> from neurostatx.statistics.models import GAD7Labeler
>>> X = pd.DataFrame([[0] * 7])
>>> GAD7Labeler().transform(X).iloc[0]
'Subthreshold'
```

[View source](https://github.com/gagnonanthony/NeuroStatX/blob/main/neurostatx/statistics/models.py#L576-L681)

## neurostatx.statistics.models.PHQ9Labeler

*class*

```python
class PHQ9Labeler
```

Assign PHQ-9 severity labels from the nine questionnaire items.

[View source](https://github.com/gagnonanthony/NeuroStatX/blob/main/neurostatx/statistics/models.py#L382-L533)

### neurostatx.statistics.models.PHQ9Labeler.fit

*method*

```python
def fit(X, y=None)
```

Label PHQ-9 item scores.

Delegates to
[transform][neurostatx.statistics.models.PHQ9Labeler.transform].

**Parameters**

- `X` (`pd.DataFrame`) — Item scores of shape (n_samples, 9).
- `y` (`pd.Series`) (default: `None`) — Unused target, kept for sklearn compatibility.

**Returns**

- `labels` (`pd.Series`) — Severity labels returned by ``transform``.

**Examples**

```pycon
>>> import pandas as pd
>>> from neurostatx.statistics.models import PHQ9Labeler
>>> X = pd.DataFrame([[0] * 9])
>>> PHQ9Labeler().fit(X).iloc[0]
'Subthreshold'
```

[View source](https://github.com/gagnonanthony/NeuroStatX/blob/main/neurostatx/statistics/models.py#L388-L420)

### neurostatx.statistics.models.PHQ9Labeler.transform

*method*

```python
def transform(X)
```

Assign a PHQ-9 severity label to each row.

Labels are ``Subthreshold``, ``Mild``, ``Moderate``, ``Mod-Severe``,
or ``Severe``.

**Parameters**

- `X` (`pd.DataFrame`) — Item scores of shape (n_samples, 9).

**Returns**

- `labels` (`pd.Series`) — One severity label per sample.

**Examples**

```pycon
>>> import pandas as pd
>>> from neurostatx.statistics.models import PHQ9Labeler
>>> X = pd.DataFrame([[0] * 9])
>>> PHQ9Labeler().transform(X).iloc[0]
'Subthreshold'
```

[View source](https://github.com/gagnonanthony/NeuroStatX/blob/main/neurostatx/statistics/models.py#L422-L533)

## neurostatx.statistics.models.Penalty

*class*

```python
class Penalty(StrEnum, Enum)
```

Bases: `StrEnum`, `Enum`

Regularization penalties for logistic regression.

[View source](https://github.com/gagnonanthony/NeuroStatX/blob/main/neurostatx/statistics/models.py#L67-L72)

### neurostatx.statistics.models.Penalty.elasticnet

*attribute* · *class attribute* · *instance attribute*

```python
elasticnet = 'elasticnet'
```

[View source](https://github.com/gagnonanthony/NeuroStatX/blob/main/neurostatx/statistics/models.py#L72-L72)

### neurostatx.statistics.models.Penalty.l1

*attribute* · *class attribute* · *instance attribute*

```python
l1 = 'l1'
```

[View source](https://github.com/gagnonanthony/NeuroStatX/blob/main/neurostatx/statistics/models.py#L70-L70)

### neurostatx.statistics.models.Penalty.l2

*attribute* · *class attribute* · *instance attribute*

```python
l2 = 'l2'
```

[View source](https://github.com/gagnonanthony/NeuroStatX/blob/main/neurostatx/statistics/models.py#L71-L71)

## neurostatx.statistics.models.ScoringMethod

*class*

```python
class ScoringMethod(StrEnum, Enum)
```

Bases: `StrEnum`, `Enum`

sklearn scoring names accepted by permutation testing.

[View source](https://github.com/gagnonanthony/NeuroStatX/blob/main/neurostatx/statistics/models.py#L20-L64)

### neurostatx.statistics.models.ScoringMethod.accuracy

*attribute* · *class attribute* · *instance attribute*

```python
accuracy = 'accuracy'
```

[View source](https://github.com/gagnonanthony/NeuroStatX/blob/main/neurostatx/statistics/models.py#L23-L23)

### neurostatx.statistics.models.ScoringMethod.adjusted_mutual_info_score

*attribute* · *class attribute* · *instance attribute*

```python
adjusted_mutual_info_score = 'adjusted_mutual_info_score'
```

[View source](https://github.com/gagnonanthony/NeuroStatX/blob/main/neurostatx/statistics/models.py#L43-L43)

### neurostatx.statistics.models.ScoringMethod.adjusted_rand_score

*attribute* · *class attribute* · *instance attribute*

```python
adjusted_rand_score = 'adjusted_rand_score'
```

[View source](https://github.com/gagnonanthony/NeuroStatX/blob/main/neurostatx/statistics/models.py#L42-L42)

### neurostatx.statistics.models.ScoringMethod.average_precision

*attribute* · *class attribute* · *instance attribute*

```python
average_precision = 'average_precision'
```

[View source](https://github.com/gagnonanthony/NeuroStatX/blob/main/neurostatx/statistics/models.py#L26-L26)

### neurostatx.statistics.models.ScoringMethod.balanced_accuracy

*attribute* · *class attribute* · *instance attribute*

```python
balanced_accuracy = 'balanced_accuracy'
```

[View source](https://github.com/gagnonanthony/NeuroStatX/blob/main/neurostatx/statistics/models.py#L24-L24)

### neurostatx.statistics.models.ScoringMethod.completeness_score

*attribute* · *class attribute* · *instance attribute*

```python
completeness_score = 'completeness_score'
```

[View source](https://github.com/gagnonanthony/NeuroStatX/blob/main/neurostatx/statistics/models.py#L44-L44)

### neurostatx.statistics.models.ScoringMethod.d2_absolute_error_score

*attribute* · *class attribute* · *instance attribute*

```python
d2_absolute_error_score = 'd2_absolute_error_score'
```

[View source](https://github.com/gagnonanthony/NeuroStatX/blob/main/neurostatx/statistics/models.py#L62-L62)

### neurostatx.statistics.models.ScoringMethod.d2_pinball_score

*attribute* · *class attribute* · *instance attribute*

```python
d2_pinball_score = 'd2_pinball_score'
```

[View source](https://github.com/gagnonanthony/NeuroStatX/blob/main/neurostatx/statistics/models.py#L63-L63)

### neurostatx.statistics.models.ScoringMethod.d2_tweedie_score

*attribute* · *class attribute* · *instance attribute*

```python
d2_tweedie_score = 'd2_tweedie_score'
```

[View source](https://github.com/gagnonanthony/NeuroStatX/blob/main/neurostatx/statistics/models.py#L64-L64)

### neurostatx.statistics.models.ScoringMethod.explained_variance

*attribute* · *class attribute* · *instance attribute*

```python
explained_variance = 'explained_variance'
```

[View source](https://github.com/gagnonanthony/NeuroStatX/blob/main/neurostatx/statistics/models.py#L51-L51)

### neurostatx.statistics.models.ScoringMethod.f1

*attribute* · *class attribute* · *instance attribute*

```python
f1 = 'f1'
```

[View source](https://github.com/gagnonanthony/NeuroStatX/blob/main/neurostatx/statistics/models.py#L28-L28)

### neurostatx.statistics.models.ScoringMethod.f1_macro

*attribute* · *class attribute* · *instance attribute*

```python
f1_macro = 'f1_macro'
```

[View source](https://github.com/gagnonanthony/NeuroStatX/blob/main/neurostatx/statistics/models.py#L30-L30)

### neurostatx.statistics.models.ScoringMethod.f1_micro

*attribute* · *class attribute* · *instance attribute*

```python
f1_micro = 'f1_micro'
```

[View source](https://github.com/gagnonanthony/NeuroStatX/blob/main/neurostatx/statistics/models.py#L29-L29)

### neurostatx.statistics.models.ScoringMethod.f1_samples

*attribute* · *class attribute* · *instance attribute*

```python
f1_samples = 'f1_samples'
```

[View source](https://github.com/gagnonanthony/NeuroStatX/blob/main/neurostatx/statistics/models.py#L32-L32)

### neurostatx.statistics.models.ScoringMethod.f1_weighted

*attribute* · *class attribute* · *instance attribute*

```python
f1_weighted = 'f1_weighted'
```

[View source](https://github.com/gagnonanthony/NeuroStatX/blob/main/neurostatx/statistics/models.py#L31-L31)

### neurostatx.statistics.models.ScoringMethod.fowlkes_mallows_score

*attribute* · *class attribute* · *instance attribute*

```python
fowlkes_mallows_score = 'fowlkes_mallows_score'
```

[View source](https://github.com/gagnonanthony/NeuroStatX/blob/main/neurostatx/statistics/models.py#L45-L45)

### neurostatx.statistics.models.ScoringMethod.homogeneity_score

*attribute* · *class attribute* · *instance attribute*

```python
homogeneity_score = 'homogeneity_score'
```

[View source](https://github.com/gagnonanthony/NeuroStatX/blob/main/neurostatx/statistics/models.py#L46-L46)

### neurostatx.statistics.models.ScoringMethod.jaccard

*attribute* · *class attribute* · *instance attribute*

```python
jaccard = 'jaccard'
```

[View source](https://github.com/gagnonanthony/NeuroStatX/blob/main/neurostatx/statistics/models.py#L36-L36)

### neurostatx.statistics.models.ScoringMethod.max_error

*attribute* · *class attribute* · *instance attribute*

```python
max_error = 'max_error'
```

[View source](https://github.com/gagnonanthony/NeuroStatX/blob/main/neurostatx/statistics/models.py#L52-L52)

### neurostatx.statistics.models.ScoringMethod.mutual_info_score

*attribute* · *class attribute* · *instance attribute*

```python
mutual_info_score = 'mutual_info_score'
```

[View source](https://github.com/gagnonanthony/NeuroStatX/blob/main/neurostatx/statistics/models.py#L47-L47)

### neurostatx.statistics.models.ScoringMethod.neg_brier_score

*attribute* · *class attribute* · *instance attribute*

```python
neg_brier_score = 'neg_brier_score'
```

[View source](https://github.com/gagnonanthony/NeuroStatX/blob/main/neurostatx/statistics/models.py#L27-L27)

### neurostatx.statistics.models.ScoringMethod.neg_log_loss

*attribute* · *class attribute* · *instance attribute*

```python
neg_log_loss = 'neg_log_loss'
```

[View source](https://github.com/gagnonanthony/NeuroStatX/blob/main/neurostatx/statistics/models.py#L33-L33)

### neurostatx.statistics.models.ScoringMethod.neg_mean_absolute_error

*attribute* · *class attribute* · *instance attribute*

```python
neg_mean_absolute_error = 'neg_mean_absolute_error'
```

[View source](https://github.com/gagnonanthony/NeuroStatX/blob/main/neurostatx/statistics/models.py#L53-L53)

### neurostatx.statistics.models.ScoringMethod.neg_mean_absolute_percentage_error

*attribute* · *class attribute* · *instance attribute*

```python
neg_mean_absolute_percentage_error = 'neg_mean_absolute_percentage_error'
```

[View source](https://github.com/gagnonanthony/NeuroStatX/blob/main/neurostatx/statistics/models.py#L61-L61)

### neurostatx.statistics.models.ScoringMethod.neg_mean_gamma_deviance

*attribute* · *class attribute* · *instance attribute*

```python
neg_mean_gamma_deviance = 'neg_mean_gamma_deviance'
```

[View source](https://github.com/gagnonanthony/NeuroStatX/blob/main/neurostatx/statistics/models.py#L60-L60)

### neurostatx.statistics.models.ScoringMethod.neg_mean_poisson_deviance

*attribute* · *class attribute* · *instance attribute*

```python
neg_mean_poisson_deviance = 'neg_mean_poisson_deviance'
```

[View source](https://github.com/gagnonanthony/NeuroStatX/blob/main/neurostatx/statistics/models.py#L59-L59)

### neurostatx.statistics.models.ScoringMethod.neg_mean_squared_error

*attribute* · *class attribute* · *instance attribute*

```python
neg_mean_squared_error = 'neg_mean_squared_error'
```

[View source](https://github.com/gagnonanthony/NeuroStatX/blob/main/neurostatx/statistics/models.py#L54-L54)

### neurostatx.statistics.models.ScoringMethod.neg_mean_squared_log_error

*attribute* · *class attribute* · *instance attribute*

```python
neg_mean_squared_log_error = 'neg_mean_squared_log_error'
```

[View source](https://github.com/gagnonanthony/NeuroStatX/blob/main/neurostatx/statistics/models.py#L55-L55)

### neurostatx.statistics.models.ScoringMethod.neg_median_absolute_error

*attribute* · *class attribute* · *instance attribute*

```python
neg_median_absolute_error = 'neg_median_absolute_error'
```

[View source](https://github.com/gagnonanthony/NeuroStatX/blob/main/neurostatx/statistics/models.py#L56-L56)

### neurostatx.statistics.models.ScoringMethod.neg_root_mean_squared_error

*attribute* · *class attribute* · *instance attribute*

```python
neg_root_mean_squared_error = 'neg_root_mean_squared_error'
```

[View source](https://github.com/gagnonanthony/NeuroStatX/blob/main/neurostatx/statistics/models.py#L57-L57)

### neurostatx.statistics.models.ScoringMethod.normalized_mutual_info_score

*attribute* · *class attribute* · *instance attribute*

```python
normalized_mutual_info_score = 'normalized_mutual_info_score'
```

[View source](https://github.com/gagnonanthony/NeuroStatX/blob/main/neurostatx/statistics/models.py#L48-L48)

### neurostatx.statistics.models.ScoringMethod.precision

*attribute* · *class attribute* · *instance attribute*

```python
precision = 'precision'
```

[View source](https://github.com/gagnonanthony/NeuroStatX/blob/main/neurostatx/statistics/models.py#L34-L34)

### neurostatx.statistics.models.ScoringMethod.r2

*attribute* · *class attribute* · *instance attribute*

```python
r2 = 'r2'
```

[View source](https://github.com/gagnonanthony/NeuroStatX/blob/main/neurostatx/statistics/models.py#L58-L58)

### neurostatx.statistics.models.ScoringMethod.rand_score

*attribute* · *class attribute* · *instance attribute*

```python
rand_score = 'rand_score'
```

[View source](https://github.com/gagnonanthony/NeuroStatX/blob/main/neurostatx/statistics/models.py#L50-L50)

### neurostatx.statistics.models.ScoringMethod.recall

*attribute* · *class attribute* · *instance attribute*

```python
recall = 'recall'
```

[View source](https://github.com/gagnonanthony/NeuroStatX/blob/main/neurostatx/statistics/models.py#L35-L35)

### neurostatx.statistics.models.ScoringMethod.roc_auc

*attribute* · *class attribute* · *instance attribute*

```python
roc_auc = 'roc_auc'
```

[View source](https://github.com/gagnonanthony/NeuroStatX/blob/main/neurostatx/statistics/models.py#L37-L37)

### neurostatx.statistics.models.ScoringMethod.roc_auc_ovo

*attribute* · *class attribute* · *instance attribute*

```python
roc_auc_ovo = 'roc_auc_ovo'
```

[View source](https://github.com/gagnonanthony/NeuroStatX/blob/main/neurostatx/statistics/models.py#L39-L39)

### neurostatx.statistics.models.ScoringMethod.roc_auc_ovo_weighted

*attribute* · *class attribute* · *instance attribute*

```python
roc_auc_ovo_weighted = 'roc_auc_ovo_weighted'
```

[View source](https://github.com/gagnonanthony/NeuroStatX/blob/main/neurostatx/statistics/models.py#L41-L41)

### neurostatx.statistics.models.ScoringMethod.roc_auc_ovr

*attribute* · *class attribute* · *instance attribute*

```python
roc_auc_ovr = 'roc_auc_ovr'
```

[View source](https://github.com/gagnonanthony/NeuroStatX/blob/main/neurostatx/statistics/models.py#L38-L38)

### neurostatx.statistics.models.ScoringMethod.roc_auc_ovr_weighted

*attribute* · *class attribute* · *instance attribute*

```python
roc_auc_ovr_weighted = 'roc_auc_ovr_weighted'
```

[View source](https://github.com/gagnonanthony/NeuroStatX/blob/main/neurostatx/statistics/models.py#L40-L40)

### neurostatx.statistics.models.ScoringMethod.top_k_accuracy

*attribute* · *class attribute* · *instance attribute*

```python
top_k_accuracy = 'top_k_accuracy'
```

[View source](https://github.com/gagnonanthony/NeuroStatX/blob/main/neurostatx/statistics/models.py#L25-L25)

### neurostatx.statistics.models.ScoringMethod.v_measure_score

*attribute* · *class attribute* · *instance attribute*

```python
v_measure_score = 'v_measure_score'
```

[View source](https://github.com/gagnonanthony/NeuroStatX/blob/main/neurostatx/statistics/models.py#L49-L49)

## neurostatx.statistics.models.Solver

*class*

```python
class Solver(StrEnum, Enum)
```

Bases: `StrEnum`, `Enum`

sklearn LogisticRegression solver names.

[View source](https://github.com/gagnonanthony/NeuroStatX/blob/main/neurostatx/statistics/models.py#L75-L83)

### neurostatx.statistics.models.Solver.lbfgs

*attribute* · *class attribute* · *instance attribute*

```python
lbfgs = 'lbfgs'
```

[View source](https://github.com/gagnonanthony/NeuroStatX/blob/main/neurostatx/statistics/models.py#L80-L80)

### neurostatx.statistics.models.Solver.liblinear

*attribute* · *class attribute* · *instance attribute*

```python
liblinear = 'liblinear'
```

[View source](https://github.com/gagnonanthony/NeuroStatX/blob/main/neurostatx/statistics/models.py#L81-L81)

### neurostatx.statistics.models.Solver.newton_cg

*attribute* · *class attribute* · *instance attribute*

```python
newton_cg = 'newton-cg'
```

[View source](https://github.com/gagnonanthony/NeuroStatX/blob/main/neurostatx/statistics/models.py#L78-L78)

### neurostatx.statistics.models.Solver.newton_cholesky

*attribute* · *class attribute* · *instance attribute*

```python
newton_cholesky = 'newton-cholesky'
```

[View source](https://github.com/gagnonanthony/NeuroStatX/blob/main/neurostatx/statistics/models.py#L79-L79)

### neurostatx.statistics.models.Solver.sag

*attribute* · *class attribute* · *instance attribute*

```python
sag = 'sag'
```

[View source](https://github.com/gagnonanthony/NeuroStatX/blob/main/neurostatx/statistics/models.py#L82-L82)

### neurostatx.statistics.models.Solver.saga

*attribute* · *class attribute* · *instance attribute*

```python
saga = 'saga'
```

[View source](https://github.com/gagnonanthony/NeuroStatX/blob/main/neurostatx/statistics/models.py#L83-L83)

## neurostatx.statistics.models.permutation_testing

*function*

```python
def permutation_testing(estimator, X, Y, binary=False, nb_permutations=1000, scoring='r2', splits=10, processes=1, verbose=False)
```

Permutation-test an estimator's score and coefficients.

**Parameters**

- `estimator` (`estimator`) — Unfitted sklearn-compatible estimator.
- `X` (`pd.DataFrame`) — Predictor variables.
- `Y` (`pd.DataFrame`) — Dependent variables.
- `binary` (`bool`) (default: `False`) — Unused flag kept for API compatibility. Defaults to False.
- `nb_permutations` (`int`) (default: `1000`) — Number of permutations. Defaults to 1000.
- `scoring` (`str`) (default: `'r2'`) — Scoring name passed to sklearn. Defaults to ``"r2"``.
- `splits` (`int`) (default: `10`) — Number of cross-validation folds. Defaults to 10.
- `processes` (`int`) (default: `1`) — Number of parallel jobs. Defaults to 1.
- `verbose` (`bool`) (default: `False`) — If True, increase sklearn Parallel verbosity. Defaults to False.

**Returns**

- `mod` (`estimator`) — Fitted estimator from the unpermuted data.
- `score` (`float`) — Observed score.
- `coef` (`array`) — Observed coefficients.
- `perm_score` (`array`) — Permuted scores.
- `score_pvalue` (`float`) — P-value for the observed score.
- `perm_coef` (`array`) — Permuted coefficients.
- `coef_pvalue` (`array`) — P-values for the coefficients.

**Examples**

```pycon
>>> import numpy as np
>>> from sklearn.linear_model import LinearRegression
>>> from neurostatx.statistics.models import permutation_testing
>>> rng = np.random.RandomState(0)
>>> X = rng.rand(20, 2)
>>> Y = X[:, 0] + 0.1 * rng.rand(20)
>>> mod, score, coef, perm_score, score_pvalue, perm_coef, coef_pvalue = (
...     permutation_testing(LinearRegression(), X, Y, nb_permutations=5,
...                         splits=3, processes=1)
... )
```

[View source](https://github.com/gagnonanthony/NeuroStatX/blob/main/neurostatx/statistics/models.py#L176-L257)

## neurostatx.statistics.models.plsr_cv

*function*

```python
def plsr_cv(X, Y, nb_comp, max_iter=1000, splits=10, processes=1, verbose=False)
```

Fit a PLSR model and choose the component count by cross-validation.

**Parameters**

- `X` (`pd.DataFrame`) — Predictor variables.
- `Y` (`pd.DataFrame`) — Dependent variables.
- `nb_comp` (`int`) — Maximum number of components to evaluate.
- `max_iter` (`int`) (default: `1000`) — Maximum iterations for PLSR. Defaults to 1000.
- `splits` (`int`) (default: `10`) — Number of cross-validation folds. Defaults to 10.
- `processes` (`int`) (default: `1`) — Number of parallel jobs. Defaults to 1.
- `verbose` (`bool`) (default: `False`) — If True, show a progress bar. Defaults to False.

**Returns**

- `plsr` (`PLSRegression`) — Fitted model using the component count with lowest CV MSE.
- `mse` (`list`) — Cross-validated MSE for each component count.
- `score_c` (`float`) — In-sample R2 score.
- `score_cv` (`float`) — Cross-validated R2 score.
- `rscore` (`float`) — Square root of the in-sample R2 score.
- `mse_c` (`float`) — In-sample mean squared error.
- `mse_cv` (`float`) — Cross-validated mean squared error.

**Examples**

```pycon
>>> import pandas as pd
>>> from neurostatx.statistics.models import plsr_cv
>>> X = pd.DataFrame({"a": [1, 2, 3, 4], "b": [2, 1, 4, 3]})
>>> Y = pd.DataFrame({"y": [1.1, 1.9, 3.2, 3.8]})
>>> plsr, mse, score_c, score_cv, rscore, mse_c, mse_cv = plsr_cv(
...     X, Y, nb_comp=2, splits=2
... )
```

[View source](https://github.com/gagnonanthony/NeuroStatX/blob/main/neurostatx/statistics/models.py#L86-L173)
