Class: Statsample::Reliability::ItemCharacteristicCurve

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(ds, vector_total = nil) ⇒ ItemCharacteristicCurve

Returns a new instance of ItemCharacteristicCurve

Raises:

  • (ArgumentError)

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

#countsObject (readonly)

Returns the value of attribute counts


108
109
110
# File 'lib/statsample/reliability.rb', line 108

def counts
  @counts
end

#totalsObject (readonly)

Returns the value of attribute totals


108
109
110
# File 'lib/statsample/reliability.rb', line 108

def totals
  @totals
end

#vector_totalObject (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

#processObject


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