Class: Statsample::Reliability::SkillScaleAnalysis

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

Overview

Analysis of a Skill Scale Given a dataset with results and a correct answers hash, generates a ScaleAnalysis

Usage

x1 = Daru::Vector.new(%{a b b c})
x2 = Daru::Vector.new(%{b a b c})
x3 = Daru::Vector.new(%{a c b a})
ds = Daru::DataFrame.new({:x1 => @x1, :x2 => @x2, :x3 => @x3})
key={ :x1 => 'a',:x2 => 'b', :x3 => 'a'}    
ssa=Statsample::Reliability::SkillScaleAnalysis.new(ds,key)
puts ssa.summary

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Summarizable

#summary

Constructor Details

#initialize(ds, key, opts = Hash.new) ⇒ SkillScaleAnalysis

Returns a new instance of SkillScaleAnalysis.



19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/statsample/reliability/skillscaleanalysis.rb', line 19

def initialize(ds,key,opts=Hash.new)
  opts_default={
    :name=>_("Skill Scale Reliability Analysis (%s)") % ds.name,
    :summary_minimal_item_correlation=>0.10,
    :summary_show_problematic_items=>true
  }
  @ds=ds
  @key=key
  @opts=opts_default.merge(opts)
  @opts.each{|k,v| self.send("#{k}=",v) if self.respond_to? k }
  @cds=nil
end

Instance Attribute Details

#nameObject

Returns the value of attribute name.



16
17
18
# File 'lib/statsample/reliability/skillscaleanalysis.rb', line 16

def name
  @name
end

#summary_minimal_item_correlationObject

Returns the value of attribute summary_minimal_item_correlation.



17
18
19
# File 'lib/statsample/reliability/skillscaleanalysis.rb', line 17

def summary_minimal_item_correlation
  @summary_minimal_item_correlation
end

#summary_show_problematic_itemsObject

Returns the value of attribute summary_show_problematic_items.



18
19
20
# File 'lib/statsample/reliability/skillscaleanalysis.rb', line 18

def summary_show_problematic_items
  @summary_show_problematic_items
end

Instance Method Details

#corrected_datasetObject



59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
# File 'lib/statsample/reliability/skillscaleanalysis.rb', line 59

def corrected_dataset
  if @cds.nil?
    @cds = Daru::DataFrame.new({}, order: @ds.vectors, name: @ds.name)
    @ds.each_row do |row|
      out = {}
      row.each_with_index do |v, k|
        if @key.has_key? k
          if @ds[k].exists? v
            out[k]= @key[k] == v ? 1 : 0
          else
            out[k] = nil
          end
        else
          out[k] = v
        end
      end

      @cds.add_row(Daru::Vector.new(out))
    end
    @cds.update
  end
  @cds
end

#corrected_dataset_minimalObject

Dataset only corrected vectors



32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/statsample/reliability/skillscaleanalysis.rb', line 32

def corrected_dataset_minimal
  cds = corrected_dataset
  dsm = Daru::DataFrame.new(
    @key.keys.inject({}) do |ac,v| 
      ac[v] = cds[v]
      ac
    end
  )
  
  dsm.rename _("Corrected dataset from %s") % @ds.name
  dsm
end

#report_building(builder) ⇒ Object



83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
# File 'lib/statsample/reliability/skillscaleanalysis.rb', line 83

def report_building(builder)
  builder.section(:name=>@name) do |s|
    sa = scale_analysis
    s.parse_element(sa)
    if summary_show_problematic_items
      s.section(:name=>_("Problematic Items")) do |spi|
        count=0
        sa.item_total_correlation.each do |k,v|
          if v < summary_minimal_item_correlation
            count+=1
            spi.section(:name=>_("Item: %s") % @ds[k].name) do |spii|
              spii.text _("Correct answer: %s") % @key[k]
              spii.text _("p: %0.3f") % corrected_dataset[k].mean
              props=@ds[k].proportions.inject({}) {|ac,v| ac[v[0]] = v[1].to_f;ac}
              
              spi.table(:name=>"Proportions",:header=>[_("Value"), _("%")]) do |table|
                props.each do |k1,v|
                  table.row [ @ds[k].index_of(k1), "%0.3f" % v]
                end
              end
            end
          end
        end

        spi.text _("No problematic items") if count==0
      end
    end
  end
end

#scale_analysisObject



53
54
55
56
57
# File 'lib/statsample/reliability/skillscaleanalysis.rb', line 53

def scale_analysis
  sa = ScaleAnalysis.new(corrected_dataset_minimal)
  sa.name=_("%s (Scale Analysis)") % @name
  sa
end

#vector_meanObject



49
50
51
# File 'lib/statsample/reliability/skillscaleanalysis.rb', line 49

def vector_mean
  corrected_dataset_minimal.vector_mean
end

#vector_sumObject



45
46
47
# File 'lib/statsample/reliability/skillscaleanalysis.rb', line 45

def vector_sum
  corrected_dataset_minimal.vector_sum
end