Class: Statsample::Reliability::ItemCharacteristicCurve
- Defined in:
- lib/statsample/reliability.rb
Instance Attribute Summary collapse
-
#counts ⇒ Object
readonly
Returns the value of attribute counts.
-
#totals ⇒ Object
readonly
Returns the value of attribute totals.
-
#vector_total ⇒ Object
readonly
Returns the value of attribute vector_total.
Instance Method Summary collapse
-
#curve_field(field, item) ⇒ Object
Return a hash with p for each different value on a vector.
-
#initialize(ds, vector_total = nil) ⇒ ItemCharacteristicCurve
constructor
A new instance of ItemCharacteristicCurve.
- #process ⇒ Object
Constructor Details
#initialize(ds, vector_total = nil) ⇒ ItemCharacteristicCurve
Returns a new instance of ItemCharacteristicCurve.
109 110 111 112 113 114 115 116 117 |
# File 'lib/statsample/reliability.rb', line 109 def initialize (ds, vector_total=nil) vector_total||=ds.vector_sum raise ArgumentError, "Total size != Dataset size" if vector_total.size != ds.nrows @vector_total=vector_total @ds=ds @totals={} @counts=@ds.vectors.to_a.inject({}) {|a,v| a[v]={};a} process end |
Instance Attribute Details
#counts ⇒ Object (readonly)
Returns the value of attribute counts.
108 109 110 |
# File 'lib/statsample/reliability.rb', line 108 def counts @counts end |
#totals ⇒ Object (readonly)
Returns the value of attribute totals.
108 109 110 |
# File 'lib/statsample/reliability.rb', line 108 def totals @totals end |
#vector_total ⇒ Object (readonly)
Returns the value of attribute vector_total.
108 109 110 |
# File 'lib/statsample/reliability.rb', line 108 def vector_total @vector_total end |
Instance Method Details
#curve_field(field, item) ⇒ Object
Return a hash with p for each different value on a vector
134 135 136 137 138 139 140 141 142 |
# File 'lib/statsample/reliability.rb', line 134 def curve_field(field, item) out={} item=item.to_s @totals.each do |value,n| count_value= @counts[field][value][item].nil? ? 0 : @counts[field][value][item] out[value]=count_value.quo(n) end out end |
#process ⇒ Object
118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 |
# File 'lib/statsample/reliability.rb', line 118 def process i=0 @ds.each_row do |row| tot=@vector_total[i] @totals[tot]||=0 @totals[tot]+=1 @ds.vectors.each do |f| item=row[f].to_s @counts[f][tot]||={} @counts[f][tot][item]||=0 @counts[f][tot][item] += 1 end i+=1 end end |