Created
August 23, 2018 18:05
-
-
Save Swarchal/6f7c3826efa43d59908f0b0ab10da86b to your computer and use it in GitHub Desktop.
Multivariate Z-prime/factor (Kummel et al, 2010) in python
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 | |
| from sklearn.discriminant_analysis import LinearDiscriminantAnalysis | |
| def z_factor(p, n): | |
| numerator = 3 * (np.std(p) + np.std(n)) | |
| denominator = np.abs(np.mean(p) - np.mean(n)) | |
| return 1 - (numerator / denominator) | |
| def multivariate_z_factor(data, labels): | |
| assert len(set(labels)) == 2, "only allowed 2 types of label" | |
| labels = np.array(labels) | |
| label_1, label_2 = set(labels) | |
| lda = LinearDiscriminantAnalysis(n_components=1) | |
| lda_out = lda.fit_transform(data, labels) | |
| x = lda_out[labels == label_1] | |
| y = lda_out[labels == label_2] | |
| return z_factor(x, y) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment