Skip to content

factor

class MethodTypes(value, names=None, *, module=None, qualname=None, type=None, start=1, boundary=None)

Bases: StrEnum, Enum

minres = ‘minres’

ml = ‘ml’

principal = ‘principal’

class RotationTypes(value, names=None, *, module=None, qualname=None, type=None, start=1, boundary=None)

Bases: StrEnum, Enum

equamax = ‘equamax’

oblimax = ‘oblimax’

oblimin = ‘oblimin’

promax = ‘promax’

quartimax = ‘quartimax’

quartimin = ‘quartimin’

varimax = ‘varimax’

cfa(df, model)

Used to compute a confirmatory factor analysis (CFA) to evaluate the goodness of fit of the model.

This function uses the semopy package to evaluate the goodness of fit of the proposed model (https://semopy.com/).

Parameters

df : Input dataset with only variables to include in the CFA.

model : Model description for the CFA.

Returns

semopy.Model : Model object containing the CFA.

scores : Factor scores of the model.

stats : Statistics of the model.

efa(df, method, rotation, nfactors=1)

Function to compute a simple exploratory factor analysis (EFA) using the factor_analyzer package.

Parameters

df : Input dataset with only variables to include in the EFA.

method : Method used to fit the model. List of possible methods:

  • minres: Minimal Residual
  • ml: Maximum Likelihood Factor
  • principal: Principal Component

rotation : Rotation method to apply to the factor loadings: List of possible rotations:

  • varimax: Orthogonal Rotation
  • promax: Oblique Rotation
  • oblimin: Oblique Rotation
  • oblimax: Orthogonal Rotation
  • quartimin: Oblique Rotation
  • quartimax: Orthogonal Rotation
  • equamax: Orthogonal Rotation

nfactors : Number of factors (latent variables) to extract from the data. Defaults to 1.

Returns

FactorAnalyzer : FactorAnalyzer object containing the model.

ev : Original eigenvalues of the model.

v : Common factor eigenvalues of the model.

scores : Factor scores of the model.

loadings : Loadings of the model.

communalities : Communalities of the model.

horn_parallel_analysis(x, output_folder, method=‘minres’, rotation=None, nfactors=1, niter=20)

This function is mimicking the function from the psych R package fa.parallel to compute the horn’s parallel analysis to determine the appropriate number of factors to use in factorial analysis.

Portion of this code comes from this post on stackoverflow : https://stackoverflow.com/questions/62303782/is-there-a-way-to-conduct-a-parallel-analysis-in-python and from the translation of the original function fa.parallel in the psych R package : https://github.com/cran/psych/blob/ee72f0cc2aa7c85a844e3ef63c8629096f22c35d/R/fa.parallel.R

Results have been compared between the original R code and this function and no difference have been observed between the two (see pull request #11, https://github.com/gagnonanthony/NeuroStatX/pull/11)

Parameters

x : Input dataset with only variables to include in the EFA.

method : Method used to fit the model. List of possible methods:

  • minres: Minimal Residual
  • ml: Maximum Likelihood Factor
  • principal: Principal Component

Defaults to “minres”.

rotation : Rotation method to apply to the factor loadings: List of possible rotations:

  • varimax: Orthogonal Rotation
  • promax: Oblique Rotation
  • oblimin: Oblique Rotation
  • oblimax: Orthogonal Rotation
  • quartimin: Oblique Rotation
  • quartimax: Orthogonal Rotation
  • equamax: Orthogonal Rotation

Defaults to None.

nfactors : Number of factors (latent variables) to extract from the data. Defaults to 1.

niter : Number of iterations to perform the parallel analysis. Defaults to 20.

Returns

suggfactors : Suggested number of factors to use in the factorial analysis.

suggcomponents : Suggested number of components to use in the factorial analysis.