Module: Rust::RBindings
- Defined in:
- lib/rust/core/rust.rb,
lib/rust/core/csv.rb,
lib/rust/plots/core.rb,
lib/rust/stats/tests.rb,
lib/rust/models/anova.rb,
lib/rust/stats/effsize.rb,
lib/rust/models/regression.rb,
lib/rust/stats/correlation.rb,
lib/rust/stats/descriptive.rb
Overview
Module that contains methods that allow to call R functions faster. Such methods have names resembling the ones available in R (e.g., cor, wilcox_test).
Instance Method Summary collapse
- #aov(formula, data, **options) ⇒ Object
- #boxplot(*args, **options) ⇒ Object
- #cliff_delta(d1, d2) ⇒ Object
- #cohen_d(d1, d2, **args) ⇒ Object
- #cor(d1, d2, **options) ⇒ Object
- #cor_test(d1, d2, **options) ⇒ Object
- #data_frame(*args) ⇒ Object
- #lm(formula, data, **options) ⇒ Object
- #lmer(formula, data, **options) ⇒ Object
- #mean(series) ⇒ Object
- #median(series) ⇒ Object
- #plot(x, y = (1..x.size).to_a, **options) ⇒ Object
- #quantile(series, percentiles = [0.0, 0.25, 0.5, 0.75, 1.0]) ⇒ Object
- #read_csv(filename, **options) ⇒ Object
- #sd(series) ⇒ Object
- #t_test(d1, d2, **args) ⇒ Object
- #var(series) ⇒ Object
- #wilcox_test(d1, d2, **args) ⇒ Object
- #write_csv(filename, dataframe, **options) ⇒ Object
Instance Method Details
#aov(formula, data, **options) ⇒ Object
74 75 76 |
# File 'lib/rust/models/anova.rb', line 74 def aov(formula, data, **) return ANOVAModel.generate(formula, data, **) end |
#boxplot(*args, **options) ⇒ Object
362 363 364 365 366 367 368 369 370 371 372 373 374 375 |
# File 'lib/rust/plots/core.rb', line 362 def boxplot(*args, **) result = Rust::Plots::BoxPlot.new .each do |k, v| result[k] = v end result. args.each do |s| result.series(s) end result.show end |
#cliff_delta(d1, d2) ⇒ Object
95 96 97 |
# File 'lib/rust/stats/effsize.rb', line 95 def cliff_delta(d1, d2) Rust::EffectSize::CliffDelta.compute(d1, d2) end |
#cohen_d(d1, d2, **args) ⇒ Object
99 100 101 |
# File 'lib/rust/stats/effsize.rb', line 99 def cohen_d(d1, d2, **args) Rust::EffectSize::CohenD.compute(d1, d2) end |
#cor(d1, d2, **options) ⇒ Object
159 160 161 |
# File 'lib/rust/stats/correlation.rb', line 159 def cor(d1, d2, **) return cor_test(d1, d2, **).correlation end |
#cor_test(d1, d2, **options) ⇒ Object
163 164 165 166 167 168 169 170 171 172 173 174 |
# File 'lib/rust/stats/correlation.rb', line 163 def cor_test(d1, d2, **) method = [:method].to_s.downcase if "pearson".start_with?(method) return Rust::Correlation::Pearson.test(d1, d2) elsif "spearman".start_with?(method) return Rust::Correlation::Spearman.test(d1, d2) elsif "kendall".start_with?(method) return Rust::Correlation::Kendall.test(d1, d2) else raise "Unsupported method #{method}" end end |
#data_frame(*args) ⇒ Object
199 200 201 |
# File 'lib/rust/core/rust.rb', line 199 def data_frame(*args) Rust::DataFrame.new(*args) end |
#lm(formula, data, **options) ⇒ Object
241 242 243 244 |
# File 'lib/rust/models/regression.rb', line 241 def lm(formula, data, **) independent = formula.right_part.split("+").map { |v| v.strip } return LinearRegressionModel.generate(formula.left_part, independent, data, **) end |
#lmer(formula, data, **options) ⇒ Object
246 247 248 249 250 251 252 253 254 255 256 257 |
# File 'lib/rust/models/regression.rb', line 246 def lmer(formula, data, **) independent = formula.right_part.split("+").map { |v| v.strip } RegressionModel.generate( LinearMixedEffectsModel, "lmer", formula.left_part, independent, data, ** ) end |
#mean(series) ⇒ Object
138 139 140 |
# File 'lib/rust/stats/descriptive.rb', line 138 def mean(series) Rust::Descriptive.mean(series) end |
#median(series) ⇒ Object
142 143 144 |
# File 'lib/rust/stats/descriptive.rb', line 142 def median(series) Rust::Descriptive.median(series) end |
#plot(x, y = (1..x.size).to_a, **options) ⇒ Object
350 351 352 353 354 355 356 357 358 359 360 |
# File 'lib/rust/plots/core.rb', line 350 def plot(x, y=(1..x.size).to_a, **) result = Rust::Plots::ScatterPlot.new(x, y) .each do |k, v| result[k] = v end result. result.show end |
#quantile(series, percentiles = [0.0, 0.25, 0.5, 0.75, 1.0]) ⇒ Object
154 155 156 |
# File 'lib/rust/stats/descriptive.rb', line 154 def quantile(series, percentiles = [0.0, 0.25, 0.5, 0.75, 1.0]) Rust::Descriptive.quantile(series, percentiles) end |
#read_csv(filename, **options) ⇒ Object
119 120 121 |
# File 'lib/rust/core/csv.rb', line 119 def read_csv(filename, **) Rust::CSV.read(filename, **) end |
#sd(series) ⇒ Object
150 151 152 |
# File 'lib/rust/stats/descriptive.rb', line 150 def sd(series) Rust::Descriptive.standard_deviation(series) end |
#t_test(d1, d2, **args) ⇒ Object
376 377 378 379 380 381 382 383 |
# File 'lib/rust/stats/tests.rb', line 376 def t_test(d1, d2, **args) paired = args[:paired] || false if paired return Rust::StatisticalTests::T.paired(d1, d2) else return Rust::StatisticalTests::T.unpaired(d1, d2) end end |
#var(series) ⇒ Object
146 147 148 |
# File 'lib/rust/stats/descriptive.rb', line 146 def var(series) Rust::Descriptive.variance(series) end |
#wilcox_test(d1, d2, **args) ⇒ Object
367 368 369 370 371 372 373 374 |
# File 'lib/rust/stats/tests.rb', line 367 def wilcox_test(d1, d2, **args) paired = args[:paired] || false if paired return Rust::StatisticalTests::Wilcoxon.paired(d1, d2) else return Rust::StatisticalTests::Wilcoxon.unpaired(d1, d2) end end |