Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Factor Analysis using Python Factor_Analyzer

Tags:

python-3.x

I am trying to perform factor analysis by using factor analyzer module by using the below codes:

for bartlett_sphericity

from factor_analyzer.factor_analyzer import calculate_bartlett_sphericity
chi_sqaure_value, p_value = calculate_bartlett_sphericity(fac)
chi_sqaure_value, p_value

for KMO

from factor_analyzer.factor_analyzer import calculate_kmo
kmo_all, kmo_model = calculate_kmo(fac)
kmo_model

after running the above codes, I got (inf,nan) from bartlett_sphericity and nan from KMO. please advise how to fix this issue.

like image 469
Arfeen Zia Avatar asked Jul 18 '26 03:07

Arfeen Zia


1 Answers

I literally just had this issue. It turned out that there were two problems that caused it. The first one was that the correlation matrix had nan's in it. This was because I had several columns that were all zeros, after I removed those, I still had the problem. It turned out that I had two columns that were perfectly correlated, i.e. had a correlation of 1 or -1. After I removed one of these (you don't need to remove BOTH perfectly correlated columns), both of the above worked, and I was trucking along with me FA.

like image 162
Kenney Avatar answered Jul 22 '26 09:07

Kenney



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!