Sha256: 344548c3357794bf29ce6b358359ea214f8b69665c8d686546e292f4b68f3507

Contents?: true

Size: 1.04 KB

Versions: 6

Compression:

Stored size: 1.04 KB

Contents

require(File.dirname(__FILE__)+'/helpers_tests.rb')


class StatsampleMatrixTestCase < MiniTest::Unit::TestCase
  
  
  def test_covariate
    a=Matrix[[1.0, 0.3, 0.2], [0.3, 1.0, 0.5], [0.2, 0.5, 1.0]]
    a.extend Statsample::CovariateMatrix
    a.fields=%w{a b c}
    assert_equal(:correlation, a.type)

    assert_equal(Matrix[[0.5],[0.3]], a.submatrix(%w{c a}, %w{b}))
    assert_equal(Matrix[[1.0, 0.2] , [0.2, 1.0]], a.submatrix(%w{c a}))
    assert_equal(:correlation, a.submatrix(%w{c a}).type)

    a=Matrix[[20,30,10], [30,60,50], [10,50,50]]

    a.extend Statsample::CovariateMatrix

    assert_equal(:covariance, a.type)

    a=50.times.collect {rand()}.to_scale
    b=50.times.collect {rand()}.to_scale
    c=50.times.collect {rand()}.to_scale
    ds={'a'=>a,'b'=>b,'c'=>c}.to_dataset
    corr=Statsample::Bivariate.correlation_matrix(ds)
    real=Statsample::Bivariate.covariance_matrix(ds).correlation
    corr.row_size.times do |i|
      corr.column_size.times do |j|
        assert_in_delta(corr[i,j], real[i,j],1e-15)
      end
    end
  end  
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
statsample-0.17.0 test/test_matrix.rb
statsample-0.16.0 test/test_matrix.rb
statsample-0.15.1 test/test_matrix.rb
statsample-0.15.0 test/test_matrix.rb
statsample-0.14.1 test/test_matrix.rb
statsample-0.14.0 test/test_matrix.rb