rust 0.2 → 0.3

Sign up to get free protection for your applications and to get access to all the features.
@@ -41,14 +41,14 @@ module Rust::StatisticalTests::Wilcoxon
41
41
  raise "The two distributions have different size" if d1.size != d2.size
42
42
 
43
43
  Rust.exclusive do
44
- Rust::R_ENGINE.a = d1
45
- Rust::R_ENGINE.b = d2
44
+ Rust["wilcox.a"] = d1
45
+ Rust["wilcox.b"] = d2
46
46
 
47
- _, warnings = Rust._eval("result = wilcox.test(a, b, alternative='two.sided', paired=T)", true)
47
+ _, warnings = Rust._eval("wilcox.result = wilcox.test(wilcox.a, wilcox.b, alternative='two.sided', paired=T)", true)
48
48
  result = Rust::StatisticalTests::Result.new
49
49
  result.name = "Wilcoxon Signed-Rank test"
50
- result.pvalue = Rust._pull("result$p.value")
51
- result[:w] = Rust._pull("result$statistic")
50
+ result.pvalue = Rust._pull("wilcox.result$p.value")
51
+ result[:w] = Rust._pull("wilcox.result$statistic")
52
52
  result.exact = !warnings.include?("cannot compute exact p-value with zeroes")
53
53
  result.alpha = alpha
54
54
 
@@ -61,14 +61,14 @@ module Rust::StatisticalTests::Wilcoxon
61
61
  raise TypeError, "Expecting Array of numerics" if !d2.is_a?(Array) || !d2.all? { |e| e.is_a?(Numeric) }
62
62
 
63
63
  Rust.exclusive do
64
- Rust::R_ENGINE.a = d1
65
- Rust::R_ENGINE.b = d2
64
+ Rust["wilcox.a"] = d1
65
+ Rust["wilcox.b"] = d2
66
66
 
67
- _, warnings = Rust._eval("result = wilcox.test(a, b, alternative='two.sided', paired=F)", true)
67
+ _, warnings = Rust._eval("wilcox.result = wilcox.test(wilcox.a, wilcox.b, alternative='two.sided', paired=F)", true)
68
68
  result = Rust::StatisticalTests::Result.new
69
69
  result.name = "Wilcoxon Ranked-Sum test (a.k.a. Mann–Whitney U test)"
70
- result.pvalue = Rust._pull("result$p.value")
71
- result[:w] = Rust._pull("result$statistic")
70
+ result.pvalue = Rust._pull("wilcox.result$p.value")
71
+ result[:w] = Rust._pull("wilcox.result$statistic")
72
72
  result.exact = !warnings.include?("cannot compute exact p-value with ties")
73
73
  result.alpha = alpha
74
74
 
@@ -86,14 +86,14 @@ module Rust::StatisticalTests::T
86
86
  raise "The two distributions have different size" if d1.size != d2.size
87
87
 
88
88
  Rust.exclusive do
89
- Rust::R_ENGINE.a = d1
90
- Rust::R_ENGINE.b = d2
89
+ Rust["t.a"] = d1
90
+ Rust["t.b"] = d2
91
91
 
92
- warnings = Rust._eval("result = t.test(a, b, alternative='two.sided', paired=T)")
92
+ warnings = Rust._eval("t.result = t.test(t.a, t.b, alternative='two.sided', paired=T)")
93
93
  result = Rust::StatisticalTests::Result.new
94
94
  result.name = "Paired t-test"
95
- result.pvalue = Rust._pull("result$p.value")
96
- result[:t] = Rust._pull("result$statistic")
95
+ result.pvalue = Rust._pull("t.result$p.value")
96
+ result[:t] = Rust._pull("t.result$statistic")
97
97
  result.exact = true
98
98
  result.alpha = alpha
99
99
 
@@ -106,14 +106,14 @@ module Rust::StatisticalTests::T
106
106
  raise TypeError, "Expecting Array of numerics" if !d2.is_a?(Array) || !d2.all? { |e| e.is_a?(Numeric) }
107
107
 
108
108
  Rust.exclusive do
109
- Rust::R_ENGINE.a = d1
110
- Rust::R_ENGINE.b = d2
109
+ Rust["t.a"] = d1
110
+ Rust["t.b"] = d2
111
111
 
112
- Rust._eval("result = t.test(a, b, alternative='two.sided', paired=F)")
112
+ Rust._eval("t.result = t.test(t.a, t.b, alternative='two.sided', paired=F)")
113
113
  result = Rust::StatisticalTests::Result.new
114
114
  result.name = "Welch Two Sample t-test"
115
- result.pvalue = Rust._pull("result$p.value")
116
- result[:t] = Rust._pull("result$statistic")
115
+ result.pvalue = Rust._pull("t.result$p.value")
116
+ result[:t] = Rust._pull("t.result$statistic")
117
117
  result.exact = true
118
118
  result.alpha = alpha
119
119
 
@@ -123,6 +123,27 @@ module Rust::StatisticalTests::T
123
123
  end
124
124
  end
125
125
 
126
+ module Rust::StatisticalTests::Shapiro
127
+ class << self
128
+ def compute(vector, alpha = 0.05)
129
+ raise TypeError, "Expecting Array of numerics" if !vector.is_a?(Array) || !vector.all? { |e| e.is_a?(Numeric) }
130
+ Rust.exclusive do
131
+ Rust['shapiro.v'] = vector
132
+
133
+ Rust._eval("shapiro.result = shapiro.test(shapiro.v)")
134
+ result = Rust::StatisticalTests::Result.new
135
+ result.name = "Shapiro-Wilk normality test"
136
+ result.pvalue = Rust._pull("shapiro.result$p.value")
137
+ result[:W] = Rust._pull("shapiro.result$statistic")
138
+ result.exact = true
139
+ result.alpha = alpha
140
+
141
+ return result
142
+ end
143
+ end
144
+ end
145
+ end
146
+
126
147
  module Rust::RBindings
127
148
  def wilcox_test(d1, d2, **args)
128
149
  paired = args[:paired] || false
@@ -1,3 +1,8 @@
1
+ require_relative 'rust-core'
2
+ require_relative 'rust-basics'
3
+ require_relative 'rust-csv'
1
4
  require_relative 'rust-tests'
2
5
  require_relative 'rust-effsize'
3
6
  require_relative 'rust-descriptive'
7
+ require_relative 'rust-plots'
8
+ require_relative 'rust-calls'
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.2'
4
+ version: '0.3'
5
5
  platform: ruby
6
6
  authors:
7
7
  - Simone Scalabrino
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-09-05 00:00:00.000000000 Z
11
+ date: 2020-09-13 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rinruby
@@ -56,9 +56,13 @@ executables: []
56
56
  extensions: []
57
57
  extra_rdoc_files: []
58
58
  files:
59
+ - lib/rust-basics.rb
60
+ - lib/rust-calls.rb
59
61
  - lib/rust-core.rb
62
+ - lib/rust-csv.rb
60
63
  - lib/rust-descriptive.rb
61
64
  - lib/rust-effsize.rb
65
+ - lib/rust-plots.rb
62
66
  - lib/rust-tests.rb
63
67
  - lib/rust.rb
64
68
  homepage: https://github.com/intersimone999/ruby-rust