class Statsample::Reliability::ICC

Intra-class correlation

According to Shrout & Fleiss (1979, p.422): “ICC is the correlation between one measurement (either a single rating or a mean of several ratings) on a target and another measurement obtained on that target”

Usage

require 'statsample'
size=1000
a = size.times.map {rand(10)}.to_scale
b = a.recode{|i|i+rand(4)-2}
c  =a.recode{|i|i+rand(4)-2}
d = a.recode{|i|i+rand(4)-2}
ds={'a'=>a,'b'=>b,'c'=>c,'d'=>d}.to_dataset
# Use :type attribute to set type to summarize
icc=Statsample::Reliability::ICC.new(ds, :type=>:icc_1_k)
puts icc.summary

Reference

Intra-class correlation

According to Shrout & Fleiss (1979, p.422): “ICC is the correlation between one measurement (either a single rating or a mean of several ratings) on a target and another measurement obtained on that target”

Usage

require 'statsample'
size=1000
a = size.times.map {rand(10)}.to_scale
b = a.recode{|i|i+rand(4)-2}
c  =a.recode{|i|i+rand(4)-2}
d = a.recode{|i|i+rand(4)-2}
ds={'a'=>a,'b'=>b,'c'=>c,'d'=>d}.to_dataset
# Use :type attribute to set type to summarize
icc=Statsample::Reliability::ICC.new(ds, :type=>:icc_1_k)
puts icc.summary

Reference

Attributes

bms[R]
df_bj[R]
df_bt[R]

Create a ICC analysis for a given dataset Each vector is a different measurement. Only uses complete data (listwise deletion).

df_residual[R]
df_wt[R]
ems[R]
jms[R]
ms_bj[R]
ms_bt[R]
ms_residual[R]
ms_wt[R]
msc[R]
mse[R]
msr[R]
msw[R]
wms[R]

McGraw and Wong ICC denominations

↑ top

Attributes

alpha[RW]
f[R]
g_rho[RW]
icc_1[R]
icc_a_1[R]
icc_a_k[R]
icc_c_1[R]
icc_c_k[R]
icc_k[R]
k[R]
lbound[R]
n[R]
name[RW]
r[R]

ICC value, set with :type

total_mean[R]
type[R]

Type of analysis, for easy summarization By default, set to :icc_1

  • Shrout & Fleiss(1979) denominations

    • :icc_1_1

    • :icc_2_1

    • :icc_3_1

    • :icc_1_k

    • :icc_2_k

    • :icc_3_k

  • McGraw & Wong (1996) denominations

    • :icc_1

    • :icc_k

    • :icc_c_1

    • :icc_c_k

    • :icc_a_1

    • :icc_a_k

ubound[R]

Public Class Methods

new(ds, opts=Hash.new) click to toggle source
# File lib/statsample/reliability/icc.rb, line 98
def initialize(ds, opts=Hash.new)
  @ds=ds.dup_only_valid
  @vectors=@ds.vectors.values
  @n=@ds.cases
  @k=@ds.fields.size
  compute
  @g_rho=0
  @alpha=0.05
  @icc_name=nil
  opts_default={:name=>"Intra-class correlation", :type=>:icc_1}
  @opts=opts_default.merge(opts)
  @opts.each{|k,v| self.send("#{k}=",v) if self.respond_to? k }
end

Public Instance Methods

compute() click to toggle source
# File lib/statsample/reliability/icc.rb, line 196
def compute
  @df_bt=n-1
  @df_wt=n*(k-1)
  @df_bj=k-1
  @df_residual=(n-1)*(k-1)
  @total_mean=@vectors.inject(0){|ac,v| ac+v.sum}.quo(n*k)
  vm=@ds.vector_mean
  
  @ss_bt=k*vm.ss(@total_mean)
  @ms_bt=@ss_bt.quo(@df_bt)
  
  @ss_bj=n*@vectors.inject(0){|ac,v| ac+(v.mean-@total_mean).square}
  @ms_bj=@ss_bj.quo(@df_bj)
  
  @ss_wt=@vectors.inject(0){|ac,v| ac+(v-vm).ss(0)}
  @ms_wt=@ss_wt.quo(@df_wt)
  
  @ss_residual=@ss_wt-@ss_bj
  @ms_residual=@ss_residual.quo(@df_residual)
  ###
  # Shrout and Fleiss denomination
  ###
  # ICC(1,1) / ICC(1)
  @icc_1_1=(bms-wms).quo(bms+(k-1)*wms) 
  # ICC(2,1) / ICC(A,1)
  @icc_2_1=(bms-ems).quo(bms+(k-1)*ems+k*(jms - ems).quo(n))  
  # ICC(3,1) / ICC(C,1)
  @icc_3_1=(bms-ems).quo(bms+(k-1)*ems) 
  
  
  
  # ICC(1,K) / ICC(K)
  @icc_1_k=(bms-wms).quo(bms) 
  # ICC(2,K) / ICC(A,k)
  @icc_2_k=(bms-ems).quo(bms+(jms-ems).quo(n))
  # ICC(3,K) / ICC(C,k) = Cronbach's alpha
  @icc_3_k=(bms-ems).quo(bms) 
  
  ###
  # McGraw and Wong
  ###
  
