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,
lib/rust/external/robustbase.rb,
lib/rust/external/ggplot2/core.rb,
lib/rust/external/ggplot2/geoms.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

Instance Method Details

#adjbox(*args, **options) ⇒ Object



30
31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/rust/external/robustbase.rb', line 30

def adjbox(*args, **options)
    result = Rust::Plots::AdjustedBoxplot.new
    options.each do |k, v|
        result[k] = v
    end
    
    result._do_not_override_options!
    
    args.each do |s|
        result.series(s)
    end
    
    result.show
end

#aes(**options) ⇒ Object



155
156
157
# File 'lib/rust/external/ggplot2/core.rb', line 155

def aes(**options)
    Rust::Plots::GGPlot::Aes.new(**options)
end

#aov(formula, data, **options) ⇒ Object



74
75
76
# File 'lib/rust/models/anova.rb', line 74

def aov(formula, data, **options)
    return ANOVAModel.generate(formula, data, **options)
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, **options)
    result = Rust::Plots::BoxPlot.new
    options.each do |k, v|
        result[k] = v
    end
    
    result._do_not_override_options!
    
    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

#coord_flip(**options) ⇒ Object



164
165
166
# File 'lib/rust/external/ggplot2/core.rb', line 164

def coord_flip(**options)
    Rust::Plots::GGPlot::FlipCoordinates.new(**options)
end

#cor(d1, d2, **options) ⇒ Object



159
160
161
# File 'lib/rust/stats/correlation.rb', line 159

def cor(d1, d2, **options)
    return cor_test(d1, d2, **options).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, **options)
    method = options[: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

#geom_bar(*arguments, **options) ⇒ Object



68
69
70
# File 'lib/rust/external/ggplot2/geoms.rb', line 68

def geom_bar(*arguments, **options)
    return Rust::Plots::GGPlot::GeomBar.new(*arguments, **options)
end

#geom_boxplot(*arguments, **options) ⇒ Object



72
73
74
# File 'lib/rust/external/ggplot2/geoms.rb', line 72

def geom_boxplot(*arguments, **options)
    return Rust::Plots::GGPlot::GeomBoxplot.new(*arguments, **options)
end

#geom_col(*arguments, **options) ⇒ Object



64
65
66
# File 'lib/rust/external/ggplot2/geoms.rb', line 64

def geom_col(*arguments, **options)
    return Rust::Plots::GGPlot::GeomCol.new(*arguments, **options)
end

#geom_density(*arguments, **options) ⇒ Object



80
81
82
# File 'lib/rust/external/ggplot2/geoms.rb', line 80

def geom_density(*arguments, **options)
    return Rust::Plots::GGPlot::GeomDensity.new(*arguments, **options)
end

#geom_histogram(*arguments, **options) ⇒ Object



76
77
78
# File 'lib/rust/external/ggplot2/geoms.rb', line 76

def geom_histogram(*arguments, **options)
    return Rust::Plots::GGPlot::GeomHistogram.new(*arguments, **options)
end

#geom_line(*arguments, **options) ⇒ Object



60
61
62
# File 'lib/rust/external/ggplot2/geoms.rb', line 60

def geom_line(*arguments, **options)
    return Rust::Plots::GGPlot::GeomLine.new(*arguments, **options)
end

#geom_point(*arguments, **options) ⇒ Object



56
57
58
# File 'lib/rust/external/ggplot2/geoms.rb', line 56

def geom_point(*arguments, **options)
    return Rust::Plots::GGPlot::GeomPoint.new(*arguments, **options)
end

#ggplot(*arguments) ⇒ Object



151
152
153
# File 'lib/rust/external/ggplot2/core.rb', line 151

def ggplot(*arguments)
    Rust::Plots::GGPlot::Plot.new(*arguments)
end

#labs(**options) ⇒ Object Also known as: labels



159
160
161
# File 'lib/rust/external/ggplot2/core.rb', line 159

def labs(**options)
    Rust::Plots::GGPlot::Labels.new(**options)
end

#lm(formula, data, **options) ⇒ Object



241
242
243
244
# File 'lib/rust/models/regression.rb', line 241

def lm(formula, data, **options)
    independent = formula.right_part.split("+").map { |v| v.strip }
    return LinearRegressionModel.generate(formula.left_part, independent, data, **options)
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, **options)
    independent = formula.right_part.split("+").map { |v| v.strip }
    
    RegressionModel.generate(
        LinearMixedEffectsModel,
        "lmer", 
        formula.left_part, 
        independent, 
        data,
        **options
    )
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, **options)
    result = Rust::Plots::ScatterPlot.new(x, y)
    
    options.each do |k, v|
        result[k] = v
    end
    
    result._do_not_override_options!
    
    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, **options)
    Rust::CSV.read(filename, **options)
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

#write_csv(filename, dataframe, **options) ⇒ Object



123
124
125
# File 'lib/rust/core/csv.rb', line 123

def write_csv(filename, dataframe, **options)
    Rust::CSV.write(filename, dataframe, **options)
end