-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfactoranlysis.py
41 lines (27 loc) · 892 Bytes
/
factoranlysis.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# factor analysis
import pandas as pd
import sklearn.datasets
from factor_analyzer import FactorAnalyzer
from factor_analyzer.factor_analyzer import calculate_kmo
import matplotlib.pyplot as plt
import pingouin as pg
df = pd.read_csv('C:/Users/socie/OneDrive/Documents/thesis 1 and 2/thesis 2/data/data qualitative.csv',sep=';', engine='python')
df.drop(['index', 'age', 'sex', 'no. people in houshold','Frame', '6','7','8','9','10','11','12'], axis=1, inplace=True)
df.dropna
kmo_all,kmo_model=calculate_kmo(df)
print(kmo_model)
fa = FactorAnalyzer(n_factors=1, rotation= None)
fa.fit(df)
loadings = fa.loadings_
print(loadings)
ev, v = fa.get_eigenvalues()
xvals = range(1, df.shape[1]+1)
plt.scatter(xvals, ev)
plt.plot(xvals, ev)
plt.title('Scree Plot')
plt.xlabel('factor')
plt.ylabel('Eigenvalue')
plt.grid()
plt.show()
fa.get_communalities()
pg.cronbach_alpha(data=df)