Skip to content

Commit 13a3232

Browse files
author
jbiggsets
committed
Merge branch 'master' into bugfix/fix-scores
2 parents 0c74e5c + 7c3e3cd commit 13a3232

File tree

58 files changed

+5145
-647
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

58 files changed

+5145
-647
lines changed

.circleci/config.yml

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,7 @@ jobs:
1212
- checkout
1313
- restore_cache:
1414
keys:
15-
- v1-dependencies-{{ checksum "conda_requirements.txt" }}
16-
- v1-dependencies-
15+
- deps
1716

1817
- run: rm -rf ~/repo/artifacts
1918
- run: mkdir ~/repo/artifacts
@@ -28,13 +27,14 @@ jobs:
2827
2928
- save_cache:
3029
paths:
31-
- ~/repo
32-
key: v1-dependencies-{{ checksum "conda_requirements.txt" }}
30+
- "~/miniconda3/pkgs"
31+
key: deps
3332

3433
# install factor analyzer
3534
- run:
3635
name: Install factor analyzer
37-
command: ~/miniconda3/bin/pip install -e .
36+
command: |
37+
~/miniconda3/bin/pip install -e .
3838
3939
# run all of the tests
4040
- run:

README.rst

Lines changed: 94 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -29,22 +29,26 @@ Exploratory factor analysis (EFA) is a statistical technique used to
2929
identify latent relationships among sets of observed variables in a
3030
dataset. In particular, EFA seeks to model a large set of observed
3131
variables as linear combinations of some smaller set of unobserved,
32-
latent factors.
32+
latent factors. The matrix of weights, or factor loadings, generated
33+
from an EFA model describes the underlying relationships between each
34+
variable and the latent factors.
3335

34-
The matrix of weights, or factor loadings, generated from an EFA model
35-
describes the underlying relationships between each variable and the
36-
latent factors. Typically, a number of factors (K) is selected such that
37-
it is substantially smaller than the number of variables. The factor
38-
analysis model can be estimated using a variety of standard estimation
39-
methods, including but not limited to OLS, minres, or MLE.
36+
Confirmatory factor analysis (CFA), a closely associated technique, is
37+
used to test an a priori hypothesis about latent relationships among sets
38+
of observed variables. In CFA, the researcher specifies the expected pattern
39+
of factor loadings, and other possible constraints on the model.
40+
41+
Typically, a number of factors (K) in an EFA or CFA model is selected
42+
such that it is substantially smaller than the number of variables. The
43+
factor analysis model can be estimated using a variety of standard
44+
estimation methods, including but not limited to OLS, minres, or MLE.
4045

4146
Factor loadings are similar to standardized regression coefficients, and
4247
variables with higher loadings on a particular factor can be interpreted
43-
as explaining a larger proportion of the variation in that factor. In
44-
many cases, factor loading matrices are rotated after the factor
45-
analysis model is estimated in order to produce a simpler, more
46-
interpretable structure to identify which variables are loading on a
47-
particular factor.
48+
as explaining a larger proportion of the variation in that factor. In the
49+
case of EFA, factor loading matrices are usually rotated after the factor
50+
analysis model is estimated in order to produce a simpler, more interpretable
51+
structure to identify which variables are loading on a particular factor.
4852

4953
Two common types of rotations are:
5054

@@ -56,11 +60,12 @@ Two common types of rotations are:
5660
upon the varimax rotation, but ultimately allows factors to become
5761
correlated.
5862

59-
This package includes a stand-alone Python module with a ``FactorAnalyzer``
60-
class. The class includes an ``analyze()`` method that allows users to perform
61-
factor analysis using either minres or MLE, with optional rotations on the factor
62-
loading matrices. The package also offers a stand-alone ``Rotator`` class to
63-
perform common rotations on an unrotated loading matrix.
63+
This package includes a ``factor_analyzer`` module with a stand-alone
64+
``FactorAnalyzer``class. The class includes an ``analyze()`` method that
65+
allows users to perform factor analysis using either minres or MLE, with
66+
optional rotations on the factor loading matrices. The package also offers
67+
a stand-alone ``Rotator`` class to perform common rotations on an unrotated
68+
loading matrix.
6469