end
icc_1_1_ci(alpha=0.05) click to toggle source

Intervale of confidence for ICC (1,1)

# File lib/statsample/reliability/icc.rb, line 312
def icc_1_1_ci(alpha=0.05)
  per=1-(0.5*alpha)
 
  fu=icc_1_f.f*Distribution::F.p_value(per, @df_wt, @df_bt)
  fl=icc_1_f.f.quo(Distribution::F.p_value(per, @df_bt, @df_wt))
  
  [(fl-1).quo(fl+k-1), (fu-1).quo(fu+k-1)]
end
icc_1_f(rho=0.0) click to toggle source
# File lib/statsample/reliability/icc.rb, line 240
def icc_1_f(rho=0.0)
  num=msr*(1-rho)
  den=msw*(1+(k-1)*rho)
  Statsample::Test::F.new(num, den, @df_bt, @df_wt)
end
icc_1_f_shrout() click to toggle source

F test for ICC Case 1. Shrout and Fleiss

# File lib/statsample/reliability/icc.rb, line 307
def icc_1_f_shrout
  Statsample::Test::F.new(bms, wms, @df_bt, @df_wt)
end
icc_1_k_ci(alpha=0.05) click to toggle source

Intervale of confidence for ICC (1,k)

# File lib/statsample/reliability/icc.rb, line 322
def icc_1_k_ci(alpha=0.05)
  per=1-(0.5*alpha)
  fu=icc_1_f.f*Distribution::F.p_value(per, @df_wt, @df_bt)
  fl=icc_1_f.f.quo(Distribution::F.p_value(per, @df_bt, @df_wt))
  [1-1.quo(fl), 1-1.quo(fu)]
end
icc_1_k_f(rho=0) click to toggle source

One way random F, type k

# File lib/statsample/reliability/icc.rb, line 246
def icc_1_k_f(rho=0)
  num=msr*(1-rho)
  den=msw
  Statsample::Test::F.new(num, den, @df_bt, @df_wt)
end
icc_2_1_ci(alpha=0.05) click to toggle source
# File lib/statsample/reliability/icc.rb, line 350
def icc_2_1_ci(alpha=0.05)
  icc_2_1_ci_mcgraw
end
icc_2_1_ci_mcgraw(alpha=0.05) click to toggle source

Confidence interval ICC(A,1), McGawn

# File lib/statsample/reliability/icc.rb, line 356
def icc_2_1_ci_mcgraw(alpha=0.05)
  fd,fu=icc_2_1_fs(icc_2_1,alpha)
  cl=(n*(msr-fd*mse)).quo(fd*(k*msc+(k*n-k-n)*mse)+n*msr)
  cu=(n*(fu*msr-mse)).quo(k*msc+(k*n-k-n)*mse+n*fu*msr)
  [cl,cu]
end
icc_2_1_fs(pp,alpha=0.05) click to toggle source

F* for ICC(2,1) and ICC(2,k)

# File lib/statsample/reliability/icc.rb, line 338
def icc_2_1_fs(pp,alpha=0.05)
  fj=jms.quo(ems)
  per=1-(0.5*alpha)
  vn=(k-1)*(n-1)*((k*pp*fj+n*(1+(k-1)*pp)-k*pp)**2)
  vd=(n-1)*(k**2)*(pp**2)*(fj**2)+((n*(1+(k-1)*pp)-k*pp)**2)
  v=vn.quo(vd)
  f1=Distribution::F.p_value(per, n-1,v)
  f2=Distribution::F.p_value(per, v, n-1)
  [f1,f2]
