rust 0.7 → 0.11

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.
@@ -1,6 +1,13 @@
1
- require_relative 'rust-core'
1
+ require_relative '../core'
2
+
3
+ ##
4
+ # Module with utilities for running statistical hypothesis tests.
2
5
 
3
6
  module Rust::StatisticalTests
7
+
8
+ ##
9
+ # Represents the result of a statistical hypothesis test.
10
+
4
11
  class Result
5
12
  attr_accessor :name
6
13
  attr_accessor :statistics
@@ -21,16 +28,28 @@ module Rust::StatisticalTests
21
28
  @statistics[name.to_sym] = value
22
29
  end
23
30
 
31
+ ##
32
+ # If a hypothesis is available, returns the adjusted p-value with respect to all the other results obtained for
33
+ # the same hypothesis. Otherwise, simply returns the p-value for this result.
34
+ # The +method+ for adjustment can be optionally specified (Bonferroni, by default).
35
+
24
36
  def adjusted_pvalue(method='bonferroni')
25
- return 1 unless @hypothesis
37
+ return @pvalue unless @hypothesis
26
38
  @hypothesis.adjusted_pvalue_for(self, method)
27
39
  end
28
40
 
41
+ ##
42
+ # Sets the underlying hypothesis for the test. The p-values of the results belonging to the same hypothesis can
43
+ # be adjusted through the adjusted_pvalue method.
44
+
29
45
  def hypothesis=(value)
30
46
  @hypothesis = value
31
47
  @hypothesis.add(self)
32
48
  end
33
49
 
50
+ ##
51
+ # Returns true if the results are significant according to the specified alpha.
52
+
34
53
  def significant
35
54
  pvalue < alpha
36
55
  end
@@ -43,7 +62,13 @@ module Rust::StatisticalTests
43
62
  end
44
63
  end
45
64
 
46
- class Hypothesis
65
+ ##
66
+ # Represents a hypothesis behind one or more results.
67
+
68
+ class Hypothesis
69
+ ##
70
+ # Returns the hypothesis with the given +title_or_instance+ as title (if String).
71
+
47
72
  def self.find(title_or_instance)
48
73
  return Hypothesis.new(nil) if title_or_instance == nil
49
74
 
@@ -63,18 +88,28 @@ module Rust::StatisticalTests
63
88
  attr_reader :results
64
89
  attr_reader :title
65
90
 
91
+ ##
92
+ # Creates a new hypothesis with a given +title+.
93
+
66
94
  def initialize(title)
67
95
  @title = title
68
96
  @results = []
69
97
  end
70
98
 
99
+ ##
100
+ # Registers a +result+ for this hypothesis.
101
+
71
102
  def add(result)
72
103
  @results << result
73
104
  end
74
105
 
75
- def adjusted_pvalue_for(instance, method)
106
+ ##
107
+ # Returns the adjusted p-value for a specific +result+ with respect to all the other results obtained under this
108
+ # same hypothesis, using the specified +method+.
109
+
110
+ def adjusted_pvalue_for(result, method)
76
111
  p_values = @results.map { |r| r.pvalue }
77
- index = @results.index(instance)
112
+ index = @results.index(result)
78
113
 
79
114
  adjusted_pvalues = Rust::StatisticalTests::PValueAdjustment.method(method).adjust(*p_values)
80
115
 
@@ -85,85 +120,17 @@ module Rust::StatisticalTests
85
120
  end
86
121
  end
87
122
  end
