lib/statsample/dominanceanalysis/bootstrap.rb in statsample-0.5.1 vs lib/statsample/dominanceanalysis/bootstrap.rb in statsample-0.6.0

- old
+ new

@@ -24,29 +24,33 @@ if @da.nil? @da=DominanceAnalysis.new(@ds,@y_var,@lr_class) end @da end + # Creates re-samples from original dataset. + # * number_samples: Number of new samples to add + # * n: size of each new sample. If nil, equal to original sample size + # * report: if true, echo number of current resample and total def bootstrap(number_samples,n=nil,report=false) - number_samples.times{ |t| - @n_samples+=1 - puts _("Bootstrap %d of %d") % [t+1, number_samples] if report - ds_boot=@ds.bootstrap(n) - da_1=DominanceAnalysis.new(ds_boot,@y_var,@lr_class) - da_1.total_dominance.each{|k,v| - @samples_td[k].push(v) - } - da_1.conditional_dominance.each{|k,v| - @samples_cd[k].push(v) - } - da_1.general_dominance.each{|k,v| - @samples_gd[k].push(v) - } - da_1.general_averages.each{|k,v| - @samples_ga[k].push(v) - } - } + number_samples.times{ |t| + @n_samples+=1 + puts _("Bootstrap %d of %d") % [t+1, number_samples] if report + ds_boot=@ds.bootstrap(n) + da_1=DominanceAnalysis.new(ds_boot,@y_var,@lr_class) + da_1.total_dominance.each{|k,v| + @samples_td[k].push(v) + } + da_1.conditional_dominance.each{|k,v| + @samples_cd[k].push(v) + } + da_1.general_dominance.each{|k,v| + @samples_gd[k].push(v) + } + da_1.general_averages.each{|k,v| + @samples_ga[k].push(v) + } + } end def create_samples_pairs @samples_td={} @samples_cd={} @samples_gd={} @@ -104,22 +108,22 @@ out.add(_("General averages")) table=Statsample::ReportTable.new table.header=[_("var"),_("mean"),_("se"),_("p.5"),_("p.95")] @fields.each{|f| v=@samples_ga[f].to_vector(:scale) - row=[@ds.vector_label(f), sprintf("%0.3f",v.mean), sprintf("%0.3f",v.sd), sprintf("%0.3f",v.percentil(5)),sprintf("%0.3f",v.percentil(95))] + row=[@ds.label(f), sprintf("%0.3f",v.mean), sprintf("%0.3f",v.sd), sprintf("%0.3f",v.percentil(5)),sprintf("%0.3f",v.percentil(95))] table.add_row(row) } out.parse_table(table) out end def summary_pairs(pair,std,ttd) freqs=std.proportions - [0,0.5,1].each{|n| + [0, 0.5, 1].each{|n| freqs[n]=0 if freqs[n].nil? } - name=@ds.vector_label(pair[0])+" - "+@ds.vector_label(pair[1]) + name=@ds.label(pair[0])+" - "+@ds.label(pair[1]) [name,f(ttd,1),f(std.mean,4),f(std.sd),f(freqs[1]), f(freqs[0]), f(freqs[0.5]), f(freqs[ttd])] end def f(v,n=3) prec="%0.#{n}f" sprintf(prec,v)