Class: Rust::ANOVAModel

Inherits:
RustDatatype show all
Defined in:
lib/rust/models/anova.rb

Overview

Mirror for an ANOVA model type in R. To create a new ANOVA model (aov), call the #generate method.

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from RustDatatype

pull_priority, #r_hash, #r_mirror, #r_mirror_to

Constructor Details

#initialize(model) ⇒ ANOVAModel

Creates a new model.



46
47
48
# File 'lib/rust/models/anova.rb', line 46

def initialize(model)
    @model = model
end

Class Method Details

.can_pull?(type, klass) ⇒ Boolean

Returns:

  • (Boolean)


9
10
11
# File 'lib/rust/models/anova.rb', line 9

def self.can_pull?(type, klass)
    return type == "list" && [klass].flatten.include?("aov")
end

.generate(formula, data, **options) ⇒ Object

Generates a new ANOVA model with a given formula, data. options can be specified and directly passed to the aov function in R.



27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/rust/models/anova.rb', line 27

def self.generate(formula, data, **options)
    mapped = ""
    if options.size > 0
        mapped = options.map { |k, v| "#{k}=#{v}" }.join(", ")
        mapped = ", " + mapped
    end
    
    Rust.exclusive do
        Rust["aov.data"] = data
        Rust._eval("aov.model.result <- aov(#{formula.to_R}, data=aov.data#{mapped})")
        result = ANOVAModel.new(Rust["aov.model.result"])
        result.r_mirror_to("aov.model.result")
        return result
    end
end

.pull_variable(variable, type, klass) ⇒ Object



13
14
15
16
17
# File 'lib/rust/models/anova.rb', line 13

def self.pull_variable(variable, type, klass)
    model = RustDatatype.pull_variable(variable, Rust::List)
    
    return ANOVAModel.new(model)
end

Instance Method Details

#load_in_r_as(variable_name) ⇒ Object



19
20
21
# File 'lib/rust/models/anova.rb', line 19

def load_in_r_as(variable_name)
    @model.load_in_r_as(variable_name)
end

#modelObject

Returns the model.



53
54
55
# File 'lib/rust/models/anova.rb', line 53

def model
    @model
end

#summaryObject

Returns a summary of the ANOVA model through the summary function in R.



60
61
62
63
64
65
66
67
68
69
# File 'lib/rust/models/anova.rb', line 60

def summary
    unless @summary
        Rust.exclusive do
            Rust._eval("aov.smr <- summary(#{self.r_mirror})")
            @summary = Rust['aov.smr']
        end
    end
    
    return @summary
end