class Statsample::Bivariate::Pearson

Pearson correlation coefficient ®

The moment-product Pearson's correlation coefficient, known as 'r' is a measure of bivariate associate between two continous variables.

Usage

a = [1,2,3,4,5,6].to_scale
b = [2,3,4,5,6,7].to_scale
pearson = Statsample::Bivariate::Pearson.new(a,b)
puts pearson.r
puts pearson.t
puts pearson.probability
puts pearson.summary

Pearson correlation coefficient ®

The moment-product Pearson's correlation coefficient, known as 'r' is a measure of bivariate associate between two continous variables.

Usage

a = [1,2,3,4,5,6].to_scale
b = [2,3,4,5,6,7].to_scale
pearson = Statsample::Bivariate::Pearson.new(a,b)
puts pearson.r
puts pearson.t
puts pearson.probability
puts pearson.summary

Attributes

n[RW]
name[RW]

Name of correlation

tails[RW]

Tails for probability (:both, :left or :right)

Public Class Methods

new(v1,v2,opts=Hash.new) click to toggle source
# File lib/statsample/bivariate/pearson.rb, line 27
def initialize(v1,v2,opts=Hash.new)
  @v1_name,@v2_name = v1.name,v2.name
  @v1,@v2           = Statsample.only_valid_clone(v1,v2)
  @n=@v1.size
  opts_default={
    :name=>_("Correlation (%s - %s)") % [@v1_name, @v2_name],
    :tails=>:both
  }
  @opts=opts.merge(opts_default)
  @opts.each{|k,v|
    self.send("#{k}=",v) if self.respond_to? k
  }
end

Public Instance Methods

probability() click to toggle source
# File lib/statsample/bivariate/pearson.rb, line 46
def probability
  p_using_cdf(Distribution::T.cdf(t, @v1.size-2), tails)
end
r() click to toggle source
# File lib/statsample/bivariate/pearson.rb, line 40
def r
  Statsample::Bivariate.pearson(@v1,@v2)
end
report_building(builder) click to toggle source
# File lib/statsample/bivariate/pearson.rb, line 49
def report_building(builder)
  builder.text(_("%s : r=%0.3f (t:%0.3f, g.l.=%d, p:%0.3f / %s tails)") % [@name, r,t, (n-2), probability, tails])
end
t() click to toggle source
# File lib/statsample/bivariate/pearson.rb, line 43
def t
  Statsample::Bivariate.t_pearson(@v1,@v2)
end