# [R] Help with ICC

Richards, Tom richards at upci.pitt.edu
Wed Nov 28 08:37:41 CET 2001

```Hello, R-folks:

Here is a statement I use to make a data frame:

iccdata <- data.frame(i=rep(1:10,rep(2,10)),j=rep(1:2,10),
x=c(0.35011,0.11989,0.13081,0.09919,0.16000,0.12000,0.00000,0.00000,
0.44023,0.32977,2.67081,2.63919,0.09050,0.03950,0.44019,0.30981,0.59000,
0.57000,4.03000,3.77000))

Then here are the data:

> iccdata
i j       x
1   1 1 0.35011
2   1 2 0.11989
3   2 1 0.13081
4   2 2 0.09919
5   3 1 0.16000
6   3 2 0.12000
7   4 1 0.00000
8   4 2 0.00000
9   5 1 0.44023
10  5 2 0.32977
11  6 1 2.67081
12  6 2 2.63919
13  7 1 0.09050
14  7 2 0.03950
15  8 1 0.44019
16  8 2 0.30981
17  9 1 0.59000
18  9 2 0.57000
19 10 1 4.03000
20 10 2 3.77000

Variable i is for patient, j is for occasion, and x is measured on
each occasion.  These data have the same mean and variance listed on page 9
of Fleiss's book, Design and Analysis of Clinical Experiments, given below:

> lapply(split(iccdata\$x,iccdata\$i),function(x){c(mean(x),var(x))})
\$"1"
[1] 0.23500000 0.02650062

\$"2"
[1] 0.1150000000 0.0004999122

\$"3"
[1] 0.1400 0.0008

\$"4"
[1] 0 0

\$"5"
[1] 0.385000000 0.006100706

\$"6"
[1] 2.6550000000 0.0004999122

\$"7"
[1] 0.0650000 0.0013005

\$"8"
[1] 0.375000000 0.008499472

\$"9"
[1] 0.5800 0.0002

\$"10"
[1] 3.9000 0.0338

Now, how do you use (lme in) R to compute the Intraclass correlation for
these data?  I have written brute-force code to get the "right" answer, but
I cannot get the proper mean squares from any regression model I have tried.
It seems like it should be trivial, but I cannot do it!  I need this to work
in order to apply the technique to a much larger data set.  I could use my
silly code, in SAS, but I want to see and understand the variance
components.  After studying Pinheiro and Bates for a while, I naively tried
the following, which is not what I want.

> ICC <- groupedData(x~j|i,data=iccdata)
> ICC.lme <- lme(x~j,data=ICC)

Can you help me?  Thanks in advance!

Tom
-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
Send "info", "help", or "[un]subscribe"
(in the "body", not the subject !)  To: r-help-request at stat.math.ethz.ch
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._

```