Last active
December 5, 2017 01:50
-
-
Save trycycle/731c34d8919eca27bdc4e97fc02df500 to your computer and use it in GitHub Desktop.
Cronbach alpha信頼性係数
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import pandas as pd | |
def cronbach_alpha(dataframe, columns): | |
''' dataframe: pandas dataframe | |
columns: list of the dataframe column names | |
''' | |
var_sum = 0 | |
tmp_df = pd.DataFrame(index=dataframe.index, columns=['total']) | |
tmp_df = tmp_df.fillna(0) | |
for col in columns: | |
var_sum += dataframe[col].var(ddof=False) | |
tmp_df['total'] += dataframe[col] | |
total_var = tmp_df['total'].var(ddof=False) | |
alpha = (len(columns) / (len(columns) - 1)) * (1 - (var_sum / total_var)) | |
return alpha |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment