Calculate image intraclass correlation
coefficient (I2C2) of balanced/unbalanced data using the trace method

```
I2C2(y, id, visit, symmetric = FALSE, truncate = FALSE,
twoway = TRUE, demean = TRUE, return_demean = TRUE, ...)
i2c2(...)
```

## Arguments

y |
An n by p data matrix containing n vectorized image data with p voxels.
Each row contains one observed image data at a particular visit for one subject.
Each column contains image values for all subjects and visits at a particular voxel.
The rows are organized by subjects and then visits, EX)
(Y11, Y12, Y21, Y22, ... , YI1 , YI2) |

id |
Vector of IDs, EX) c(1, 1, 2, 2, 3, 3, 4, 4, ... , I, I) |

visit |
Vector of visits, EX) (1, 2, 1, 2, 1, 2, ... , 1, 2) |

symmetric |
if FALSE then the function uses the
method of moments estimator formula;
if TRUE, pairwise symmetric sum formula, default is FALSE |

truncate |
if TRUE, set negative I2C2 to zero |

twoway |
a logical argument indicating whether a oneway or twoway
mean subtraction is more appropriate for the problem. If FALSE, only the overall sample
mean will be removed only; if TRUE, it will also remove visit specific means to
avoid scanner or batch effects |

demean |
if TRUE, include the demean step and
output the demeaned dataset |

return_demean |
return de-meaned matrix. Set to `FALSE` |

... |
not used |

## Value

The output of the function is a list that contains the
following elements.
lambda: estimated I2C2
Kx: the trace of between-cluster variance operator
Ku: the trace of within-cluster variance operator
demean_y: if demean == TRUE, output the demeaned dataset

## References

Shou, H, Eloyan, A, Lee, S, Zipunnikov, V, Crainiceanu, AN, Nebel, NB, Caffo, B, Lindquist, MA, Crainiceanu, CM (2013).
Quantifying the reliability of image replication studies: the image intraclass correlation coefficient (I2C2).
Cogn Affect Behav Neurosci, 13, 4:714-24.

## Author

Haochang Shou, Ani Eloyan, Seonjoo Lee, Vadim Zipunnikov, Adina N. Crainiceanu,
Mary Beth Nebel, Brian Caffo, Martin Lindquist, Ciprian M. Crainiceanu

## Examples

```
id = c(1:10, 10:1)
visit = rep(1:2, each = 10)
visit = as.character(visit)
n = length(id)
p = 100
y = matrix(rnorm(n * p), nrow = n, ncol = p)
res = I2C2(y, id = id, visit = visit)
res$lambda
#> [1] 0.07058552
```