statsample 0.6.2 → 0.6.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -33,14 +33,37 @@ class StatsampleBivariateTestCase < Test::Unit::TestCase
33
33
  poly = Statsample::Bivariate::Polychoric.new(matrix)
34
34
  assert_in_delta(tetra.r,poly.r,0.0001)
35
35
 
36
- # Example for http://www.john-uebersax.com/stat/tetra.htm#exampl
36
+ # Example for Tallis(1962, cited by Drasgow, 2006)
37
37
 
38
38
  matrix=Matrix[[58,52,1],[26,58,3],[8,12,9]]
39
39
  poly=Statsample::Bivariate::Polychoric.new(matrix)
40
- assert_in_delta(0.4199, poly.r, 0.0001)
41
- assert_in_delta(-0.2397, poly.threshold_y[0],0.001)
42
- assert_in_delta(-0.0276, poly.threshold_x[0],0.001)
40
+ poly.method=:two_step
41
+ poly.compute
42
+ assert_in_delta(0.420, poly.r, 0.001)
43
+ assert_in_delta(-0.240, poly.threshold_y[0],0.001)
44
+ assert_in_delta(-0.027, poly.threshold_x[0],0.001)
45
+ assert_in_delta(1.578, poly.threshold_y[1],0.001)
46
+ assert_in_delta(1.137, poly.threshold_x[1],0.001)
43
47
 
48
+
49
+ poly.method=:polychoric_series
50
+ poly.compute
51
+
52
+ assert_in_delta(0.556, poly.r, 0.001)
53
+ assert_in_delta(-0.240, poly.threshold_y[0],0.001)
54
+ assert_in_delta(-0.027, poly.threshold_x[0],0.001)
55
+ assert_in_delta(1.578, poly.threshold_y[1],0.001)
56
+ assert_in_delta(1.137, poly.threshold_x[1],0.001)
57
+
58
+
59
+ poly.method=:joint
60
+ poly.compute
61
+
62
+ assert_in_delta(0.4192, poly.r, 0.0001)
63
+ assert_in_delta(-0.2421, poly.threshold_y[0],0.0001)
64
+ assert_in_delta(-0.0297, poly.threshold_x[0],0.0001)
65
+ assert_in_delta(1.5938, poly.threshold_y[1],0.0001)
66
+ assert_in_delta(1.1331, poly.threshold_x[1],0.0001)
44
67
 
45
68
  end
46
69
  def test_tetrachoric
@@ -10,34 +10,34 @@ end
10
10
  class DistributionTestCase < Test::Unit::TestCase
11
11
  def test_chi
12
12
  if !NOT_GSL
13
- [2,3,4,5].each{|k|
13
+ [2,3,4,5].each{|k|
14
14
  chis=rand()*10
15
15
  area=Distribution::ChiSquare.cdf(chis, k)
16
16
  assert_in_delta(area, GSL::Cdf.chisq_P(chis,k),0.0001)
17
17
  assert_in_delta(chis, Distribution::ChiSquare.p_value(area,k),0.0001,"Error on prob #{area} and k #{k}")
18
- }
18
+ }
19
19
  end
20
20
  end
21
21
  def test_t
22
22
  if !NOT_GSL
