module Statsample::Bivariate

Constants

EXTENSION_VERSION

Version of bivariate extension

Public Class Methods

polychoric(v1,v2) click to toggle source

Calculate Polychoric correlation for two vectors.

# File lib/statsample/bivariate/polychoric.rb, line 6
def self.polychoric(v1,v2)
  pc=Polychoric.new_with_vectors(v1,v2)
  pc.r
end
polychoric_correlation_matrix(ds) click to toggle source

Polychoric correlation matrix. Order of rows and columns depends on DataFrame#vectors order

# File lib/statsample/bivariate/polychoric.rb, line 13
def self.polychoric_correlation_matrix(ds)
  cache={}
  matrix=ds.collect_matrix do |row,col|
    if row==col
      1.0
    else
      begin
        if cache[[col,row]].nil?
          poly=polychoric(ds[row],ds[col])
          cache[[row,col]]=poly
          poly
        else
          cache[[col,row]]
        end
      rescue RuntimeError
        nil
      end
    end
  end
  matrix.extend CovariateMatrix
  matrix.fields=ds.vectors.to_a
  matrix
end
tetrachoric(v1,v2) click to toggle source

Calculate Tetrachoric correlation for two vectors.

# File lib/statsample/bivariate/tetrachoric.rb, line 4
def self.tetrachoric(v1,v2)
  tc=Tetrachoric.new_with_vectors(v1,v2)
  tc.r
end
tetrachoric_correlation_matrix(ds) click to toggle source

Tetrachoric correlation matrix. Order of rows and columns depends on DataFrame#vectors order

# File lib/statsample/bivariate/tetrachoric.rb, line 11
def self.tetrachoric_correlation_matrix(ds)
  cache={}
  matrix=ds.collect_matrix do |row,col|
    if row==col
      1.0
    else
      begin
        if cache[[col,row]].nil?
          r=tetrachoric(ds[row],ds[col])
          cache[[row,col]]=r
          r
        else
          cache[[col,row]]
        end
      rescue RuntimeError
        nil
      end
    end
  end
  
  matrix.extend CovariateMatrix
  matrix.fields=ds.vectors.to_a
  matrix
end