# neurostatx.cli.ExploratoryFA

*module*

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

## neurostatx.cli.ExploratoryFA.app

*attribute* · *module attribute*

```python
app = App(default_parameter=Parameter(negative=()))
```

Cyclopts application for the ExploratoryFA command-line tool.

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

## neurostatx.cli.ExploratoryFA.ExploratoryFA

*function*

```python
def ExploratoryFA(in_dataset: Annotated[str, Parameter(show_default=False, group='Essential Files Options')], id_column: Annotated[str, Parameter(show_default=False, group='Essential Files Options')], desc_columns: Annotated[int, Parameter(show_default=False, group='Essential Files Options')], out_folder: Annotated[str, Parameter(group='Essential Files Options')] = './ResultsEFA/', rotation: Annotated[RotationTypes, Parameter(group='Factorial Analysis parameters')] = RotationTypes.promax, method: Annotated[MethodTypes, Parameter(group='Factorial Analysis parameters')] = MethodTypes.minres, nb_factors: Annotated[int, Parameter(--nb_factors, group='Factorial Analysis parameters')] = None, train_dataset_size: Annotated[float, Parameter(--train_dataset_size, group='Factorial Analysis parameters')] = 0.5, random_state: Annotated[int, Parameter(--random_state, group='Factorial Analysis parameters')] = 1234, verbose: Annotated[bool, Parameter(-v, --verbose, group='Optional parameters')] = False, save_parameters: Annotated[bool, Parameter(-s, --save_parameters, group='Optional parameters')] = False, overwrite: Annotated[bool, Parameter(-f, --overwrite, group='Optional parameters')] = False)
```

Perform exploratory factor analysis with Horn's parallel analysis.

ExploratoryFA fits an EFA model using the provided rotation and method.
When only an EFA is requested, Horn's parallel analysis determines the
optimal number of factors to extract. The script can also split the data
into a training set for EFA and a test set for later
[ConfirmatoryFA][neurostatx.cli.ConfirmatoryFA.ConfirmatoryFA]. It writes
the EFA model, loadings, communalities, and the transformed dataset.

> **Notes**
>
> **Input specifications**
> 
> The dataset can contain multiple descriptive columns before the variables
> of interest. Specify that count with --desc-columns. Rows with missing
> values are removed by default; use the mean or median option to impute
> missing data (be cautious when doing this). See [1], [2], and [3] for
> discussion of EFA vs CFA factor scores.

> **References**
>
> [1] [Costa, V., & Sarmento, R. Confirmatory Factor
> Analysis](https://arxiv.org/ftp/arxiv/papers/1905/1905.05598.pdf)
> 
> [2] [Whether to use EFA or CFA to predict latent variable
> scores](https://stats.stackexchange.com/questions/346499/whether-to-use-efa-or-cfa-to-predict-latent-variables-scores)
> 
> [3] [Comparison of factor score estimation
> methods](https://github.com/gagnonanthony/NeuroStatX/pull/11)

**Parameters**

- `in_dataset` (`str`) — Input dataset to use in the factorial analysis.
- `id_column` (`str`) — Name of the column containing the subject's ID tag. Required for proper handling of IDs and merging multiple datasets.
- `desc_columns` (`int`) — Number of descriptive columns at the beginning of the dataset to exclude in statistics and descriptive tables.
- `out_folder` (`str`) (default: `'./ResultsEFA/'`) — Path of the folder in which the results will be written. If not specified, current folder and default name will be used. Defaults to ``./ResultsEFA/``.
- `rotation` (`RotationTypes`) (default: `RotationTypes.promax`) — Select the type of rotation to apply on your data. Defaults to promax.
- `method` (`MethodTypes`) (default: `MethodTypes.minres`) — Select the method for fitting the data. Defaults to minres.
- `nb_factors` (`int`) (default: `None`) — Specify the number of factors to extract from the data. If not specified, the script will use Horn's parallel analysis to determine the optimal number of factors. Defaults to None.
- `train_dataset_size` (`float`) (default: `0.5`) — Specify the proportion of the input dataset to use as training dataset in the EFA (value from 0 to 1). Defaults to 0.5.
- `random_state` (`int`) (default: `1234`) — Random seed for reproducibility. Defaults to 1234.
- `verbose` (`bool`) (default: `False`) — If true, produce verbose output. Defaults to False.
- `save_parameters` (`bool`) (default: `False`) — If true, save the parameters used in the analysis in a text file. Defaults to False.
- `overwrite` (`bool`) (default: `False`) — If true, force overwriting of existing output files. Defaults to False.

**Examples**

```bash
ExploratoryFA --in-dataset df --id-column IDs --out-folder results_FA/
--rotation promax --method ml --train_dataset_size 0.5 -v -f -s
```

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