end
icc_2_f() click to toggle source

F test for ICC Case 2

# File lib/statsample/reliability/icc.rb, line 330
def icc_2_f
  Statsample::Test::F.new(bms, ems, @df_bt, @df_residual)
end
icc_2_k_ci(alpha=0.05) click to toggle source
# File lib/statsample/reliability/icc.rb, line 363
def icc_2_k_ci(alpha=0.05)
  icc_2_k_ci_mcgraw(alpha)
end
icc_2_k_ci_mcgraw(alpha=0.05) click to toggle source
# File lib/statsample/reliability/icc.rb, line 367
def icc_2_k_ci_mcgraw(alpha=0.05)
  f1,f2=icc_2_1_fs(icc_2_k,alpha)
  [
  (n*(msr-f1*mse)).quo(f1*(msc-mse)+n*msr),
  (n*(f2*msr-mse)).quo(msc-mse+n*f2*msr)
  ]
  
end
icc_2_k_ci_shrout(alpha=0.05) click to toggle source
# File lib/statsample/reliability/icc.rb, line 375
def icc_2_k_ci_shrout(alpha=0.05)
  ci=icc_2_1_ci(alpha)
  [(ci[0]*k).quo(1+(k-1)*ci[0]), (ci[1]*k).quo(1+(k-1)*ci[1])]
end
icc_3_1_ci(alpha=0.05) click to toggle source
# File lib/statsample/reliability/icc.rb, line 385
def icc_3_1_ci(alpha=0.05)
  per=1-(0.5*alpha)
  fl=icc_3_f.f.quo(Distribution::F.p_value(per, @df_bt, @df_residual))
  fu=icc_3_f.f*Distribution::F.p_value(per, @df_residual, @df_bt)
  [(fl-1).quo(fl+k-1), (fu-1).quo(fu+k-1)]
end
icc_3_f() click to toggle source
# File lib/statsample/reliability/icc.rb, line 381
def icc_3_f
  Statsample::Test::F.new(bms, ems, @df_bt, @df_residual)
end
icc_3_k_ci(alpha=0.05) click to toggle source
# File lib/statsample/reliability/icc.rb, line 392
def icc_3_k_ci(alpha=0.05)
  per=1-(0.5*alpha)
  fl=icc_3_f.f.quo(Distribution::F.p_value(per, @df_bt, @df_residual))
  fu=icc_3_f.f*Distribution::F.p_value(per, @df_residual, @df_bt)
  [1-1.quo(fl),1-1.quo(fu)]
end
icc_a_1_f(rho=0) click to toggle source
# File lib/statsample/reliability/icc.rb, line 279
def icc_a_1_f(rho=0)
  fj=jms.quo(ems)
  num=msr
  den=a(rho)*msc+b(rho)*mse
  pp = @icc_2_1
  vn=(k-1)*(n-1)*((k*pp*fj+n*(1+(k-1)*pp)-k*pp)**2)
  vd=(n-1)*(k**2)*(pp**2)*(fj**2)+((n*(1+(k-1)*pp)-k*pp)**2)
  v=vn.quo(vd)
  Statsample::Test::F.new(num, den, @df_bt, v)        
end
icc_a_k_f(rho=0) click to toggle source
# File lib/statsample/reliability/icc.rb, line 290
def icc_a_k_f(rho=0)
  num=msr
  den=c(rho)*msc+d(rho)*mse
  
  fj=jms.quo(ems)
  
  pp = @icc_2_k
  vn=(k-1)*(n-1)*((k*pp*fj+n*(1+(k-1)*pp)-k*pp)**2)
  vd=(n-1)*(k**2)*(pp**2)*(fj**2)+((n*(1+(k-1)*pp)-k*pp)**2)
  v=vn.quo(vd)
  
  
  Statsample::Test::F.new(num, den, @df_bt,v)        

end
icc_c_1_f(rho=0) click to toggle source
# File lib/statsample/reliability/icc.rb, line 252
def icc_c_1_f(rho=0)
  num=msr*(1-rho)
  den=mse*(1+(k-1)*rho)
  Statsample::Test::F.new(num, den, @df_bt, @df_residual)
