Method: Statsample::Factor.kmo_univariate

Defined in:
lib/statsample/factor.rb

.kmo_univariate(matrix, var) ⇒ Object

Kaiser-Meyer-Olkin measure of sampling adequacy for one variable.



78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
# File 'lib/statsample/factor.rb', line 78

def self.kmo_univariate(matrix, var)
  if var.is_a? String
    if matrix.respond_to? :fields
      j=matrix.fields.index(var)
      raise "Matrix doesn't have field #{var}" if j.nil?
    else
      raise "Matrix doesn't respond to fields"
    end
  else
    j=var
  end
  
  q=anti_image_correlation_matrix(matrix)
  n=matrix.row_size
  
  sum_r,sum_q=0,0
  
  n.times do |k|
    if j!=k
      sum_r+=matrix[j,k]**2
      sum_q+=q[j,k]**2
    end
  end
  sum_r.quo(sum_r+sum_q)
end