test/test_reliability.rb in statsample-1.4.3 vs test/test_reliability.rb in statsample-1.5.0

- old
+ new

@@ -14,13 +14,13 @@ context "Cronbach's alpha" do setup do @samples = 40 @n_variables = rand(10) + 2 @ds = Statsample::Dataset.new - base = @samples.times.collect { |_a| rand }.to_scale + base = @samples.times.collect { |_a| rand }.to_numeric @n_variables.times do |i| - @ds[i] = base.collect { |v| v + rand }.to_scale + @ds[i] = base.collect { |v| v + rand }.to_numeric end @ds.update_valid_data @k = @ds.fields.size @cm = Statsample::Bivariate.covariance_matrix(@ds) @@ -65,25 +65,25 @@ context Statsample::Reliability::ItemCharacteristicCurve do setup do @samples = 100 @points = rand(10) + 3 @max_point = (@points - 1) * 3 - @x1 = @samples.times.map { rand(@points) }.to_scale - @x2 = @samples.times.map { rand(@points) }.to_scale - @x3 = @samples.times.map { rand(@points) }.to_scale + @x1 = @samples.times.map { rand(@points) }.to_numeric + @x2 = @samples.times.map { rand(@points) }.to_numeric + @x3 = @samples.times.map { rand(@points) }.to_numeric @ds = { 'a' => @x1, 'b' => @x2, 'c' => @x3 }.to_dataset @icc = Statsample::Reliability::ItemCharacteristicCurve.new(@ds) end should 'have a correct automatic vector_total' do assert_equal(@ds.vector_sum, @icc.vector_total) end should 'have a correct different vector_total' do - x2 = @samples.times.map { rand(10) }.to_scale + x2 = @samples.times.map { rand(10) }.to_numeric @icc = Statsample::Reliability::ItemCharacteristicCurve.new(@ds, x2) assert_equal(x2, @icc.vector_total) assert_raises(ArgumentError) do - inc = (@samples + 10).times.map { rand(10) }.to_scale + inc = (@samples + 10).times.map { rand(10) }.to_numeric @icc = Statsample::Reliability::ItemCharacteristicCurve.new(@ds, inc) end end should 'have 0% for 0 points on maximum value values' do max = @icc.curve_field('a', 0)[@max_point.to_f] @@ -117,11 +117,11 @@ @scales = 3 @items_per_scale = 10 h = {} @scales.times {|s| @items_per_scale.times {|i| - h["#{s}_#{i}"] = (size.times.map { (s * 2) + rand }).to_scale + h["#{s}_#{i}"] = (size.times.map { (s * 2) + rand }).to_numeric } } @ds = h.to_dataset @msa = Statsample::Reliability::MultiScaleAnalysis.new(name: 'Multiple Analysis') do |m| m.scale 'complete', @ds @@ -175,22 +175,22 @@ assert(@msa.summary.size > 0) end end context Statsample::Reliability::ScaleAnalysis do setup do - @x1 = [1, 1, 1, 1, 2, 2, 2, 2, 3, 3, 3, 30].to_scale - @x2 = [1, 1, 1, 2, 2, 3, 3, 3, 3, 4, 4, 50].to_scale - @x3 = [2, 2, 1, 1, 1, 2, 2, 2, 3, 4, 5, 40].to_scale - @x4 = [1, 2, 3, 4, 4, 4, 4, 3, 4, 4, 5, 30].to_scale + @x1 = [1, 1, 1, 1, 2, 2, 2, 2, 3, 3, 3, 30].to_numeric + @x2 = [1, 1, 1, 2, 2, 3, 3, 3, 3, 4, 4, 50].to_numeric + @x3 = [2, 2, 1, 1, 1, 2, 2, 2, 3, 4, 5, 40].to_numeric + @x4 = [1, 2, 3, 4, 4, 4, 4, 3, 4, 4, 5, 30].to_numeric @ds = { 'x1' => @x1, 'x2' => @x2, 'x3' => @x3, 'x4' => @x4 }.to_dataset @ia = Statsample::Reliability::ScaleAnalysis.new(@ds) @cov_matrix = @ia.cov_m end should 'return correct values for item analysis' do assert_in_delta(0.980, @ia.alpha, 0.001) assert_in_delta(0.999, @ia.alpha_standarized, 0.001) - var_mean = 4.times.map { |m| @cov_matrix[m, m] }.to_scale.mean + var_mean = 4.times.map { |m| @cov_matrix[m, m] }.to_numeric.mean assert_in_delta(var_mean, @ia.variances_mean) assert_equal(@x1.mean, @ia.item_statistics['x1'][:mean]) assert_equal(@x4.mean, @ia.item_statistics['x4'][:mean]) assert_in_delta(@x1.sds, @ia.item_statistics['x1'][:sds], 1e-14) assert_in_delta(@x4.sds, @ia.item_statistics['x4'][:sds], 1e-14) @@ -209,10 +209,10 @@ if i != j covariances.push(@cov_matrix[i, j]) end } } - assert_in_delta(covariances.to_scale.mean, @ia.covariances_mean) + assert_in_delta(covariances.to_numeric.mean, @ia.covariances_mean) assert_in_delta(0.999, @ia.item_total_correlation['x1'], 0.001) assert_in_delta(1050.455, @ia.stats_if_deleted['x1'][:variance_sample], 0.001) end should 'return a summary' do assert(@ia.summary.size > 0)