Last active
November 1, 2023 20:23
-
-
Save StefRe/f02055e4044d267cd856eee54d16134f to your computer and use it in GitHub Desktop.
Testing Coefficients of Variation from multiple samples
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 | |
import scipy | |
def feltz_miller(*samples): | |
k = len(samples) | |
m_j = np.array([len(sample) - 1 for sample in samples]) | |
cv_j = np.array([np.std(sample, ddof=1) / np.mean(sample) for sample in samples]) | |
d = np.sum(m_j * cv_j) / np.sum(m_j) | |
d_ad = np.sum(m_j * (cv_j - d) ** 2) / (d**2 * (0.5 + d**2)) | |
return d_ad, scipy.stats.chi2.sf(d_ad, k - 1) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This is a straightforward translation of Ben Marwick's R code into Python. For details see the
cvequality
vignette.