SciRubyファミリーのStatsampleを使って、相関係数を一発で算出する。
require 'statsample'
a = [1,2,3,4,5,6].to_vector
b = [5,2,nil,4,3,8].to_vector
pearson = Statsample::Bivariate::Pearson.new(a,b)
puts pearson.r
puts pearson.t
puts pearson.probability
puts pearson.summary
0.4608403716896188
0.8993962691856522
0.4347262709638615
Correlation ( - ) : r=0.461 (t:0.899, g.l.=3, p:0.435 / both tails)