EducationalTestingService / factor_analyzer

A Python module to perform exploratory & confirmatory factor analyses.
GNU General Public License v2.0
230 stars 68 forks source link

Only 3 factors appear in factor loading matrix, but "n_factors=5" as input. Likely my error but I cannot find it. #109

Closed andrew-d-moses closed 2 years ago

andrew-d-moses commented 2 years ago

Describe the bug I entered 5 factors in my code, but only 3 are rendering when printing the factor loading matrix. Wondering what my mistake was? sample_data.csv

df = pd.read_csv('C:/Users/AndyMoses/Desktop/ItemAnalysis/src/static_project/sample_data.csv') fa_varimax = FactorAnalyzer(rotation="varimax", method="principal") fa_varimax.fit(df) FactorAnalyzer(n_factors=5, rotation='varimax', method='principal', is_corr_matrix=False, impute='median', use_smc=True) rotate_varimax = favarimax.loadings print(rotate_varimax)

And the output in VS Code (which is the same output when writing to an Excel file via a Django app, so not limited to VSC): Output exceeds the size limit. Open the full output data in a text editor [[ 0.22156706 0.38404786 0.28181195] [ 0.17968448 0.39469408 0.23918164] [ 0.18200352 0.52964041 0.3408932 ] [ 0.30368834 0.44708095 0.46059331] [ 0.39417626 0.40413976 0.21795698] [ 0.32156001 0.41446895 0.26533367] [ 0.29748443 0.19255904 0.24866207] [ 0.3219189 0.24081229 0.38861891] [ 0.25080844 0.19437257 0.61583525] [ 0.40463031 0.22446054 0.60529619] [ 0.12400847 0.65162555 0.40907754] [ 0.12615878 0.83409766 0.19148932] [ 0.1569939 0.85534094 0.08538576] [ 0.20022938 0.8348135 0.05810201] [ 0.6010612 0.32369841 0.14726195] [ 0.40188962 0.40260223 0.33942879] [ 0.22851894 0.10146794 0.24729369] [ 0.36393788 0.27985003 0.1539713 ] [ 0.24452691 0.21911811 0.65568452] [ 0.14787228 0.32477633 0.6983241 ] [ 0.34644957 0.24520421 0.67442527] [ 0.65542534 0.10894993 0.33310308] [ 0.64573726 0.12292077 0.15523874] [ 0.57727558 0.25255066 0.36156582] [ 0.53467353 0.31718859 0.36337659] ... [ 0.23648423 -0.0891555 0.44225961] [ 0.34498065 -0.10889681 0.33314325] [ 0.37169892 -0.12811148 0.1219136 ] [ 0.50090602 0.21714636 0.33453773]]

To Reproduce Steps to reproduce the behavior:

  1. Go to '...'
  2. Click on '....'
  3. Scroll down to '....'
  4. See error

Expected behavior I expected 5 columns.

Screenshots If applicable, add screenshots to help explain your problem.

Desktop (please complete the following information): Lenovo ThinkPad X1, Windows 10 Pro, MS Visual Studio Code version 17.2

Smartphone (please complete the following information): N/A

Additional context Add any other context about the problem here.

jbiggsets commented 2 years ago

Hi @andrew-d-moses, I'm not able to reproduce this error. I think what's going on is you're first fitting the model with the default value for n_factors (which is 3), and assigning that to fa_varimax. Then you create a new FactorAnalyzer instance, which you don't assign to anything.

So, when you retrieve the loadings, you're retrieving the loadings from fa_varimax, which was fit with the default (3) number of factors. Let me know if I can close this issue.