end
icc_c_k_ci(alpha=0.05) click to toggle source
# File lib/statsample/reliability/icc.rb, line 399
def icc_c_k_ci(alpha=0.05)
  per=1-(0.5*alpha)
  fl=icc_c_k_f.f.quo(Distribution::F.p_value(per, @df_bt, @df_residual))
  fu=icc_c_k_f.f*Distribution::F.p_value(per, @df_residual, @df_bt)
  [1-1.quo(fl),1-1.quo(fu)]
end
icc_c_k_f(rho=0) click to toggle source
# File lib/statsample/reliability/icc.rb, line 257
def icc_c_k_f(rho=0)
  num=(1-rho)
  den=1-@icc_3_k
  Statsample::Test::F.new(num, den, @df_bt, @df_residual)
end
report_building(b) click to toggle source
# File lib/statsample/reliability/icc.rb, line 405
def report_building(b)
   b.section(:name=>name) do |s|
     s.text @icc_name
     s.text _("ICC: %0.4f") % @r
     s.parse_element(@f)
     s.text _("CI (%0.2f): [%0.4f - %0.4f]") % [(1-@alpha)*100, @lbound, @ubound]
   end
end
type=(v) click to toggle source
# File lib/statsample/reliability/icc.rb, line 111
def type=(v)
  case v
    when :icc_1_1
      @icc_name=_("Shrout & Fleiss ICC(1,1)")
      @r=@icc_1_1
      @f=icc_1_f
      @lbound, @ubound=icc_1_1_ci(@alpha)            
    when :icc_2_1
      @icc_name=_("Shrout & Fleiss ICC(2,1)")
      @r=@icc_2_1
      @f=icc_2_f
      @lbound, @ubound=icc_2_1_ci(@alpha)            
      
    when :icc_3_1
      @icc_name=_("Shrout & Fleiss ICC(3,1)")
      
      @r=@icc_3_1
      @f=icc_3_f
      @lbound, @ubound=icc_3_1_ci(@alpha)            

    when :icc_1_k
      @icc_name=_("Shrout & Fleiss ICC(1,k)")
      
      @r=@icc_1_k
      @f=icc_1_k_f
      @lbound, @ubound=icc_1_k_ci(@alpha)            
    when :icc_2_k
      @icc_name=_("Shrout & Fleiss ICC(2,k)")
      
      @r=@icc_2_k
      @f=icc_2_k_f
      @lbound, @ubound=icc_2_k_ci(@alpha)            
      
    when :icc_3_k
      @icc_name=_("Shrout & Fleiss ICC(3,k)")
      
      @r=@icc_3_k
      @f=icc_3_k_f
      @lbound, @ubound=icc_3_k_ci(@alpha)            
      
      
    when :icc_1
      @icc_name=_("McGraw & Wong ICC(1)")
      
      @r=@icc_1_1
      @f=icc_1_f(@g_rho)
      @lbound, @ubound=icc_1_1_ci(@alpha)
    when :icc_k
      @icc_name=_("McGraw & Wong ICC(K)")
      
      @r=@icc_1_k
      @f=icc_1_k_f(@g_rho)
      @lbound, @ubound=icc_1_k_ci(@alpha)
    when :icc_c_1
      @icc_name=_("McGraw & Wong ICC(C,1)")
      
      @r=@icc_3_1
      @f=icc_c_1_f(@g_rho)
      @lbound, @ubound=icc_3_1_ci(@alpha)

    when :icc_c_k
      @icc_name=_("McGraw & Wong ICC(C,K)")
      
      @r=@icc_3_k
      @f=icc_c_k_f(@g_rho)
      @lbound, @ubound=icc_c_k_ci(@alpha)

    when :icc_a_1
      @icc_name=_("McGraw & Wong ICC(A,1)")
      
      @r=@icc_2_1
      @f=icc_a_1_f(@g_rho)
      @lbound,@ubound = icc_2_1_ci(@alpha)

    when :icc_a_k
      @icc_name=_("McGraw & Wong ICC(A,K)")
      
      @r=@icc_2_k
      @f=icc_a_k_f(@g_rho)
      @lbound,@ubound=icc_2_k_ci(@alpha)

    else
      raise "Type #{v} doesn't exists" 
  end
end

Shrout and Fleiss ICC denominations

↑ top

Attributes

icc_1_1[R]
icc_1_k[R]
icc_2_1[R]
icc_2_k[R]
icc_3_1[R]
icc_3_k[R]