statsample 0.15.1 → 0.16.0
Sign up to get free protection for your applications and to get access to all the features.
- data.tar.gz.sig +0 -0
- data/History.txt +8 -0
- data/Manifest.txt +2 -6
- data/Rakefile +2 -2
- data/examples/dominance_analysis.rb +1 -2
- data/examples/multivariate_correlation.rb +1 -0
- data/examples/parallel_analysis.rb +7 -6
- data/examples/scatterplot.rb +12 -0
- data/lib/distribution/normal.rb +29 -1
- data/lib/statsample.rb +5 -2
- data/lib/statsample/bivariate.rb +3 -2
- data/lib/statsample/converters.rb +1 -1
- data/lib/statsample/dataset.rb +42 -14
- data/lib/statsample/factor/parallelanalysis.rb +5 -5
- data/lib/statsample/graph.rb +1 -4
- data/lib/statsample/graph/scatterplot.rb +169 -0
- data/lib/statsample/matrix.rb +5 -5
- data/lib/statsample/mle/logit.rb +5 -4
- data/lib/statsample/multiset.rb +4 -1
- data/lib/statsample/vector.rb +9 -2
- data/references.txt +1 -0
- data/test/test_anovaoneway.rb +1 -1
- data/test/test_factor.rb +29 -24
- data/test/test_reliability_icc.rb +0 -2
- data/test/test_vector.rb +4 -0
- metadata +78 -42
- metadata.gz.sig +0 -0
- data/lib/statsample/graph/gdchart.rb +0 -45
- data/lib/statsample/graph/svgboxplot.rb +0 -108
- data/lib/statsample/graph/svggraph.rb +0 -184
- data/lib/statsample/graph/svghistogram.rb +0 -206
- data/lib/statsample/graph/svgscatterplot.rb +0 -118
- data/test/test_svg_graph.rb +0 -54
@@ -1,118 +0,0 @@
|
|
1
|
-
require 'tempfile'
|
2
|
-
module Statsample
|
3
|
-
module Graph
|
4
|
-
class SvgScatterplot < SVG::Graph::Plot # :nodoc:
|
5
|
-
attr_accessor :draw_path
|
6
|
-
def initialize(ds,config={})
|
7
|
-
super(config)
|
8
|
-
@ds=ds
|
9
|
-
set_x(@ds.fields[0])
|
10
|
-
end
|
11
|
-
def report_building_html(g)
|
12
|
-
self.parse()
|
13
|
-
tf=Tempfile.new(['image','.svg'])
|
14
|
-
tf.write self.burn
|
15
|
-
tf.close
|
16
|
-
image=ReportBuilder::Image.new(tf.path)
|
17
|
-
g.parse_element(image)
|
18
|
-
end
|
19
|
-
def set_defaults
|
20
|
-
super
|
21
|
-
init_with(
|
22
|
-
:show_data_values => false,
|
23
|
-
:draw_path => false
|
24
|
-
)
|
25
|
-
end
|
26
|
-
def set_x(x)
|
27
|
-
@x=x
|
28
|
-
@y=@ds.fields - [x]
|
29
|
-
end
|
30
|
-
def parse
|
31
|
-
data=@y.inject({}){|a,v| a[v]=[];a}
|
32
|
-
@ds.each{|row|
|
33
|
-
@y.each{|y|
|
34
|
-
data[y]+=[row[@x],row[y]] unless row[@x].nil? or row[y].nil?
|
35
|
-
}
|
36
|
-
}
|
37
|
-
data.each{|y,d|
|
38
|
-
add_data({
|
39
|
-
:data=>d, :title=>@ds[y].name
|
40
|
-
})
|
41
|
-
}
|
42
|
-
end
|
43
|
-
def get_x_labels
|
44
|
-
values=super
|
45
|
-
values.collect{|x|
|
46
|
-
if x.is_a? Integer
|
47
|
-
x
|
48
|
-
else
|
49
|
-
sprintf("%0.2f",x).to_f
|
50
|
-
end
|
51
|
-
}
|
52
|
-
end
|
53
|
-
def get_y_labels
|
54
|
-
values=super
|
55
|
-
values.collect{|x|
|
56
|
-
if x.is_a? Integer
|
57
|
-
x
|
58
|
-
else
|
59
|
-
sprintf("%0.2f",x).to_f
|
60
|
-
end
|
61
|
-
}
|
62
|
-
end
|
63
|
-
def draw_data
|
64
|
-
line = 1
|
65
|
-
|
66
|
-
x_min, x_max, x_div = x_range
|
67
|
-
y_min, y_max, y_div = y_range
|
68
|
-
x_step = (@graph_width.to_f - font_size*2) / (x_max-x_min)
|
69
|
-
y_step = (@graph_height.to_f - font_size*2) / (y_max-y_min)
|
70
|
-
|
71
|
-
for data in @data
|
72
|
-
x_points = data[:data][X]
|
73
|
-
y_points = data[:data][Y]
|
74
|
-
|
75
|
-
lpath = "L"
|
76
|
-
x_start = 0
|
77
|
-
y_start = 0
|
78
|
-
x_points.each_index { |idx|
|
79
|
-
x = (x_points[idx] - x_min) * x_step
|
80
|
-
y = @graph_height - (y_points[idx] - y_min) * y_step
|
81
|
-
x_start, y_start = x,y if idx == 0
|
82
|
-
lpath << "#{x} #{y} "
|
83
|
-
}
|
84
|
-
|
85
|
-
if area_fill
|
86
|
-
@graph.add_element( "path", {
|
87
|
-
"d" => "M#{x_start} #@graph_height #{lpath} V#@graph_height Z",
|
88
|
-
"class" => "fill#{line}"
|
89
|
-
})
|
90
|
-
end
|
91
|
-
if draw_path
|
92
|
-
@graph.add_element( "path", {
|
93
|
-
"d" => "M#{x_start} #{y_start} #{lpath}",
|
94
|
-
"class" => "line#{line}"
|
95
|
-
})
|
96
|
-
end
|
97
|
-
if show_data_points || show_data_values
|
98
|
-
x_points.each_index { |idx|
|
99
|
-
x = (x_points[idx] - x_min) * x_step
|
100
|
-
y = @graph_height - (y_points[idx] - y_min) * y_step
|
101
|
-
if show_data_points
|
102
|
-
@graph.add_element( "circle", {
|
103
|
-
"cx" => x.to_s,
|
104
|
-
"cy" => y.to_s,
|
105
|
-
"r" => "2.5",
|
106
|
-
"class" => "dataPoint#{line}"
|
107
|
-
})
|
108
|
-
add_popup(x, y, format( x_points[idx], y_points[idx] )) if add_popups
|
109
|
-
end
|
110
|
-
make_datapoint_text( x, y-6, y_points[idx] ) if show_data_values
|
111
|
-
}
|
112
|
-
end
|
113
|
-
line += 1
|
114
|
-
end
|
115
|
-
end
|
116
|
-
end
|
117
|
-
end
|
118
|
-
end
|
data/test/test_svg_graph.rb
DELETED
@@ -1,54 +0,0 @@
|
|
1
|
-
require(File.dirname(__FILE__)+'/helpers_tests.rb')
|
2
|
-
require('statsample/graph')
|
3
|
-
class StatsampleSvgGraphTestCase < MiniTest::Unit::TestCase
|
4
|
-
|
5
|
-
def setup
|
6
|
-
@image_path=Dir::tmpdir+"/images"
|
7
|
-
FileUtils.mkdir(@image_path) if !File.exists? @image_path
|
8
|
-
end
|
9
|
-
def test_histogram
|
10
|
-
if Statsample.has_gsl?
|
11
|
-
ar=(1..1000).to_a.collect {|a|
|
12
|
-
rand(10)
|
13
|
-
}.to_vector(:scale)
|
14
|
-
h=ar.histogram([0,2,5,11])
|
15
|
-
file=Tempfile.new("svg_histogram_only.svg")
|
16
|
-
graph = Statsample::Graph::SvgHistogram.new({})
|
17
|
-
graph.histogram=h
|
18
|
-
file.puts(graph.burn)
|
19
|
-
else
|
20
|
-
skip "Statsample::Graph::SvgHistogram.new not tested (no ruby-gsl)"
|
21
|
-
end
|
22
|
-
end
|
23
|
-
def assert_svg(msg=nil)
|
24
|
-
msg||="%s isn't a svg file"
|
25
|
-
Tempfile.open("svg") do |fp|
|
26
|
-
yield fp
|
27
|
-
fp.close
|
28
|
-
fp.open
|
29
|
-
assert_match(/DOCTYPE svg/, fp.gets(nil), sprintf(msg,fp.path))
|
30
|
-
end
|
31
|
-
end
|
32
|
-
def test_vector
|
33
|
-
ar=[]
|
34
|
-
(1..1000).each {|a|
|
35
|
-
ar.push(rand(10))
|
36
|
-
}
|
37
|
-
vector=ar.to_vector
|
38
|
-
assert_svg {|file| vector.svggraph_frequencies(file)}
|
39
|
-
assert_svg {|file| vector.svggraph_frequencies(file, 800, 600, SVG::Graph::Bar, :graph_title=>'Bar') }
|
40
|
-
assert_svg {|file| vector.svggraph_frequencies(file, 800, 600, SVG::Graph::BarHorizontalNoOp, :graph_title=>'Horizontal Bar') }
|
41
|
-
assert_svg {|file| vector.svggraph_frequencies(file,800,600, SVG::Graph::PieNoOp, :graph_title=>'Pie') }
|
42
|
-
vector.type=:scale
|
43
|
-
if Statsample.has_gsl?
|
44
|
-
file=Tempfile.new("svg_histogram.svg").path
|
45
|
-
hist=vector.svggraph_histogram(5)
|
46
|
-
File.open(file,"wb") {|fp|
|
47
|
-
fp.write(hist.burn)
|
48
|
-
}
|
49
|
-
#assert(File.exists?(file))
|
50
|
-
else
|
51
|
-
skip "Statsample::Vector#svggraph_histogram.new not tested (no ruby-gsl)"
|
52
|
-
end
|
53
|
-
end
|
54
|
-
end
|