Sha256: a172a74601f3d9409a69b8a121f044558b8cda9927febfe4818c3a40cecb55d8

Contents?: true

Size: 906 Bytes

Versions: 3

Compression:

Stored size: 906 Bytes

Contents

#!/usr/bin/ruby

# == Description
# 
# Creating and summarizing a correlation matrix with daru and statsample
$:.unshift(File.dirname(__FILE__)+'/../lib/')

require 'statsample'
Statsample::Analysis.store("Statsample::Bivariate.correlation_matrix") do
  # Create a Daru::DataFrame containing 4 vectors a, b, c and d.
  #
  # Notice that the `clone` option has been set to *false*. This tells Daru
  # to not clone the Daru::Vectors being supplied by `rnorm`, since it would
  # be unnecessarily counter productive to clone the vectors once they have
  # been assigned to the dataframe.
  samples=1000
  ds = Daru::DataFrame.new({
    :a => rnorm(samples),
    :b => rnorm(samples),
    :c => rnorm(samples),
    :d => rnorm(samples)
  }, clone: false)

  # Calculate correlation matrix by calling the `cor` shorthand.
  cm = cor(ds)
  summary(cm)
end

if __FILE__==$0
  Statsample::Analysis.run_batch
end

Version data entries

3 entries across 3 versions & 2 rubygems

Version Path
statsample-ekatena-2.0.2.1 examples/correlation_matrix.rb
statsample-ekatena-2.0.2 examples/correlation_matrix.rb
statsample-2.1.0 examples/correlation_matrix.rb