Class: Statsample::Reliability::ItemCharacteristicCurve
- Inherits:
-
Object
- Object
- 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
-
#initialize(ds, vector_total = nil) ⇒ ItemCharacteristicCurve
constructor
A new instance of ItemCharacteristicCurve.
- #process ⇒ Object
Constructor Details
#initialize(ds, vector_total = nil) ⇒ ItemCharacteristicCurve
27 28 29 30 31 32 33 34 35 |
# File 'lib/statsample/reliability.rb', line 27 def initialize (ds, vector_total=nil) vector_total||=ds.vector_sum raise "Total size != Dataset size" if vector_total.size!=ds.cases @vector_total=vector_total @ds=ds @totals={} @counts=@ds.fields.inject({}) {|a,v| a[v]={};a} process end |
Instance Attribute Details
#counts ⇒ Object (readonly)
Returns the value of attribute counts.
26 27 28 |
# File 'lib/statsample/reliability.rb', line 26 def counts @counts end |
#totals ⇒ Object (readonly)
Returns the value of attribute totals.
26 27 28 |
# File 'lib/statsample/reliability.rb', line 26 def totals @totals end |
#vector_total ⇒ Object (readonly)
Returns the value of attribute vector_total.
26 27 28 |
# File 'lib/statsample/reliability.rb', line 26 def vector_total @vector_total end |
Instance Method Details
#curve_field(field, item) ⇒ Object
51 52 53 54 55 56 57 58 59 |
# File 'lib/statsample/reliability.rb', line 51 def curve_field(field, item) out={} item=item.to_s @totals.each{|value,n| count_value= @counts[field][value][item].nil? ? 0 : @counts[field][value][item] out[value]=count_value.to_f/n.to_f } out end |
#process ⇒ Object
36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/statsample/reliability.rb', line 36 def process i=0 @ds.each do |row| tot=@vector_total[i] @totals[tot]||=0 @totals[tot]+=1 @ds.fields.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 |