88
- end
89
-
90
- module Rust::StatisticalTests::PValueAdjustment
91
- def self.method(name)
92
- name = name.to_s
93
- case name.downcase
94
- when "bonferroni", "b"
95
- return Bonferroni
96
- when "holm", "h"
97
- return Holm
98
- when "hochberg"
99
- return Hochberg
100
- when "hommel"
101
- return Hommel
102
- when "benjaminihochberg", "bh"
103
- return BenjaminiHochberg
104
- when "benjaminiyekutieli", "by"
105
- return BenjaminiYekutieli
106
- end
107
- end
108
-
109
- class Bonferroni
110
- def self.adjust(*p_values)
111
- Rust.exclusive do
112
- Rust['adjustment.p'] = p_values
113
- return Rust._pull("p.adjust(adjustment.p, method=\"bonferroni\")")
114
- end
115
- end
116
- end
117
123
 
118
- class Holm
119
- def self.adjust(*p_values)
120
- Rust.exclusive do
121
- Rust['adjustment.p'] = p_values
122
- return Rust._pull("p.adjust(adjustment.p, method=\"holm\")")
123
- end
124
- end
125
- end
126
-
127
- class Hochberg
128
- def self.adjust(*p_values)
129
- Rust.exclusive do
130
- Rust['adjustment.p'] = p_values
131
- return Rust._pull("p.adjust(adjustment.p, method=\"hochberg\")")
132
- end
133
- end
134
- end
135
-
136
- class Hommel
137
- def self.adjust(*p_values)
138
- Rust.exclusive do
139
- Rust['adjustment.p'] = p_values
140
- return Rust._pull("p.adjust(adjustment.p, method=\"hommel\")")
141
- end
142
- end
143
- end
144
-
145
- class BenjaminiHochberg
146
- def self.adjust(*p_values)
147
- Rust.exclusive do
148
- Rust['adjustment.p'] = p_values
149
- return Rust._pull("p.adjust(adjustment.p, method=\"BH\")")
150
- end
151
- end
152
- end
153
-
154
- class BenjaminiYekutieli
155
- def self.adjust(*p_values)
156
- Rust.exclusive do
157
- Rust['adjustment.p'] = p_values
158
- return Rust._pull("p.adjust(adjustment.p, method=\"BY\")")
159
- end
160
- end
161
- end
162
- end
124
+ ##
125
+ # Class with utilities for running Wilcoxon Signed-Rank test and Ranked-Sum test (a.k.a. Mann-Whitney U test).
163
126
 
164
- module Rust::StatisticalTests::Wilcoxon
165
- class << self
166
- def paired(d1, d2, alpha = 0.05, **options)
127
+ class Wilcoxon
128
+
129
+ ##
130
+ # Runs a Wilxoson Signed-Rank test for +d1+ and +d2+, with a given +alpha+ (0.05, by default).
131
+ # +options+ can be specified and directly passed to the R function.
132
+
133
+ def self.paired(d1, d2, alpha = 0.05, **options)
167
134
  raise TypeError, "Expecting Array of numerics" if !d1.is_a?(Array) || !d1.all? { |e| e.is_a?(Numeric) }
168
135
  raise TypeError, "Expecting Array of numerics" if !d2.is_a?(Array) || !d2.all? { |e| e.is_a?(Numeric) }
169
136
  raise "The two distributions have different size" if d1.size != d2.size
@@ -185,7 +152,11 @@ module Rust::StatisticalTests::Wilcoxon
185
152
  end
186
153
  end
187
154
 
188
- def unpaired(d1, d2, alpha = 0.05, **options)
155
+ ##
156
+ # Runs a Wilxoson Ranked-Sum (a.k.a. Mann-Whitney U) test for +d1+ and +d2+, with a given +alpha+ (0.05, by default).
157
+ # +options+ can be specified and directly passed to the R function.
158
+
159
+ def self.unpaired(d1, d2, alpha = 0.05, **options)
189
160
  raise TypeError, "Expecting Array of numerics" if !d1.is_a?(Array) || !d1.all? { |e| e.is_a?(Numeric) }
190
161
  raise TypeError, "Expecting Array of numerics" if !d2.is_a?(Array) || !d2.all? { |e| e.is_a?(Numeric) }
191
162
 
@@ -206,11 +177,17 @@ module Rust::StatisticalTests::Wilcoxon
206
177
  end
