Last active
March 16, 2025 13:20
-
-
Save jailop/cb458a22800c2bce1e55289e9a2836fa to your computer and use it in GitHub Desktop.
Cronbach's Alpha Calculation
This file contains hidden or 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 numpy as np | |
| # Rows are respondents | |
| # Columns are survey items | |
| data = np.array([ | |
| [4.0, 4.0, 4.0, 5.0], | |
| [3.0, 4.0, 3.0, 4.0], | |
| [5.0, 4.0, 5.0, 5.0], | |
| [2.0, 3.0, 2.0, 3.0], | |
| [4.0, 4.0, 4.0, 4.0], | |
| ]) | |
| # ddof means degrees of freedom | |
| var_items = np.var(data, axis=0, ddof=1) | |
| total_scores = np.sum(data, axis=1) | |
| var_total = np.var(total_scores, ddof=1) | |
| n = data.shape[0] | |
| correction_factor = n / (n - 1) | |
| alpha = correction_factor * (1 - np.sum(var_items) / var_total) | |
| print(f"Cronbach's Alpha: {alpha:0.4f}") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment