Compute intraclass correlation

Requirements

You need the free software R : go to R download page

Your data file need to be in a dyadic structure : go to this page to see how restructure your table in python.

Code

Read .CSV file

In [1]:
data <- read.csv("input.csv", sep = ";")

Create new column with mean scores of the two participants

In [2]:
data$mean <- (data$p1+data$p2)/2

Create new column with distances between the two participants

In [3]:
data$distance <- data$p1-data$p2
In [4]:
data
Dyadp1p2meandistance
1 8 6 7.0 2
2 5 3 4.0 2
3 7 2 4.5 5
4 8 5 6.5 3
5 8 7 7.5 1
6 5 6 5.5-1
7 3 4 3.5-1
8 8 9 8.5-1
9 6 7 6.5-1
10 2 3 2.5-1

Compute mean of all 2n scores

In [5]:
M <- mean(c(data$p1,data$p2))

Compute (mean - M)² for each dyad

In [6]:
data$"(mean-M)²" <- (data$mean - M)^2
In [7]:
data
Dyadp1p2meandistance(mean-M)²
1 8 6 7.0 2 1.96
2 5 3 4.0 2 2.56
3 7 2 4.5 5 1.21
4 8 5 6.5 3 0.81
5 8 7 7.5 1 3.61
6 5 6 5.5 -1 0.01
7 3 4 3.5 -1 4.41
8 8 9 8.5 -1 8.41
9 6 7 6.5 -1 0.81
10 2 3 2.5 -1 9.61

Compute distance² for each dyad

In [8]:
data$"distance²" <- (data$distance)^2
In [9]:
data
Dyadp1p2meandistance(mean-M)²distance²
1 8 6 7.0 2 1.96 4
2 5 3 4.0 2 2.56 4
3 7 2 4.5 5 1.2125
4 8 5 6.5 3 0.81 9
5 8 7 7.5 1 3.61 1
6 5 6 5.5 -1 0.01 1
7 3 4 3.5 -1 4.41 1
8 8 9 8.5 -1 8.41 1
9 6 7 6.5 -1 0.81 1
10 2 3 2.5 -1 9.61 1

Compute sum of (mean - M)²

In [10]:
SumMeanSquare2 <- sum(data$"(mean-M)²")
In [11]:
SumMeanSquare2
33.4

Compute sum of distance²

In [12]:
SumDistance2 <- sum(data$"distance²")
In [13]:
SumDistance2
48

Compute mean square between dyads (MSb)

In [14]:
MSb <- (2*SumMeanSquare2) / (length(data$Dyad)-1)
In [15]:
MSb
7.42222222222222

Compute mean square within dyads (MSw)

In [16]:
MSw <- SumDistance2 / (2*length(data$Dyad))
In [17]:
MSw
2.4

Compute intraclass correlation (ICC)

In [18]:
ICC <- (MSb - MSw) / (MSb + MSw)
In [19]:
ICC
0.51131221719457

Compute F value

In [20]:
F <- MSb / MSw
In [21]:
F
3.09259259259259

Compute p value

In [22]:
pf(q=F, df1=length(data$Dyad)-1, df2=length(data$Dyad), lower.tail=TRUE)
0.953370086082719

if p-value <.05, scores are non-independant