207
178
  end
208
179
  end
209
- end
180
+
181
+ ##
182
+ # Class with utilities for running the T test.
210
183
 
211
- module Rust::StatisticalTests::T
212
- class << self
213
- def paired(d1, d2, alpha = 0.05, **options)
184
+ class T
185
+
186
+ ##
187
+ # Runs a paired T test for +d1+ and +d2+, with a given +alpha+ (0.05, by default).
188
+ # +options+ can be specified and directly passed to the R function.
189
+
190
+ def self.paired(d1, d2, alpha = 0.05, **options)
214
191
  raise TypeError, "Expecting Array of numerics" if !d1.is_a?(Array) || !d1.all? { |e| e.is_a?(Numeric) }
215
192
  raise TypeError, "Expecting Array of numerics" if !d2.is_a?(Array) || !d2.all? { |e| e.is_a?(Numeric) }
216
193
  raise "The two distributions have different size" if d1.size != d2.size
@@ -232,7 +209,11 @@ module Rust::StatisticalTests::T
232
209
  end
233
210
  end
234
211
 
235
- def unpaired(d1, d2, alpha = 0.05, **options)
212
+ ##
213
+ # Runs an unpaired T test for +d1+ and +d2+, with a given +alpha+ (0.05, by default).
214
+ # +options+ can be specified and directly passed to the R function.
215
+
216
+ def self.unpaired(d1, d2, alpha = 0.05, **options)
236
217
  raise TypeError, "Expecting Array of numerics" if !d1.is_a?(Array) || !d1.all? { |e| e.is_a?(Numeric) }
237
218
  raise TypeError, "Expecting Array of numerics" if !d2.is_a?(Array) || !d2.all? { |e| e.is_a?(Numeric) }
238
219
 
@@ -253,11 +234,17 @@ module Rust::StatisticalTests::T
253
234
  end
254
235
  end
255
236
  end
256
- end
257
237
 
258
- module Rust::StatisticalTests::Shapiro
259
- class << self
260
- def compute(vector, alpha = 0.05, **options)
238
+ ##
239
+ # Utilities for the Shapiro normality test.
240
+
241
+ class Shapiro
242
+
243
+ ##
244
+ # Runs the Shapiro normality test for +vector+ and a given +alpha+ (0.05, by default).
245
+ # +options+ can be specified and directly passed to the R function.
246
+
247
+ def self.compute(vector, alpha = 0.05, **options)
261
248
  raise TypeError, "Expecting Array of numerics" if !vector.is_a?(Array) || !vector.all? { |e| e.is_a?(Numeric) }
262
249
  Rust.exclusive do
263
250
  Rust['shapiro.v'] = vector
@@ -275,6 +262,105 @@ module Rust::StatisticalTests::Shapiro
275
262
  end
276
263
  end
277
264
  end
