Factor analysis using MINRES or ML, with optional rotation using Varimax or Promax. Bases: sklearn.base.BaseEstimator, sklearn.base.TransformerMixin The main exploratory factor analysis class. The type of rotation
to perform after fitting the factor analysis model. If set to None, no rotation will be performed, nor will any associated Kaiser normalization. Possible values include: Defaults
to ‘promax’. The factor loadings matrix. None, if fit()` has not been called. The original correlation matrix. None, if fit() has not been called. The rotation matrix, if a rotation has been performed. None otherwise. The structure loading matrix. This only exists if rotation is ‘promax’ and is None otherwise. The factor correlations matrix. This only exists if rotation is ‘oblique’ and is None otherwise. Notes This code was partly derived from the excellent R package psych. References [1] //github.com/cran/psych/blob/master/R/fa.R Examples >>> import pandas as pd
>>> from factor_analyzer import FactorAnalyzer
>>> df_features = pd.read_csv('tests/data/test02.csv')
>>> fa = FactorAnalyzer(rotation=None)
>>> fa.fit(df_features)
FactorAnalyzer(bounds=(0.005, 1), impute='median', is_corr_matrix=False,
method='minres', n_factors=3, rotation=None, rotation_kwargs={},
use_smc=True)
>>> fa.loadings_
array([[-0.12991218, 0.16398154, 0.73823498],
[ 0.03899558, 0.04658425, 0.01150343],
[ 0.34874135, 0.61452341, -0.07255667],
[ 0.45318006, 0.71926681, -0.07546472],
[ 0.36688794, 0.44377343, -0.01737067],
[ 0.74141382, -0.15008235, 0.29977512],
[ 0.741675 , -0.16123009, -0.20744495],
[ 0.82910167, -0.20519428, 0.04930817],
[ 0.76041819, -0.23768727, -0.1206858 ],
[ 0.81533404, -0.12494695, 0.17639683]])
>>> fa.get_communalities()
array([0.588758 , 0.00382308, 0.50452402, 0.72841183, 0.33184336,
0.66208428, 0.61911036, 0.73194557, 0.64929612, 0.71149718])
Fit factor analysis model using either MINRES, ML, or principal factor analysis. By default, use
SMC as starting guesses. Examples >>> import pandas as pd
>>> from factor_analyzer import FactorAnalyzer
>>> df_features = pd.read_csv('tests/data/test02.csv')
>>> fa = FactorAnalyzer(rotation=None)
>>> fa.fit(df_features)
FactorAnalyzer(bounds=(0.005, 1), impute='median', is_corr_matrix=False,
method='minres', n_factors=3, rotation=None, rotation_kwargs={},
use_smc=True)
>>> fa.loadings_
array([[-0.12991218, 0.16398154, 0.73823498],
[ 0.03899558, 0.04658425, 0.01150343],
[ 0.34874135, 0.61452341, -0.07255667],
[ 0.45318006, 0.71926681, -0.07546472],
[ 0.36688794, 0.44377343, -0.01737067],
[ 0.74141382, -0.15008235, 0.29977512],
[ 0.741675 , -0.16123009, -0.20744495],
[ 0.82910167, -0.20519428, 0.04930817],
[ 0.76041819, -0.23768727, -0.1206858 ],
[ 0.81533404, -0.12494695, 0.17639683]])
Calculate the communalities, given the factor
loading matrix. Examples >>> import pandas as pd
>>> from factor_analyzer import FactorAnalyzer
>>> df_features = pd.read_csv('tests/data/test02.csv')
>>> fa = FactorAnalyzer(rotation=None)
>>> fa.fit(df_features)
FactorAnalyzer(bounds=(0.005, 1), impute='median', is_corr_matrix=False,
method='minres', n_factors=3, rotation=None, rotation_kwargs={},
use_smc=True)
>>> fa.get_communalities()
array([0.588758 , 0.00382308, 0.50452402, 0.72841183, 0.33184336,
0.66208428, 0.61911036, 0.73194557, 0.64929612, 0.71149718])
Calculate the eigenvalues, given the factor
correlation matrix. Examples >>> import pandas as pd
>>> from factor_analyzer import FactorAnalyzer
>>> df_features = pd.read_csv('tests/data/test02.csv')
>>> fa = FactorAnalyzer(rotation=None)
>>> fa.fit(df_features)
FactorAnalyzer(bounds=(0.005, 1), impute='median', is_corr_matrix=False,
method='minres', n_factors=3, rotation=None, rotation_kwargs={},
use_smc=True)
>>> fa.get_eigenvalues()
(array([ 3.51018854, 1.28371018, 0.73739507, 0.1334704 , 0.03445558,
0.0102918 , -0.00740013, -0.03694786, -0.05959139, -0.07428112]),
array([ 3.51018905, 1.2837105 , 0.73739508, 0.13347082, 0.03445601,
0.01029184, -0.0074 , -0.03694834, -0.05959057, -0.07428059]))
Calculate factor variance information. The factor variance information including the variance, proportional variance, and cumulative variance for each factor. Examples >>> import pandas as pd
>>> from factor_analyzer import FactorAnalyzer
>>> df_features = pd.read_csv('tests/data/test02.csv')
>>> fa = FactorAnalyzer(rotation=None)
>>> fa.fit(df_features)
FactorAnalyzer(bounds=(0.005, 1), impute='median', is_corr_matrix=False,
method='minres', n_factors=3, rotation=None, rotation_kwargs={},
use_smc=True)
>>> # 1. Sum of squared loadings (variance)
... # 2. Proportional variance
... # 3. Cumulative variance
>>> fa.get_factor_variance()
(array([3.51018854, 1.28371018, 0.73739507]),
array([0.35101885, 0.12837102, 0.07373951]),
array([0.35101885, 0.47938987, 0.55312938]))
Calculate the uniquenesses, given the factor
loading matrix. Examples >>> import pandas as pd
>>> from factor_analyzer import FactorAnalyzer
>>> df_features = pd.read_csv('tests/data/test02.csv')
>>> fa = FactorAnalyzer(rotation=None)
>>> fa.fit(df_features)
FactorAnalyzer(bounds=(0.005, 1), impute='median', is_corr_matrix=False,
method='minres', n_factors=3, rotation=None, rotation_kwargs={},
use_smc=True)
>>> fa.get_uniquenesses()
array([0.411242 , 0.99617692, 0.49547598, 0.27158817, 0.66815664,
0.33791572, 0.38088964, 0.26805443, 0.35070388, 0.28850282])
Get factor scores for a new data set. Examples >>> import pandas as pd
>>> from factor_analyzer import FactorAnalyzer
>>> df_features = pd.read_csv('tests/data/test02.csv')
>>> fa = FactorAnalyzer(rotation=None)
>>> fa.fit(df_features)
FactorAnalyzer(bounds=(0.005, 1), impute='median', is_corr_matrix=False,
method='minres', n_factors=3, rotation=None, rotation_kwargs={},
use_smc=True)
>>> fa.transform(df_features)
array([[-1.05141425, 0.57687826, 0.1658788 ],
[-1.59940101, 0.89632125, 0.03824552],
[-1.21768164, -1.16319406, 0.57135189],
...,
[ 0.13601554, 0.03601086, 0.28813877],
[ 1.86904519, -0.3532394 , -0.68170573],
[ 0.86133386, 0.18280695, -0.79170903]])
Compute the Bartlett sphericity test. H0: The matrix of population correlations is equal to I. H1: The matrix of population correlations is not equal to I. The formula for Bartlett’s Sphericity test is: \[-1 * (n - 1 - ((2p + 5) / 6)) * ln(det(R))\] Where R det(R) is the determinant of the correlation matrix, and p is the number of variables. Calculate the Kaiser-Meyer-Olkin criterion for items and overall. This statistic represents the degree to which each observed variable is predicted, without error, by the other variables in the dataset. In general, a KMO < 0.6 is considered inadequate.factor_analyzer.factor_analyzer Module¶
class factor_analyzer.factor_analyzer.FactorAnalyzer(n_factors=3, rotation='promax', method='minres', use_smc=True, is_corr_matrix=False, bounds=(0.005, 1), impute='median', svd_method='randomized',
rotation_kwargs=None)[source]¶author: Jeremy Biggs (jeremy.m.biggs@gmail.com)
author: Nitin Madnani (nmadnani@ets.org)
organization: Educational Testing Service
date: 2022-09-05
loadings_¶Parameters:
corr_¶Type: numpy.ndarray
rotation_matrix_¶Type: numpy.ndarray
structure_¶Type: numpy.ndarray
phi_¶Type: numpy.ndarray or None
Type: numpy.ndarray or None
Parameters: Returns: communalities – The communalities from the factor loading matrix.
Return type: numpy.ndarray
Returns: Returns: Returns: uniquenesses – The uniquenesses from the factor loading matrix.
Return type: numpy.ndarray
Parameters: X (array-like, shape (n_samples, n_features)) – The data to score using the fitted factor model.
Returns: X_new – The latent variables of X.
Return type: numpy.ndarray, shape (n_samples, n_components)
factor_analyzer.factor_analyzer.calculate_kmo(x)[source]¶
Parameters: x (array-like) – The array for which to calculate sphericity.
Returns: Parameters: x (array-like) – The array from which to calculate KMOs.
Returns:
factor_analyzer.confirmatory_factor_analyzer Module¶
Confirmatory factor analysis using machine learning methods.
Jeremy Biggs (jeremy.m.biggs@gmail.com) |
Nitin Madnani (nmadnani@ets.org) |
Educational Testing Service |
2022-09-05 |
Bases: sklearn.base.BaseEstimator, sklearn.base.TransformerMixin
Fit a confirmatory factor analysis model using maximum likelihood.
|
ValueError – If is_cov_matrix is True, and n_obs is not provided. |
The model specification object.
ModelSpecification |
The factor loadings matrix. None, if fit()` has not been called.
numpy.ndarray |
The error variance matrix
numpy.ndarray |
The factor covariance matrix.
numpy.ndarray |
The log likelihood from the optimization routine.
float |
The Akaike information criterion.
float |
The Bayesian information criterion.
float |
Examples
>>> import pandas as pd >>> from factor_analyzer import (ConfirmatoryFactorAnalyzer, ... ModelSpecificationParser) >>> X = pd.read_csv('tests/data/test11.csv') >>> model_dict = {"F1": ["V1", "V2", "V3", "V4"], ... "F2": ["V5", "V6", "V7", "V8"]} >>> model_spec = ModelSpecificationParser.parse_model_specification_from_dict(X, model_dict) >>> cfa = ConfirmatoryFactorAnalyzer(model_spec, disp=False) >>> cfa.fit(X.values) >>> cfa.loadings_ array([[0.99131285, 0. ], [0.46074919, 0. ], [0.3502267 , 0. ], [0.58331488, 0. ], [0. , 0.98621042], [0. , 0.73389239], [0. , 0.37602988], [0. , 0.50049507]]) >>> cfa.factor_varcovs_ array([[1. , 0.17385704], [0.17385704, 1. ]]) >>> cfa.get_standard_errors() (array([[0.06779949, 0. ], [0.04369956, 0. ], [0.04153113, 0. ], [0.04766645, 0. ], [0. , 0.06025341], [0. , 0.04913149], [0. , 0.0406604 ], [0. , 0.04351208]]), array([0.11929873, 0.05043616, 0.04645803, 0.05803088, 0.10176889, 0.06607524, 0.04742321, 0.05373646])) >>> cfa.transform(X.values) array([[-0.46852166, -1.08708035], [ 2.59025301, 1.20227783], [-0.47215977, 2.65697245], ..., [-1.5930886 , -0.91804114], [ 0.19430887, 0.88174818], [-0.27863554, -0.7695101 ]])
fit(X, y=None)[source]¶Perform confirmatory factor analysis.
|
|
Examples
>>> import pandas as pd >>> from factor_analyzer import (ConfirmatoryFactorAnalyzer, ... ModelSpecificationParser) >>> X = pd.read_csv('tests/data/test11.csv') >>> model_dict = {"F1": ["V1", "V2", "V3", "V4"], ... "F2": ["V5", "V6", "V7", "V8"]} >>> model_spec = ModelSpecificationParser.parse_model_specification_from_dict(X, model_dict) >>> cfa = ConfirmatoryFactorAnalyzer(model_spec, disp=False) >>> cfa.fit(X.values) >>> cfa.loadings_ array([[0.99131285, 0. ], [0.46074919, 0. ], [0.3502267 , 0. ], [0.58331488, 0. ], [0. , 0.98621042], [0. , 0.73389239], [0. , 0.37602988], [0. , 0.50049507]])
get_model_implied_cov()[source]¶Get the model-implied covariance matrix (sigma) for an estimated model.
model_implied_cov – The model-implied covariance matrix. |
numpy.ndarray |
Examples
>>> import pandas as pd >>> from factor_analyzer import (ConfirmatoryFactorAnalyzer, ... ModelSpecificationParser) >>> X = pd.read_csv('tests/data/test11.csv') >>> model_dict = {"F1": ["V1", "V2", "V3", "V4"], ... "F2": ["V5", "V6", "V7", "V8"]} >>> model_spec = ModelSpecificationParser.parse_model_specification_from_dict(X, model_dict) >>> cfa = ConfirmatoryFactorAnalyzer(model_spec, disp=False) >>> cfa.fit(X.values) >>> cfa.get_model_implied_cov() array([[2.07938612, 0.45674659, 0.34718423, 0.57824753, 0.16997013, 0.12648394, 0.06480751, 0.08625868], [0.45674659, 1.16703337, 0.16136667, 0.26876186, 0.07899988, 0.05878807, 0.03012168, 0.0400919 ], [0.34718423, 0.16136667, 1.07364855, 0.20429245, 0.06004974, 0.04468625, 0.02289622, 0.03047483], [0.57824753, 0.26876186, 0.20429245, 1.28809317, 0.10001495, 0.07442652, 0.03813447, 0.05075691], [0.16997013, 0.07899988, 0.06004974, 0.10001495, 2.0364391 , 0.72377232, 0.37084458, 0.49359346], [0.12648394, 0.05878807, 0.04468625, 0.07442652, 0.72377232, 1.48080077, 0.27596546, 0.36730952], [0.06480751, 0.03012168, 0.02289622, 0.03813447, 0.37084458, 0.27596546, 1.11761918, 0.1882011 ], [0.08625868, 0.0400919 , 0.03047483, 0.05075691, 0.49359346, 0.36730952, 0.1882011 , 1.28888233]])
get_standard_errors()[source]¶Get standard errors from the implied covariance matrix and implied means.
|
Examples
>>> import pandas as pd >>> from factor_analyzer import (ConfirmatoryFactorAnalyzer, ... ModelSpecificationParser) >>> X = pd.read_csv('tests/data/test11.csv') >>> model_dict = {"F1": ["V1", "V2", "V3", "V4"], ... "F2": ["V5", "V6", "V7", "V8"]} >>> model_spec = ModelSpecificationParser.parse_model_specification_from_dict(X, model_dict) >>> cfa = ConfirmatoryFactorAnalyzer(model_spec, disp=False) >>> cfa.fit(X.values) >>> cfa.get_standard_errors() (array([[0.06779949, 0. ], [0.04369956, 0. ], [0.04153113, 0. ], [0.04766645, 0. ], [0. , 0.06025341], [0. , 0.04913149], [0. , 0.0406604 ], [0. , 0.04351208]]), array([0.11929873, 0.05043616, 0.04645803, 0.05803088, 0.10176889, 0.06607524, 0.04742321, 0.05373646]))
transform(X)[source]¶Get the factor scores for a new data set.
X (array-like, shape (n_samples, n_features)) – The data to score using the fitted factor model. |
scores – The latent variables of X. |
numpy array, shape (n_samples, n_components) |
Examples
>>> import pandas as pd >>> from factor_analyzer import (ConfirmatoryFactorAnalyzer, ... ModelSpecificationParser) >>> X = pd.read_csv('tests/data/test11.csv') >>> model_dict = {"F1": ["V1", "V2", "V3", "V4"], ... "F2": ["V5", "V6", "V7", "V8"]} >>> model_spec = ModelSpecificationParser.parse_model_specification_from_dict(X, model_dict) >>> cfa = ConfirmatoryFactorAnalyzer(model_spec, disp=False) >>> cfa.fit(X.values) >>> cfa.transform(X.values) array([[-0.46852166, -1.08708035], [ 2.59025301, 1.20227783], [-0.47215977, 2.65697245], ..., [-1.5930886 , -0.91804114], [ 0.19430887, 0.88174818], [-0.27863554, -0.7695101 ]])
References
//www.ncbi.nlm.nih.gov/pmc/articles/PMC6157408/
class factor_analyzer.confirmatory_factor_analyzer.ModelSpecification(loadings, n_factors, n_variables, factor_names=None, variable_names=None)[source]¶Bases: object
Encapsulate the model specification for CFA.
This class contains a number of specification properties that are used in the CFA procedure.
|
Return a copy of the model specification.
error_vars¶Get the error variance specification.
error_vars_free¶Get the indices of “free” error variance parameters.
factor_covs¶Get the factor covariance specification.
factor_covs_free¶Get the indices of “free” factor covariance parameters.
factor_names¶Get list of factor names, if available.
get_model_specification_as_dict()[source]¶Get the model specification as a dictionary.
model_specification – The model specification keys and values, as a dictionary. |
dict |
Get the factor loadings specification.
loadings_free¶Get the indices of “free” factor loading parameters.
n_factors¶Get the number of factors.
n_lower_diag¶Get the lower diagonal of the factor covariance matrix.
n_variables¶Get the number of variables.
variable_names¶Get list of variable names, if available.
Bases: object
Generate the model specification for CFA.
This class includes two static methods to generate a ModelSpecification object from either a dictionary or a numpy array.
static parse_model_specification_from_array(X, specification=None)[source]¶Generate the model specification from a numpy array.
The columns should correspond to the factors, and the rows should correspond to the variables. If this method is used to create the ModelSpecification object, then no factor names and variable names will be added as properties to that object.
|
A model specification object. |
ModelSpecification |
ValueError – If specification is not in the expected format. |
Examples
>>> import pandas as pd >>> import numpy as np >>> from factor_analyzer import (ConfirmatoryFactorAnalyzer, ... ModelSpecificationParser) >>> X = pd.read_csv('tests/data/test11.csv') >>> model_array = np.array([[1, 1, 1, 1, 0, 0, 0, 0], [0, 0, 0, 0, 1, 1, 1, 1]]) >>> model_spec = ModelSpecificationParser.parse_model_specification_from_array(X, ... model_array)
static parse_model_specification_from_dict(X, specification=None)[source]¶Generate the model specification from a dictionary.
The keys in the dictionary should be the factor names, and the values should be the feature names. If this method is used to create the ModelSpecification object, then factor names and variable names will be added as properties to that object.
|
A model specification object. |
ModelSpecification |
ValueError – If specification is not in the expected format. |
Examples
>>> import pandas as pd >>> from factor_analyzer import (ConfirmatoryFactorAnalyzer, ... ModelSpecificationParser) >>> X = pd.read_csv('tests/data/test11.csv') >>> model_dict = {"F1": ["V1", "V2", "V3", "V4"], ... "F2": ["V5", "V6", "V7", "V8"]} >>> model_spec = ModelSpecificationParser.parse_model_specification_from_dict(X, model_dict)
factor_analyzer.rotator Module¶
Class to perform various rotations of factor loading matrices.
Jeremy Biggs (jeremy.m.biggs@gmail.com) |
Nitin Madnani (nmadnani@ets.org) |
Educational Testing Service |
2022-09-05 |
Bases: sklearn.base.BaseEstimator
Perform rotations on an unrotated factor loading matrix.
The Rotator class takes an (unrotated) factor loading matrix and performs one of several rotations.
|
The loadings matrix.
numpy.ndarray, shape (n_features, n_factors) |
The rotation matrix.
numpy.ndarray, shape (n_factors, n_factors) |
The factor correlations matrix. This only exists if method is ‘oblique’.
numpy.ndarray or None |
Notes
Most of the rotations in this class are ported from R’s GPARotation package.
References
[1] //cran.r-project.org/web/packages/GPArotation/index.html
Examples
>>> import pandas as pd >>> from factor_analyzer import FactorAnalyzer, Rotator >>> df_features = pd.read_csv('test02.csv') >>> fa = FactorAnalyzer(rotation=None) >>> fa.fit(df_features) >>> rotator = Rotator() >>> rotator.fit_transform(fa.loadings_) array([[-0.07693215, 0.04499572, 0.76211208], [ 0.01842035, 0.05757874, 0.01297908], [ 0.06067925, 0.70692662, -0.03311798], [ 0.11314343, 0.84525117, -0.03407129], [ 0.15307233, 0.5553474 , -0.00121802], [ 0.77450832, 0.1474666 , 0.20118338], [ 0.7063001 , 0.17229555, -0.30093981], [ 0.83990851, 0.15058874, -0.06182469], [ 0.76620579, 0.1045194 , -0.22649615], [ 0.81372945, 0.20915845, 0.07479506]])
fit(X, y=None)[source]¶Compute the factor rotation.
|
self |
Example
>>> import pandas as pd >>> from factor_analyzer import FactorAnalyzer, Rotator >>> df_features = pd.read_csv('test02.csv') >>> fa = FactorAnalyzer(rotation=None) >>> fa.fit(df_features) >>> rotator = Rotator() >>> rotator.fit(fa.loadings_)
fit_transform(X, y=None)[source]¶Compute the factor rotation, and return the new loading matrix.
|
loadings_ – The loadings matrix. |
numpy,ndarray, shape (n_features, n_factors) |
ValueError – If method is not in the list of acceptable methods. |
Example
>>> import pandas as pd >>> from factor_analyzer import FactorAnalyzer, Rotator >>> df_features = pd.read_csv('test02.csv') >>> fa = FactorAnalyzer(rotation=None) >>> fa.fit(df_features) >>> rotator = Rotator() >>> rotator.fit_transform(fa.loadings_) array([[-0.07693215, 0.04499572, 0.76211208], [ 0.01842035, 0.05757874, 0.01297908], [ 0.06067925, 0.70692662, -0.03311798], [ 0.11314343, 0.84525117, -0.03407129], [ 0.15307233, 0.5553474 , -0.00121802], [ 0.77450832, 0.1474666 , 0.20118338], [ 0.7063001 , 0.17229555, -0.30093981], [ 0.83990851, 0.15058874, -0.06182469], [ 0.76620579, 0.1045194 , -0.22649615], [ 0.81372945, 0.20915845, 0.07479506]])
factor_analyzer.utils Module¶
Utility functions, used primarily by the confirmatory factor analysis module.
Jeremy Biggs (jeremy.m.biggs@gmail.com) |
Nitin Madnani (nmadnani@ets.org) |
Educational Testing Service |
2022-09-05 |
Apply a function to impute np.nan values with the mean or the median.
|
x – The array, with the missing values imputed. |
numpy.ndarray |
Calculate the commutation matrix.
This matrix transforms the vectorized form of the matrix into the vectorized form of its transpose.
|
commutation_matrix – The commutation matrix |
numpy.ndarray |
References
//en.wikipedia.org/wiki/Commutation_matrix
factor_analyzer.utils.corr(x)[source]¶Calculate the correlation matrix.
x (array-like) – A 1-D or 2-D array containing multiple variables and observations. Each column of x represents a variable, and each row a single observation of all those variables. |
r – The correlation matrix of the variables. |
numpy array |
Calculate the covariance matrix.
|
r – The covariance matrix of the variables. |
numpy array |
Compute cross-correlations from the given covariance matrix.
This is a port of R cov2cor() function.
m (array-like) – The covariance matrix. |
retval – The cross-correlation matrix. |
numpy.ndarray |
ValueError – If the input matrix is not square. |
Calculate the duplication matrix.
A function to create the duplication matrix (Dn), which is the unique n2 × n(n+1)/2 matrix which, for any n × n symmetric matrix A, transforms vech(A) into vec(A), as in Dn vech(A) = vec(A).
n (int, optional) – The dimension of the n x n symmetric matrix. Defaults to 1. |
|
References
//en.wikipedia.org/wiki/Duplication_and_elimination_matrices
factor_analyzer.utils.duplication_matrix_pre_post(x)[source]¶Transform given input symmetric matrix using pre-post duplication.
x (array-like) – The input matrix. |
out – The transformed matrix. |
numpy.ndarray |
AssertionError – If x is not symmetric. |
Fill the lower diagonal of a square matrix, given a 1-D input array.
x (array-like) – The flattened input matrix that will be used to fill the lower diagonal of the square matrix. |
out – The output square matrix, with the lower diagonal filled by x. |
numpy.ndarray |
References
[1] //stackoverflow.com/questions/51439271/convert-1d-array-to-lower-triangular-matrix factor_analyzer.utils.get_first_idxs_from_values(x, eq=1, use_columns=True)[source]¶Get the indexes for a given value.
|
|
Get the free parameter indices from the flattened matrix.
|
idx – The free parameter indexes. |
numpy.ndarray |
Get the indices for the lower triangle of a symmetric matrix.
|
indices – The indices for the lower triangle. |
numpy.ndarray |
Get the indices for the upper triangle of a symmetric matrix.
|
indices – The indices for the upper triangle. |
numpy.ndarray |
Impute np.nan values with the mean or median, or drop the containing rows.
|
x – The array, with the missing values imputed or with rows dropped. |
numpy.ndarray |
Calculate matrix inverse using Cholesky decomposition.
Optionally, calculate the log determinant of the Cholesky.
|
|
Merge variances and covariances into a single variance-covariance matrix.
|
variance_covariance – The variance-covariance matrix. |
numpy.ndarray |
Compute partial correlations between variable pairs.
This is a python port of the pcor() function implemented in the ppcor R package, which computes partial correlations for each pair of variables in the given array, excluding all other variables.
x (array-like) – An array containing the feature values. |
pcor – An array containing the partial correlations of of each pair of variables in the given array, excluding all other variables. |
numpy.ndarray |
Calculate the squared multiple correlations.
This is equivalent to regressing each variable on all others and calculating the r-squared values.
|
smc – The squared multiple correlations matrix. |
numpy.ndarray |
Get first unique instance of every list element, while maintaining order.
seq (list-like) – The list of elements. |
seq – The updated list of elements. |
list |