Absolutely! Here’s a Python implementation of the Generalized Concordance Correlation Coefficient (GCCC) for multiple raters, based on the variance components approach described in the literature (e.g., Barnhart et al., 2002).
This implementation assumes your data is in a 2D NumPy array or Pandas DataFrame where rows are subjects and columns are raters.
Python Implementation
import numpy as np
def generalized_ccc(data):
"""
Calculate the Generalized Concordance Correlation Coefficient (GCCC)
for multiple raters.
Parameters:
data (np.ndarray): 2D array (subjects x raters)
Returns:
float: GCCC value
"""
data = np.asarray(data)
n, k = data.shape
# Mean per subject
subject_means = np.mean(data, axis=1, keepdims=True)
# Overall mean
overall_mean = np.mean(data)
# Between-subject variance
sigma_b2 = np.mean((subject_means - overall_mean) ** 2)
# Within-subject variance
sigma_w2 = np.mean((data - subject_means) ** 2)
# GCCC formula (Barnhart et al., 2002)
gccc = sigma_b2 / (sigma_b2 + sigma_w2)
return gccc
# Example usage:
if __name__ == "__main__":
# Example data: 5 subjects, 3 raters
data = np.array([
[1.1, 1.2, 1.0],
[2.3, 2.1, 2.0],
[3.5, 3.6, 3.4],
[4.0, 4.1, 4.2],
[5.2, 5.1, 5.3]
])
print("GCCC:", generalized_ccc(data))
Notes:
- This implementation does not include a bias term (mean difference between raters), which is often negligible if raters are assumed to be unbiased. If you want to include a bias correction, let me know!
- For pairwise CCC (Lin's CCC), you would use a different formula.
- For missing data, you may need to adjust the code to handle NaNs.
References:
- Barnhart HX, Haber MJ, Song J. (2002). "Overall concordance correlation coefficient for evaluating agreement among multiple observers." Biometrics, 58(4):1020-7. Link
If you need a version that handles missing data, or want to include the bias term, just ask!