6570
The following rotations options are available in both ``FactorAnalyzer``
6671
and ``Rotator``:
@@ -73,8 +78,17 @@ and ``Rotator``:
7378
(f) quartimax (orthogonal rotation)
7479
(g) equamax (orthogonal rotation)
7580

76-
Example
77-
-------
81+
In adddition, the package includes a ``confirmatory_factor_analyzer``
82+
module with a stand-alone ``ConfirmatoryFactorAnalyzer`` class. The
83+
class includes an ``analyze()`` method that allows users to perform
84+
confirmatory factor analysis using MLE. Performing CFA requires users
85+
to specify a model with the expected factor loading relationships and
86+
other constraints.
87+
88+
Examples
89+
--------
90+
91+
Exploratory factor analysis example.
7892

7993
.. code:: python
8094
@@ -123,6 +137,67 @@ Example
123137
Proportion Var 0.351019 0.128371 0.073739
124138
Cumulative Var 0.351019 0.479390 0.553129
125139
140+
Confirmatory factor analysis example.
141+
142+
.. code:: python
143+
144+
In [1]: import pandas as pd
145+
146+
In [2]: from factor_analyzer import ConfirmatoryFactorAnalyzer
147+
148+
In [3]: data = pd.read_csv('tests/data/test12.csv')
149+
150+
In [4]: model = {'loadings': {"Verbal": ["english", "vocab", "socsci"],
151+
...: "Quant": ["socsci", "math", "natsci"]}}
152+
153+
In [6]: cfa.analyze(data, model, fix_first=False)
154+
155+
In [5]: cfa = ConfirmatoryFactorAnalyzer()
156+
157+
In [7]: cfa.loadings
158+
Out[7]:
159+
Verbal Quant
160+
english 3.532436 0.000000
161+
vocab 4.221969 0.000000
162+
socsci 3.281362 1.099739
163+
math 0.000000 4.888016
164+
natsci 0.000000 4.850257
165+
166+
In [8]: cfa.factor_covs
167+
Out[8]:
168+
Verbal Quant
169+
Verbal 1.000000 0.833013
170+
Quant 0.833013 1.000000
171+
172+
In [9]: cfa.error_vars
173+
Out[9]:
174+
evars
175+
english 9.249541
176+
vocab 5.044325
177+
socsci 5.782677
178+
math 15.519003
179+
natsci 9.406164
180+
181+
In [10]: loadings_se, error_vars_se = cfa.get_standard_errors()
182+
183+
In [11]: loadings_se
184+
Out[11]:
185+
Verbal Quant
186+
english 0.100785 0.000000
187+
vocab 0.098195 0.000000
188+
socsci 0.217784 0.216251
189+
math 0.000000 0.138298
190+
natsci 0.000000 0.123820
191+
192+
In [12]: error_vars_se
193+
Out[12]:
194+
error_vars
195+
english 0.385040
196+
vocab 0.353237
197+
socsci 0.307728
198+
math 0.742082
199+
natsci 0.600859
200+
126201
Requirements
127202
------------
128203

conda-recipe/factor_analyzer/meta.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{% set name = "factor_analyzer" %}
2-
{% set version = "0.2.3" %}
2+
{% set version = "0.3.0" %}
33
{% set file_ext = "tar.gz" %}
44
{% set hash_type = "sha256" %}
55
{% set hash_value = "94ea4c7d46e846cc7174787adce47156cf58dc257905c878edc5181b4fa300ed" %}

conda_requirements.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
python>=3.4
22
pandas
33
scipy
4+
numpy
45
nose=1.3.7

factor_analyzer/__init__.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,3 +9,14 @@
99
from .factor_analyzer import (FactorAnalyzer,
1010
calculate_bartlett_sphericity,
1111
calculate_kmo)
12+
13+
from .confirmatory_factor_analyzer import (ConfirmatoryFactorAnalyzer,
14+
ModelParser)
15+
16+
from .utils import (fill_lower_diag,
17+
merge_variance_covariance,
18+
duplication_matrix,
19+
duplication_matrix_pre_post,
20+
commutation_matrix,
21+
get_symmetric_lower_idxs,
22+
get_symmetric_upper_idxs)

factor_analyzer/analyze.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
Factor analysis command line script.
33
44
:author: Jeremy Biggs ([email protected])
5-
65
:date: 12/13/2017
76
:organization: ETS
87
"""

0 commit comments

Comments
 (0)