Class: Statsample::Vector

Inherits:
Daru::Vector show all
Includes:
VectorShorthands
Defined in:
lib/statsample/vector.rb

Overview

Collection of values on one dimension. Works as a column on a Spreadsheet.

Usage

The fast way to create a vector uses Array.to_vector or Array.to_numeric.

Deprecation Warning

Statsample::Vector has been deprecated in favour of Daru::Vector. Daru is a dedicated data analysis and manipulation library that brings awesome data analysis functionality to ruby. Check out the daru docs at github.com/v0dro/daru#notebooks

Class Method Summary collapse

Instance Method Summary collapse

Methods included from VectorShorthands

#to_numeric, #to_scale, #to_vector

Methods inherited from Daru::Vector

#histogram, #proportion_confidence_interval_t, #proportion_confidence_interval_z, #variance_proportion, #variance_total

Constructor Details

#initialize(data = [], type = :object, opts = Hash.new) ⇒ Vector

Returns a new instance of Vector.



77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
# File 'lib/statsample/vector.rb', line 77

def initialize(data=[], type=:object, opts=Hash.new)  
  $stderr.puts "WARNING: Statsample::Dataset and Statsample::Vector have been deprecated in favor of Daru::DataFrame and Daru::Vector. Please switch to using that."      

  if type == :ordinal or type == :scale
    $stderr.puts "WARNING: #{type} has been deprecated."
  end

  if type == :nominal
    $stderr.puts "WARNING: nominal has been deprecated."
  end

  if opts[:today_values]
    raise ArgumentError, "This option is no longer supported in Vector. Watch out for the next version of Daru::Vector that will have full time series support"
  end

  if  opts[:name].nil?
    @@n_table||=0
    @@n_table+=1
    opts[:name] = "Vector #{@@n_table}"
  end

  super(data, opts)
end

Class Method Details

.[](*args) ⇒ Object

Create a vector using (almost) any object

  • Array: flattened

  • Range: transformed using to_a

  • Statsample::Vector

  • Numeric and string values

Deprecation Warning

Statsample::Vector is to be replaced by Daru::Vector soon. Use the equivalent method Daru::Vector.[] for this purpose.



111
112
113
114
# File 'lib/statsample/vector.rb', line 111

def self.[](*args)
  $stderr.puts "WARNING: Statsample::Dataset and Statsample::Vector have been deprecated in favor of Daru::DataFrame and Daru::Vector. Please switch to using that."
  super *args
end

.new_numeric(n, val = nil, &block) ⇒ Object

Create a new numeric type vector Parameters

n

Size

val

Value of each value

&block

If block provided, is used to set the values of vector

Deprecation Warning

Statsample::Vector is to be replaced by Daru::Vector soon. Use the equivalent method Daru::Vector.[] for this purpose.



126
127
128
129
130
131
132
# File 'lib/statsample/vector.rb', line 126

def self.new_numeric(n,val=nil, &block)
  if block
    Statsample::Vector.new(n.times.map {|i| block.call(i)})
  else
    Statsample::Vector.new(n.times.map { val })
  end
end

.new_scale(n, val = nil, &block) ⇒ Object

Deprecated. Use new_numeric instead.



135
136
137
# File 'lib/statsample/vector.rb', line 135

def self.new_scale(n, val=nil,&block)
  new_numeric n, val, &block
end

Instance Method Details

#can_be_date?Boolean

Return true if all data is Date, “today” values or nil

Returns:

  • (Boolean)

Raises:

  • (NoMethodError)


140
141
142
# File 'lib/statsample/vector.rb', line 140

def can_be_date?
  raise NoMethodError, "This method is no longer supported."
end

#can_be_numeric?Boolean

Return true if all data is Numeric or nil

Returns:

  • (Boolean)


144
145
146
# File 'lib/statsample/vector.rb', line 144

def can_be_numeric?
  type == :numeric
end

#data_with_nilsObject

Original data.

Deprecation Warning

Use Daru::Vector#to_a instead of this method.



69
70
71
# File 'lib/statsample/vector.rb', line 69

def data_with_nils
  to_a
end

#missing_dataObject

Missing values array

Deprecation Warning

Use Daru::Vector#only_valid instead of this method.



61
62
63
# File 'lib/statsample/vector.rb', line 61

def missing_data
  only_missing.to_a
end

#to_sObject



148
149
150
# File 'lib/statsample/vector.rb', line 148

def to_s
  sprintf("Vector(type:%s, n:%d)[%s]",@type.to_s,@data.size, @data.collect{|d| d.nil? ? "nil":d}.join(","))
end

#type=(val) ⇒ Object

Raises:

  • (NoMethodError)


73
74
75
# File 'lib/statsample/vector.rb', line 73

def type= val
  raise NoMethodError, "Daru::Vector automatically figures the type of data. There is no need to assign it anymore."
end

#valid_dataObject

Valid data. Equal to data, minus values assigned as missing values.

Deprecation Warning

Use Daru::Vector#only_valid instead of this method.



52
53
54
55
# File 'lib/statsample/vector.rb', line 52

def valid_data
  $stderr.puts "WARNING: valid_data in Statsample::Vector has been deprecated in favor of only_valid in Daru::Vector. Please use that.\n"
  only_valid.to_a
end