Class: Statsample::Reliability::ItemAnalysis
- Inherits:
-
Object
- Object
- Statsample::Reliability::ItemAnalysis
- Defined in:
- lib/statsample/reliability.rb
Instance Attribute Summary collapse
-
#alpha ⇒ Object
readonly
Returns the value of attribute alpha.
-
#alpha_standarized ⇒ Object
readonly
Returns the value of attribute alpha_standarized.
-
#mean ⇒ Object
readonly
Returns the value of attribute mean.
-
#sd ⇒ Object
readonly
Returns the value of attribute sd.
-
#valid_n ⇒ Object
readonly
Returns the value of attribute valid_n.
Instance Method Summary collapse
- #gnuplot_item_characteristic_curve(directory, base = "crd", options = {}) ⇒ Object
- #html_summary ⇒ Object
-
#initialize(ds) ⇒ ItemAnalysis
constructor
A new instance of ItemAnalysis.
-
#item_characteristic_curve ⇒ Object
Returns a hash with structure.
-
#item_difficulty_analysis ⇒ Object
Returns a dataset with cases ordered by score and variables ordered by difficulty.
- #item_statistics ⇒ Object
- #item_total_correlation ⇒ Object
- #stats_if_deleted ⇒ Object
- #svggraph_item_characteristic_curve(directory, base = "icc", options = {}) ⇒ Object
Constructor Details
#initialize(ds) ⇒ ItemAnalysis
63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 |
# File 'lib/statsample/reliability.rb', line 63 def initialize(ds) @ds=ds.dup_only_valid @total=@ds.vector_sum @item_mean=@ds.vector_mean.mean @mean=@total.mean @median=@total.median @skew=@total.skew @kurtosis=@total.kurtosis @sd = @total.sd @valid_n = @total.size begin @alpha = Statsample::Reliability.cronbach_alpha(ds) @alpha_standarized = Statsample::Reliability.cronbach_alpha_standarized(ds) rescue => e raise DatasetException.new(@ds,e), "Problem on calculate alpha" end end |
Instance Attribute Details
#alpha ⇒ Object (readonly)
Returns the value of attribute alpha.
62 63 64 |
# File 'lib/statsample/reliability.rb', line 62 def alpha @alpha end |
#alpha_standarized ⇒ Object (readonly)
Returns the value of attribute alpha_standarized.
62 63 64 |
# File 'lib/statsample/reliability.rb', line 62 def alpha_standarized @alpha_standarized end |
#mean ⇒ Object (readonly)
Returns the value of attribute mean.
62 63 64 |
# File 'lib/statsample/reliability.rb', line 62 def mean @mean end |
#sd ⇒ Object (readonly)
Returns the value of attribute sd.
62 63 64 |
# File 'lib/statsample/reliability.rb', line 62 def sd @sd end |
#valid_n ⇒ Object (readonly)
Returns the value of attribute valid_n.
62 63 64 |
# File 'lib/statsample/reliability.rb', line 62 def valid_n @valid_n end |
Instance Method Details
#gnuplot_item_characteristic_curve(directory, base = "crd", options = {}) ⇒ Object
104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 |
# File 'lib/statsample/reliability.rb', line 104 def gnuplot_item_characteristic_curve(directory, base="crd",={}) require 'gnuplot' crd=item_characteristic_curve @ds.fields.each do |f| x=[] y=[] Gnuplot.open do |gp| Gnuplot::Plot.new( gp ) do |plot| crd[f].sort.each do |tot,prop| x.push(tot) y.push((prop*100).to_i.to_f/100) end plot.data << Gnuplot::DataSet.new( [x, y] ) do |ds| ds.with = "linespoints" ds.notitle end end end end end |
#html_summary ⇒ Object
204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 |
# File 'lib/statsample/reliability.rb', line 204 def html_summary html = "<p><strong>Summary for scale:</strong></p>\n<ul>\n<li>Items=\#{@ds.fields.size}</li>\n<li>Total Mean=\#{@mean}</li>\n<li>Item Mean=\#{@item_mean}</li>\n<li>Std.Dv.=\#{@sd}</li>\n<li>Median=\#{@median}</li>\n<li>Skewness=\#{sprintf(\"%0.3f\",@skew)}</li>\n<li>Kurtosis=\#{sprintf(\"%0.3f\",@kurtosis)}</li>\n\n<li>Valid n:\#{@valid_n}</li>\n<li>Cronbach alpha: \#{@alpha}</li>\n</ul>\n<table><thead><th>Variable</th>\n\n<th>Mean</th>\n<th>StDv.</th>\n<th>Mean if deleted</th><th>Var. if\ndeleted</th><th> StDv. if\ndeleted</th><th> Itm-Totl\nCorrel.</th><th>Alpha if\ndeleted</th></thead>\n" itc=item_total_correlation sid=stats_if_deleted is=item_statistics @ds.fields.each {|f| html << " <tr>\n <td>\#{f}</td>\n <td>\#{sprintf(\"%0.5f\",is[f][:mean])}</td>\n <td>\#{sprintf(\"%0.5f\",is[f][:sds])}</td>\n <td>\#{sprintf(\"%0.5f\",sid[f][:mean])}</td>\n <td>\#{sprintf(\"%0.5f\",sid[f][:variance_sample])}</td>\n <td>\#{sprintf(\"%0.5f\",sid[f][:sds])}</td>\n <td>\#{sprintf(\"%0.5f\",itc[f])}</td>\n <td>\#{sprintf(\"%0.5f\",sid[f][:alpha])}</td>\n </tr>\n" } html << "</table><hr />" html end |
#item_characteristic_curve ⇒ Object
Returns a hash with structure
81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 |
# File 'lib/statsample/reliability.rb', line 81 def item_characteristic_curve i=0 out={} total={} @ds.each do |row| tot=@total[i] @ds.fields.each do |f| out[f]||= {} total[f]||={} out[f][tot]||= 0 total[f][tot]||=0 out[f][tot]+= row[f] total[f][tot]+=1 end i+=1 end total.each do |f,var| var.each do |tot,v| out[f][tot]=out[f][tot].to_f / total[f][tot] end end out end |
#item_difficulty_analysis ⇒ Object
Returns a dataset with cases ordered by score and variables ordered by difficulty
173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 |
# File 'lib/statsample/reliability.rb', line 173 def item_difficulty_analysis dif={} @ds.fields.each{|f| dif[f]=@ds[f].mean } dif_sort=dif.sort{|a,b| -(a[1]<=>b[1])} scores_sort={} scores=@ds.vector_mean scores.each_index{|i| scores_sort[i]=scores[i] } scores_sort=scores_sort.sort{|a,b| a[1]<=>b[1]} ds_new=Statsample::Dataset.new(['case','score'] + dif_sort.collect{|a,b| a}) scores_sort.each do |i,score| row=[i, score] case_row=@ds.case_as_hash(i) dif_sort.each{|variable,dif_value| row.push(case_row[variable]) } ds_new.add_case_array(row) end ds_new.update_valid_data ds_new end |
#item_statistics ⇒ Object
164 165 166 167 168 169 |
# File 'lib/statsample/reliability.rb', line 164 def item_statistics @ds.fields.inject({}) do |a,v| a[v]={:mean=>@ds[v].mean,:sds=>@ds[v].sds} a end end |
#item_total_correlation ⇒ Object
154 155 156 157 158 159 160 161 162 163 |
# File 'lib/statsample/reliability.rb', line 154 def item_total_correlation @ds.fields.inject({}) do |a,v| vector=@ds[v].dup ds2=@ds.dup ds2.delete_vector(v) total=ds2.vector_sum a[v]=Statsample::Bivariate.pearson(vector,total) a end end |
#stats_if_deleted ⇒ Object
191 192 193 194 195 196 197 198 199 200 201 202 203 |
# File 'lib/statsample/reliability.rb', line 191 def stats_if_deleted @ds.fields.inject({}) do |a,v| ds2=@ds.dup ds2.delete_vector(v) total=ds2.vector_sum a[v]={} a[v][:mean]=total.mean a[v][:sds]=total.sds a[v][:variance_sample]=total.variance_sample a[v][:alpha]=Statsample::Reliability.cronbach_alpha(ds2) a end end |
#svggraph_item_characteristic_curve(directory, base = "icc", options = {}) ⇒ Object
126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 |
# File 'lib/statsample/reliability.rb', line 126 def svggraph_item_characteristic_curve(directory, base="icc",={}) require 'statsample/graph/svggraph' crd=ItemCharacteristicCurve.new(@ds) @ds.fields.each do |f| factors=@ds[f].factors.sort ={ :height=>500, :width=>800, :key=>true }.update() graph = ::SVG::Graph::Plot.new() factors.each do |factor| factor=factor.to_s dataset=[] crd.curve_field(f, factor).each do |tot,prop| dataset.push(tot) dataset.push((prop*100).to_i.to_f/100) end graph.add_data({ :title=>"#{factor}", :data=>dataset }) end File.open(directory+"/"+base+"_#{f}.svg","w") {|fp| fp.puts(graph.burn()) } end end |