x=c(1,2,3,4) #(n=4)
y=c(10,15,24,36)
sum((x-mean(x))^2)/(4-1) # calculation of variance of x
## [1] 1.666667
var(x) # R code
## [1] 1.666667
sum((y-mean(y))^2)/(4-1) # calculation of variance of y
## [1] 130.25
var(y) # R code
## [1] 130.25
(sum((x-mean(x))*(y-mean(y)))) / (4-1) # calculation of covariance of x and y
## [1] 14.5
cov(x,y)
## [1] 14.5
var(x,y) # R code
## [1] 14.5
cov(x,y) / (sd(x)*sd(y)) # calculation of covariance of x and y
## [1] 0.9841352
cor(x,y) # R code
## [1] 0.9841352
V1=c(2,3,4,5) # Three vectors: 3 variables; 4 subjects (n=4)
V2=c(45,35,24,36)
V3=c(2.1,3.5,6.2,4.3)
matrix=cbind(V1,V2,V3) #3x4 matrix
matrix
## V1 V2 V3
## [1,] 2 45 2.1
## [2,] 3 35 3.5
## [3,] 4 24 6.2
## [4,] 5 36 4.3
cov(matrix) ## # R code for Covariance matrix
## V1 V2 V3
## V1 1.666667 -6.333333 1.550000
## V2 -6.333333 74.000000 -14.300000
## V3 1.550000 -14.300000 2.929167
## Covariance matrix manual
Cv11=sum((V1-mean(V1))^2)/(4-1) ;Cv11
## [1] 1.666667
Cv12=(sum((V1-mean(V1))*(V2-mean(V2)))) / (4-1) ; Cv12
## [1] -6.333333
Cv22=sum((V2-mean(V2))^2)/(4-1) ; Cv22
## [1] 74
Cv23=(sum((V2-mean(V2))*(V3-mean(V3)))) / (4-1) ; Cv23
## [1] -14.3
SEM=sqrt(sd/n)
wCV=SEM/m*100 in which m=sample size
Description
The Intraclass Correlation Coefficient (ICC) is a measure of the reliability of measurements or ratings. = Coefficient of reliability
ICC = var.t/(var.t+var.e)
in which var.t = individual variance (variation explained by the model)
———var.e = residual variance
x1=c(2.3,3.2,5.6,4.5,7.6)
x2=c(2.5,3.5,4.6,5.8,6.6)
k=2
n=length(x1)
meani=(x1+x2)/k #[1] 2.40 3.35 5.10 5.15 7.10
overall.mean <- mean(meani) #[1] 4.62 = mean(c(x1,x2))
#Between sum square (bss) and between mean square (bsm)
bssi=k*(meani-overall.mean)^2 #[1] 9.8568 3.2258 0.4608 0.5618 12.3008
bss=sum(bssi) #between sum square (bss)
bms=bss/(n-1) #between mean square (bsm)
#Within sum square
wssi=(x1-x2)^2/2
wss=sum(wssi) #within sum square (wss)
wms=wss/(k*n-n) #within mean square (wms)
# ICC calculation
var.t=(bms-wms)/k
var.e=wms
ICC=var.t/(var.t+var.e)
ICC
## [1] 0.8905993
#Using ICC package
value=c(x1,x2)
ID=rep(1:5,2)
dat=cbind(ID,value)
dat=as.data.frame(dat)
dat$ID=factor(dat$ID)
library(ICC)
ICCbare(ID,value,dat)
## [1] 0.8905993