265
+
266
+ ##
267
+ # Module with utilities for adjusting the p-values.
268
+
269
+ module PValueAdjustment
270
+
271
+ ##
272
+ # Returns the Ruby class given the R name of the p-value adjustment method.
273
+
274
+ def self.method(name)
275
+ name = name.to_s
276
+ case name.downcase
277
+ when "bonferroni", "b"
278
+ return Bonferroni
279
+ when "holm", "h"
280
+ return Holm
281
+ when "hochberg"
282
+ return Hochberg
283
+ when "hommel"
284
+ return Hommel
285
+ when "benjaminihochberg", "bh"
286
+ return BenjaminiHochberg
287
+ when "benjaminiyekutieli", "by"
288
+ return BenjaminiYekutieli
289
+ end
290
+ end
291
+
292
+ ##
293
+ # Bonferroni p-value adjustment method.
294
+
295
+ class Bonferroni
296
+ def self.adjust(*p_values)
297
+ Rust.exclusive do
298
+ Rust['adjustment.p'] = p_values
299
+ return Rust._pull("p.adjust(adjustment.p, method=\"bonferroni\")")
300
+ end
301
+ end
302
+ end
303
+
304
+ ##
305
+ # Holm p-value adjustment method.
306
+
307
+ class Holm
308
+ def self.adjust(*p_values)
309
+ Rust.exclusive do
310
+ Rust['adjustment.p'] = p_values
311
+ return Rust._pull("p.adjust(adjustment.p, method=\"holm\")")
312
+ end
313
+ end
314
+ end
315
+
316
+ ##
317
+ # Hochberg p-value adjustment method.
318
+
319
+ class Hochberg
320
+ def self.adjust(*p_values)
321
+ Rust.exclusive do
322
+ Rust['adjustment.p'] = p_values
323
+ return Rust._pull("p.adjust(adjustment.p, method=\"hochberg\")")
324
+ end
325
+ end
326
+ end
327
+
328
+ ##
329
+ # Hommel p-value adjustment method.
330
+
331
+ class Hommel
332
+ def self.adjust(*p_values)
333
+ Rust.exclusive do
334
+ Rust['adjustment.p'] = p_values
335
+ return Rust._pull("p.adjust(adjustment.p, method=\"hommel\")")
336
+ end
337
+ end
338
+ end
339
+
340
+ ##
341
+ # Benjamini-Hochberg p-value adjustment method.
342
+
343
+ class BenjaminiHochberg
344
+ def self.adjust(*p_values)
345
+ Rust.exclusive do
346
+ Rust['adjustment.p'] = p_values
347
+ return Rust._pull("p.adjust(adjustment.p, method=\"BH\")")
348
+ end
349
+ end
350
+ end
351
+
352
+ ##
353
+ # Benjamini-Yekutieli p-value adjustment method.
354
+
355
+ class BenjaminiYekutieli
356
+ def self.adjust(*p_values)
357
+ Rust.exclusive do
358
+ Rust['adjustment.p'] = p_values
359
+ return Rust._pull("p.adjust(adjustment.p, method=\"BY\")")
360
+ end
361
+ end
362
+ end
363
+ end
278
364
  end
279
365
 
280
366
  module Rust::RBindings
data/lib/rust.rb CHANGED
@@ -1,9 +1,4 @@
1
- require_relative 'rust-core'
2
- require_relative 'rust-basics'
3
- require_relative 'rust-csv'
4
- require_relative 'rust-tests'
5
- require_relative 'rust-effsize'
6
- require_relative 'rust-descriptive'
7
- require_relative 'rust-plots'
8
- require_relative 'rust-calls'
9
- require_relative 'rust-probabilities'
1
+ require_relative 'rust/core'
2
+ require_relative 'rust/models/all'
3
+ require_relative 'rust/plots/all'
4
+ require_relative 'rust/stats/all'
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rust
3
3
  version: !ruby/object:Gem::Version
4
- version: '0.7'
4
+ version: '0.11'
5
5
  platform: ruby
6
6
  authors:
7
7
  - Simone Scalabrino
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-02-16 00:00:00.000000000 Z
11
+ date: 2022-08-11 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rinruby
@@ -52,20 +52,39 @@ dependencies:
52
52
  version: 1.1.2
53
53
  description: Ruby advanced statistical library based on RinRuby
54
54
  email: s.scalabrino9@gmail.com
55
- executables: []
55
+ executables:
56
+ - ruby-rust
56
57
  extensions: []
57
58
  extra_rdoc_files: []
58
59
  files:
59
- - lib/rust-basics.rb
60
- - lib/rust-calls.rb
61
- - lib/rust-core.rb
62
- - lib/rust-csv.rb
63
- - lib/rust-descriptive.rb
64
- - lib/rust-effsize.rb
65
- - lib/rust-plots.rb
66
- - lib/rust-probabilities.rb
67
- - lib/rust-tests.rb
60
+ - bin/ruby-rust
68
61
  - lib/rust.rb
