Class: Daru::Vector

Inherits:
Object show all
Defined in:
lib/statsample/daru.rb

Instance Method Summary collapse

Instance Method Details

#histogram(bins = 10) ⇒ Object



5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/statsample/daru.rb', line 5

def histogram(bins=10)
  type == :numeric or raise TypeError, "Only numeric Vectors can do this operation."

  if bins.is_a? Array
    h = Statsample::Histogram.alloc(bins)
  else
    # ugly patch. The upper limit for a bin has the form
    # x < range
    #h=Statsample::Histogram.new(self, bins)
    valid = reject_values(*Daru::MISSING_VALUES)
    min,max=Statsample::Util.nice(valid.min,valid.max)
    # fix last data
    if max == valid.max
      max += 1e-10
    end
    h = Statsample::Histogram.alloc(bins,[min,max])
    # Fix last bin
  end

  h.increment(valid)
  h
end

#proportion_confidence_interval_t(n_poblation, margin = 0.95, v = 1) ⇒ Object



38
39
40
# File 'lib/statsample/daru.rb', line 38

def proportion_confidence_interval_t(n_poblation,margin=0.95,v=1)
  Statsample::proportion_confidence_interval_t(proportion(v), @valid_data.size, n_poblation, margin)
end

#proportion_confidence_interval_z(n_poblation, margin = 0.95, v = 1) ⇒ Object



42
43
44
# File 'lib/statsample/daru.rb', line 42

def proportion_confidence_interval_z(n_poblation,margin=0.95,v=1)
  Statsample::proportion_confidence_interval_z(proportion(v), @valid_data.size, n_poblation, margin)
end

#variance_proportion(n_poblation, v = 1) ⇒ Object

Variance of p, according to poblation size



29
30
31
# File 'lib/statsample/daru.rb', line 29

def variance_proportion(n_poblation, v=1)
  Statsample::proportion_variance_sample(self.proportion(v), @valid_data.size, n_poblation)
end

#variance_total(n_poblation, v = 1) ⇒ Object

Variance of p, according to poblation size



34
35
36
# File 'lib/statsample/daru.rb', line 34

def variance_total(n_poblation, v=1)
  Statsample::total_variance_sample(self.proportion(v), @valid_data.size, n_poblation)
end