23
- [-2,0.1,0.5,1,2].each{|t|
24
- [2,5,10].each{|n|
25
- area=Distribution::T.cdf(t,n)
26
- assert_in_delta(area, GSL::Cdf.tdist_P(t,n),0.0001)
27
- assert_in_delta(Distribution::T.p_value(area,n), GSL::Cdf.tdist_Pinv(area,n),0.0001)
28
-
29
- }
23
+ [-2,0.1,0.5,1,2].each{|t|
24
+ [2,5,10].each{|n|
25
+ area=Distribution::T.cdf(t,n)
26
+ assert_in_delta(area, GSL::Cdf.tdist_P(t,n),0.0001)
27
+ assert_in_delta(Distribution::T.p_value(area,n), GSL::Cdf.tdist_Pinv(area,n),0.0001)
28
+
30
29
  }
30
+ }
31
31
  end
32
32
  end
33
33
  def test_normal
34
34
  if !NOT_GSL
35
- [-2,0.1,0.5,1,2].each{|x|
36
- area=Distribution::Normal.cdf(x)
37
- assert_in_delta(area, GSL::Cdf.ugaussian_P(x),0.0001)
38
- assert_in_delta(Distribution::Normal.p_value(area), GSL::Cdf.ugaussian_Pinv(area),0.0001)
39
- assert_in_delta(Distribution::Normal.pdf(x), GSL::Ran::ugaussian_pdf(x),0.0001)
40
- }
35
+ [-2,0.1,0.5,1,2].each{|x|
36
+ area=Distribution::Normal.cdf(x)
37
+ assert_in_delta(area, GSL::Cdf.ugaussian_P(x),0.0001)
38
+ assert_in_delta(Distribution::Normal.p_value(area), GSL::Cdf.ugaussian_Pinv(area),0.0001)
39
+ assert_in_delta(Distribution::Normal.pdf(x), GSL::Ran::ugaussian_pdf(x),0.0001)
40
+ }
41
41
  end
42
42
  end
43
43
  def test_normal_bivariate
@@ -49,7 +49,8 @@ class DistributionTestCase < Test::Unit::TestCase
49
49
  end
50
50
 
51
51
  [-3,-2,-1,0,1,1.5].each {|x|
52
- assert_in_delta(Distribution::NormalBivariate.cdf_math(x,x,0.5), Distribution::NormalBivariate.cdf_iterate(x,x,0.5), 0.001)
52
+ assert_in_delta(Distribution::NormalBivariate.cdf_hull(x,x,0.5), Distribution::NormalBivariate.cdf_genz(x,x,0.5), 0.001)
53
+ assert_in_delta(Distribution::NormalBivariate.cdf_genz(x,x,0.5), Distribution::NormalBivariate.cdf_jantaravareerat(x,x,0.5), 0.001)
53
54
  }
54
55
 
55
56
  assert_in_delta(0.686, Distribution::NormalBivariate.cdf(2,0.5,0.5), 0.001)
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: statsample
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.6.2
4
+ version: 0.6.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Claudio Bustos
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2010-02-11 00:00:00 -03:00
12
+ date: 2010-02-15 00:00:00 -03:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
@@ -52,7 +52,7 @@ dependencies:
52
52
  - !ruby/object:Gem::Version
53
53
  version: 2.4.0
54
54
  version:
55
- description: A suite for your basic and advanced statistics needs. Descriptive statistics, multiple regression, factorial analysis, dominance analysis, scale's reliability analysis, bivariate statistics and others procedures.
55
+ description: ""
56
56
  email:
57
57
  - clbustos@gmail.com
58
58
  executables:
@@ -76,6 +76,7 @@ files:
76
76
  - data/test_binomial.csv
77
77
  - data/tetmat_matrix.txt
78
78
  - data/tetmat_test.txt
79
+ - demo/correlation_matrix.rb
79
80
  - demo/dominance_analysis_bootstrap.rb
80
81
  - demo/dominanceanalysis.rb
81
82
  - demo/multiple_regression.rb
@@ -114,7 +115,6 @@ files:
114
115
  - lib/statsample/graph/svghistogram.rb
115
116
  - lib/statsample/graph/svgscatterplot.rb
116
117
  - lib/statsample/histogram.rb
117
- - lib/statsample/htmlreport.rb
118
118
  - lib/statsample/matrix.rb
119
119
  - lib/statsample/mle.rb
120
120
  - lib/statsample/mle/logit.rb
@@ -197,7 +197,7 @@ rubyforge_project: ruby-statsample
197
197
  rubygems_version: 1.3.5
198
198
  signing_key:
199
199
  specification_version: 3
200
- summary: A suite for your basic and advanced statistics needs
200
+ summary: ""
201
201
  test_files:
202
202
  - test/test_bivariate.rb
203
203
  - test/test_factor.rb
@@ -1,255 +0,0 @@
1
- require 'statsample/graph/svggraph'
2
-
3
- module Statsample
4
- class HtmlReport
5
- def initialize(name,dir=nil)
6
- require 'fileutils'
7
- @uniq=1
8
- @uniq_file=0
9
- @name=name
10
- @partials=[]
11
- @anchors=[]
12
- dir||=@name+"/"
13
- @dir=dir
14
- @level=1
15
- FileUtils.mkdir(@dir) if !File.exists? @dir
16
- end
17
- def add_summary(name,summary)
18
- add_anchor(name)
19
- @partials.push(summary)
20
- end
21
- def add_anchor(name)
22
- @anchors.push([name,@level,@uniq])
23
- @partials.push("<a name='#{@uniq}'> </a>")
24
- @uniq+=1
25
- end
26
- def uniq_file(prepend="file")
27
- @uniq_file+=1
28
- "#{prepend}_#{@uniq_file}_#{Time.now.to_i}"
29
- end
30
-
31
- def add_tetrachoric_correlation_matrix(ds)
32
- add_anchor("Tetrachoric correlation Matrix")
33
- html="<h2>Tetrachoric Correlation Matrix</h2> <table><thead><th>-</th><th>"+ds.fields.join("</th><th>")+"</th> </thead> <tbody>"
34
- matrix=Statsample::Bivariate.tetrachoric_correlation_matrix(ds)
35
-
36
-
37
- (0...(matrix.row_size)).each {|row|
38
- html+="<tr><td>"+ds.fields[row]+"</td>"
39
- (0...(matrix.column_size)).each {|col|
40
- if matrix[row,col].nil?
41
- html+="<td>--</td>"
42
- else
43
- html+="<td><strong>#{sprintf("%0.2f",matrix[row,col])}</td>"
44
- end
45
- }
46
- html+="</tr>"
47
- }
48
- html+="</tbody></table>"
49
- @partials.push(html)
50
- end
51
-
52
-
53
- def add_correlation_matrix(ds)
54
- add_anchor("Correlation Matrix")
55
- html="<h2>Correlation Matrix</h2> <table><thead><th>-</th><th>"+ds.fields.join("</th><th>")+"</th> </thead> <tbody>"
56
- matrix=Statsample::Bivariate.correlation_matrix(ds)
57
- pmatrix=Statsample::Bivariate.correlation_probability_matrix(ds)
58
-
59
-
60
- (0...(matrix.row_size)).each {|row|
61
- html+="<tr><td>"+ds.fields[row]+"</td>"
62
- (0...(matrix.column_size)).each {|col|
63
- if matrix[row,col].nil?
64
- html+="<td>--</td>"
65
- else
66
- sig=""
67
- prob_out=""
68
- if !pmatrix[row,col].nil?
69
- prob=pmatrix[row,col]
70
- prob_out=sprintf("%0.3f",prob)
71
- if prob<0.01
72
- sig="**"
73
- elsif prob<0.05
74
- sig="*"
75
- else
76
- sig=""
77
- end
78
- end
79
- if sig==""
80
- html+="<td>#{sprintf("%0.3f",matrix[row,col])} #{sig}<br /> #{prob_out}</td>"
81
- else
82
- html+="<td><strong>#{sprintf("%0.3f",matrix[row,col])} #{sig}<br /> #{prob_out}</strong></td>"
83
-
84
- end
85
- end
86
- }
87
- html+="</tr>"
88
- }
89
- html+="</tbody></table>"
90
- @partials.push(html)
91
- end
92
- # Add a scale
93
- # First arg is the name of the scale
94
- # Other are fields
95
- def add_scale(ds,name, fields,icc=false)
96
- raise "Fields are empty" if fields.size==0
97
- add_anchor("Scale:#{name}")
98
-
99
- ds_partial=ds.dup(fields)
100
- ia=Statsample::Reliability::ItemAnalysis.new(ds_partial)
101
- html="<h2>Scale: #{name}</h2>"
102
- html << ia.html_summary
103
- @partials.push(html)
104
- @level+=1
105
- v=ds_partial.vector_mean
106
- add_histogram(name, v)
107
- add_runsequence_plot(name, v)
108
- add_normalprobability_plot(name,v)
109
- add_icc(name,fields) if icc
110
- @level-=1
111
- end
112
-
113
- def add_boxplot(name,vector,options={})
114
- add_graph("Box Plot #{name}", name, vector.svggraph_boxplot(options))
115
- end
116
- def add_graph(name,id,graph)
117
- add_anchor(name)
118
- rs_file=@dir+"/#{uniq_file()}.svg"
119
- html = "<h3>#{name}</h3> <p><embed src='#{rs_file}' width='#{graph.width}' height='#{graph.height}' type='image/svg+xml' /></p>\n"
120
- File.open(rs_file, "w") {|f|
121
- f.puts(graph.burn)
122
- }
123
- @partials.push(html)
124
- end
125
- def add_runsequence_plot(name, vector,options={})
126
- add_graph("Run-Sequence Plot #{name}", name, vector.svggraph_runsequence_plot(options))
127
- end
128
- def add_lag_plot(name,vector, options={})
129
- add_graph("Lag Plot #{name}", name,vector.svggraph_lag_plot(options))
130
- end
131
-
132
- def add_normalprobability_plot(name,vector,options={})
133
- add_graph("Normal Probability Plot #{name}", name, vector.svggraph_normalprobability_plot(options))
134
- end
135
-
136
- def add_scatterplot(name, ds,x_field=nil, y_fields=nil,config={})
137
- add_anchor("Scatterplot: #{name}")
138
- x_field||=ds.fields[0]
139
- y_fields||=ds.fields-[x_field]
140
- ds_partial=ds.dup([x_field]+y_fields)
141
- sc=Statsample::Graph::SvgScatterplot.new(ds_partial, config)
142
- sc.parse
143
- sc_file=@dir+"/#{uniq_file("sc")}.svg"
144
- html = "<h3>Scatterplot #{name}</h3> <p><embed src='#{sc_file}' width='#{sc.width}' height='#{sc.height}' type='image/svg+xml' /></p>\n"
145
- File.open(sc_file, "w") {|f|
146
- f.puts(sc.burn)
147
- }
148
- @partials.push(html)
149
- end
150
-
151
-
152
- def add_boxplots(name, ds,options={})
153
- add_anchor("Boxplots: #{name}")
154
- options={:graph_title=>"Boxplots:#{name}", :show_graph_title=>true, :height=>500}.merge! options
155
- graph = Statsample::Graph::SvgBoxplot.new(options)
156
- ds.fields.each{|f|
157
- graph.add_data(:title=>f,
158
- :data=>ds[f].valid_data,
159
- :vector=>ds[f]
160
- )
161
- }
162
- add_graph(name,name,graph)
163
- graph
164
- end
165
- def add_histogram(name,vector,bins=nil,options={})
166
- bins||=vector.size / 15
167
- bins=15 if bins>15
168
- graph=vector.svggraph_histogram(bins,options)
169
- add_graph("Histogram:#{name}",name,graph)
170
- html = "<ul><li>Skewness=#{sprintf("%0.3f",vector.skew)}</li>
171
- <li>Kurtosis=#{sprintf("%0.3f",vector.kurtosis)}</li></ul>"
172
- @partials.push(html)
173
- end
174
- def add_icc(name,ds, fields)
175
- require 'statsample/graph/svggraph'
176
- raise "Fields are empty" if fields.size==0
177
- add_anchor("ICC:#{name}")
178
- ds_partial=ds.dup(fields)
179
- ia=Statsample::Reliability::ItemAnalysis.new(ds_partial)
180
- html="<h3>ICC for scale: #{name}</h3>"
181
- ia.svggraph_item_characteristic_curve(@dir ,name, {:width=>400,:height=>300})
182
- ds_partial.fields.sort.each{|f|
183
- html << "<div><p><strong>#{f}</strong></p><embed src='#{@dir}/#{name}_#{f}.svg' width='400' height='300' type='image/svg+xml' /></div>\n"
184
- }
185
- @partials.push(html)
186
- end
187
- def css
188
- <<HERE
189
- table {
190
- border-collapse: collapse;
191
- }
192
- th {
193
- text-align: left;
194
- padding-right: 1em;
195
- border-bottom: 3px solid #ccc;
196
- }
197
- th.active img {
198
- display: inline;
199
- }
200
- tr.even, tr.odd {
201
- background-color: #eee;
202
- border-bottom: 1px solid #ccc;
203
- }
204
- tr.even, tr.odd {
205
- padding: 0.1em 0.6em;
206
- }
207
- td.active {
208
- background-color: #ddd;
209
- }
210
- table td {
211
- border:1px solid #aaa;
212
- }
213
- table tr.line td{
214
- border-top: 2px solid black;
215
- }
216
-
217
- HERE
218
- end
219
-
220
- def create_uls(level)
221
- if @c_level!=level
222
- if level>@c_level
223
- "<ul>\n" * (level-@c_level)
224
- else
225
- "</ul>\n" * (@c_level-level)
226
- end
227
- else
228
- ""
229
- end
230
- end
231
-
232
- def parse
233
- html="<html><head><title>#{@name}</title><style>#{css()}</style></head><body><h1>Report: #{@name}</h1>"
234
- if @anchors.size>0
235
- html << "<div class='index'>Index</div><ul>"
236
- @c_level=1
237
- @anchors.each{|name,level,uniq|
238
- html << create_uls(level)
239
- @c_level=level
240
- html << "<li><a href='#"+uniq.to_s+"'>#{name}</a></li>"
241
- }
242
- html << create_uls(1)
243
- html << "</ul></div>"
244
- end
245
- html+="<div class='section'>"+@partials.join("</div><div class='section'>")+"</div>"
246
- html+="</body></html>"
247
- html
248
- end
249
- def save(filename)
250
- File.open(filename,"w") {|fp|
251
- fp.write(parse)
252
- }
253
- end
254
- end
255
- end