Class: Rust::Models::Regression::LinearMixedEffectsModel

Inherits:
RegressionModel show all
Defined in:
lib/rust/models/regression.rb

Overview

Represents a linear mixed effects model in R.

Instance Attribute Summary

Attributes inherited from RegressionModel

#data, #dependent_variable, #options

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from RegressionModel

#actuals, #backward_selection, #coefficients, #fitted, #initialize, #load_in_r_as, #method_missing, #model, #mse, #r_hash, #residuals, #significant_variables, #variables

Methods inherited from RustDatatype

#load_in_r_as, #r_hash, #r_mirror, #r_mirror_to

Constructor Details

This class inherits a constructor from Rust::Models::Regression::RegressionModel

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class Rust::Models::Regression::RegressionModel

Class Method Details

.can_pull?(type, klass) ⇒ Boolean

Returns:

  • (Boolean)


250
251
252
# File 'lib/rust/models/regression.rb', line 250

def self.can_pull?(type, klass)
    return type == "S4" && klass == self.r_model_name
end

.generate(dependent_variable, fixed_effects, random_effects, data, **options) ⇒ Object

Generates a linear mixed effects model, given its dependent_variable and independent_variables and its data. options can be specified and directly passed to the model.



285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
# File 'lib/rust/models/regression.rb', line 285

def self.generate(dependent_variable, fixed_effects, random_effects, data, **options)
    Rust.prerequisite("lmerTest")
    Rust.prerequisite("rsq")
    
    random_effects = random_effects.map { |effect| "(1|#{effect})" }
    
    RegressionModel.generate(
        LinearMixedEffectsModel,
        self.r_model_name, 
        dependent_variable, 
        fixed_effects + random_effects, 
        data, 
        **options
    )
end

.pull_priorityObject



254
255
256
# File 'lib/rust/models/regression.rb', line 254

def self.pull_priority
    1
end

.pull_variable(variable, type, klass) ⇒ Object



262
263
264
265
266
# File 'lib/rust/models/regression.rb', line 262

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

.r_model_nameObject



258
259
260
# File 'lib/rust/models/regression.rb', line 258

def self.r_model_name
    "lmerModLmerTest"
end

Instance Method Details

#r_2Object



301
302
303
304
305
306
# File 'lib/rust/models/regression.rb', line 301

def r_2
    Rust.exclusive do
        Rust._eval("tmp.rsq <- rsq(#{self.r_mirror}, adj=F)")
        return Rust['tmp.rsq']
    end
end

#r_2_adjustedObject



308
309
310
311
312
313
# File 'lib/rust/models/regression.rb', line 308

def r_2_adjusted
    Rust.exclusive do
        Rust._eval("tmp.rsq <- rsq(#{self.r_mirror}, adj=T)")
        return Rust['tmp.rsq']
    end
end

#summaryObject



268
269
270
271
272
273
274
275
276
277
278
279
# File 'lib/rust/models/regression.rb', line 268

def summary
    unless @summary
        Rust.exclusive do
            Rust._eval("tmp.summary <- summary(#{self.r_mirror})")
            Rust._eval("mode(tmp.summary$objClass) <- \"list\"")
            Rust._eval("tmp.summary$logLik <- attributes(tmp.summary$logLik)")
            @summary = Rust["tmp.summary"]
        end
    end
    
    return @summary
end