Internal correlation in a Python module?

I expect to calculate intra-class correlation (ICC) in Python. I could not find an existing module that has this feature. Is there an alternate name, or should I do it myself? I know that this question was asked a year ago on Cross Validated by another user, but there were no answers. I want to compare continuous evaluations between two evaluators.

+10
source share
3 answers

You can find an implementation on ICC or Brain_Data.icc

+5
source

ICC R. Python rpy2. :

from rpy2.robjects import DataFrame, FloatVector, IntVector
from rpy2.robjects.packages import importr
from math import isclose

groups = [1, 1, 1, 1, 2, 2, 2, 2, 3, 3, 3, 3, 4, 4, 4,
          4, 5, 5, 5, 5, 6, 6, 6, 6, 7, 7, 7, 7, 8, 8, 8, 8]
values = [1, 2, 0, 1, 1, 3, 3, 2, 3, 8, 1, 4, 6, 4, 3,
          3, 6, 5, 5, 6, 7, 5, 6, 2, 8, 7, 7, 9, 9, 9, 9, 8]

r_icc = importr("ICC")
df = DataFrame({"groups": IntVector(groups),
                "values": FloatVector(values)})
icc_res = r_icc.ICCbare("groups", "values", data=df)
icc_val = icc_res[0] # icc_val now holds the icc value

# check whether icc value equals reference value
print(isclose(icc_val, 0.728, abs_tol=0.001))
+8

R package psych (ICC), , ICC (1,1), ICC (1, k), ICC (2)., 1), ICC (2, k), ICC (3,1) ICC (3, k), .

,

R ICC rpy2.

:

  1. psych lme4 R:
install.packages("psych")
install.packages("lme4")
  1. ICC Python, rpy2:
import rpy2
from rpy2.robjects import IntVector, pandas2ri
from rpy2.robjects.packages import importr

psych = importr("psych")

values = rpy2.robjects.r.matrix(
    IntVector(
        [9,    2,   5,    8,
        6,    1,   3,    2,
        8,    4,   6,    8,
        7,    1,   2,    6,
        10,   5,   6,    9,
        6,   2,   4,    7]),
    ncol=4, byrow=True
)

icc = psych.ICC(values)

# Convert to Pandas DataFrame
icc_df = pandas2ri.rpy2py(icc[0])

:

                            type    ICC        F           df1   df2    p          lower bound   upper bound  
  Single_raters_absolute    ICC1    0.165783   1.794916    5.0   18.0   0.164720   -0.132910     0.722589     
  Single_random_raters      ICC2    0.289790   11.026650   5.0   15.0   0.000135   0.018791      0.761107     
  Single_fixed_raters       ICC3    0.714829   11.026650   5.0   15.0   0.000135   0.342447      0.945855     
  Average_raters_absolute   ICC1k   0.442871   1.794916    5.0   18.0   0.164720   -0.884193     0.912427     
  Average_random_raters     ICC2k   0.620080   11.026650   5.0   15.0   0.000135   0.071153      0.927240     
  Average_fixed_raters      ICC3k   0.909311   11.026650   5.0   15.0   0.000135   0.675657      0.985891  
0

Source: https://habr.com/ru/post/1662794/


All Articles