#=====> Example 1: apple data <=====#
data(apple)
pest <- unique(apple$pesticide)
icc  <- rep(-1, length(pest))
for(i in 1:length(pest)){
  these  <- apple$pesticide == pest[i]
  r      <- cor(apple$comp[these], apple$ss[these])
  icc[i] <- cor2icc(r, 10,"within")
}
names(icc) <- pest
icc
#=====> Example 2: peach data <=====#
data(peach)
pest <- unique(peach$pesticide)
icc1 <- rep(-1, length(pest))
icc2 <- rep(-1, length(pest))
for(i in 1:length(pest)){
	these  <- peach$pesticide == pest[i]
	r      <- cor(peach$comp[these], peach$ss[these])
	n      <- mean(peach$items[these])
	icc1[i] <- cor2icc(r, n, "not")
	icc2[i] <- cor2icc(r, n, "within")
}
names(icc1) <- pest
names(icc2) <- pest
icc1 # correct
icc2 # incorrect based on data collection procedure
Run the code above in your browser using DataLab