62
+ - lib/rust/core.rb
63
+ - lib/rust/core/csv.rb
64
+ - lib/rust/core/rust.rb
65
+ - lib/rust/core/types/all.rb
66
+ - lib/rust/core/types/dataframe.rb
67
+ - lib/rust/core/types/datatype.rb
68
+ - lib/rust/core/types/factor.rb
69
+ - lib/rust/core/types/language.rb
70
+ - lib/rust/core/types/list.rb
71
+ - lib/rust/core/types/matrix.rb
72
+ - lib/rust/core/types/s4class.rb
73
+ - lib/rust/core/types/utils.rb
74
+ - lib/rust/external/robustbase.rb
75
+ - lib/rust/models/all.rb
76
+ - lib/rust/models/anova.rb
77
+ - lib/rust/models/regression.rb
78
+ - lib/rust/plots/all.rb
79
+ - lib/rust/plots/basic-plots.rb
80
+ - lib/rust/plots/core.rb
81
+ - lib/rust/plots/distribution-plots.rb
82
+ - lib/rust/stats/all.rb
83
+ - lib/rust/stats/correlation.rb
84
+ - lib/rust/stats/descriptive.rb
85
+ - lib/rust/stats/effsize.rb
86
+ - lib/rust/stats/probabilities.rb
87
+ - lib/rust/stats/tests.rb
69
88
  homepage: https://github.com/intersimone999/ruby-rust
70
89
  licenses:
71
90
  - GPL-3.0-only
@@ -85,7 +104,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
85
104
  - !ruby/object:Gem::Version
86
105
  version: '0'
87
106
  requirements: []
88
- rubygems_version: 3.2.7
107
+ rubygems_version: 3.3.15
89
108
  signing_key:
90
109
  specification_version: 4
91
110
  summary: Ruby advanced statistical library
data/lib/rust-calls.rb DELETED
@@ -1,80 +0,0 @@
1
- require_relative 'rust-core'
2
-
3
- module Rust
4
- class Function
5
- attr_reader :name
6
- attr_reader :arguments
7
- attr_reader :options
8
-
9
- def initialize(name)
10
- @function = name
11
- @arguments = Arguments.new
12
- @options = Options.new
13
- end
14
-
15
- def options=(options)
16
- raise TypeError, "Expected Options" unless options.is_a?(Options)
17
-
18
- @options = options
19
- end
20
-
21
- def arguments=(arguments)
22
- raise TypeError, "Expected Arguments" unless options.is_a?(Arguments)
23
-
24
- @arguments = arguments
25
- end
26
-
27
- def to_R
28
- params = [@arguments.to_R, @options.to_R].select { |v| v != "" }.join(",")
29
- return "#@function(#{params})"
30
- end
31
-
32
- def call
33
- Rust._eval(self.to_R)
34
- end
35
- end
36
-
37
- class SimpleFormula
38
- def initialize(dependent, independent)
39
- @dependent = dependent
40
- @independent = independent
41
- end
42
-
43
- def to_R
44
- return "#@dependent ~ #@independent"
45
- end
46
- end
47
-
48
- class Variable
49
- def initialize(name)
50
- @name = name
51
- end
52
-
53
- def to_R
54
- @name
55
- end
56
- end
57
-
58
- class Arguments < Array
59
- def to_R
60
- return self.map { |v| v.to_R }.join(", ")
61
- end
62
- end
63
-
64
- class Options < Hash
65
- def to_R
66
- return self.map { |k, v| "#{k}=#{v.to_R}" }.join(", ")
67
- end
68
-
69
- def self.from_hash(hash)
70
- options = Options.new
71
- hash.each do |key, value|
72
- options[key.to_s] = value
73
- end
74
- return options
75
- end
76
- end
77
- end
78
-
79
- module Rust::RBindings
80
- end