Class: Rust::Models::Regression::LinearMixedEffectsModel
- Inherits:
-
RegressionModel
- Object
- RustDatatype
- RegressionModel
- Rust::Models::Regression::LinearMixedEffectsModel
- 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
- .can_pull?(type, klass) ⇒ Boolean
-
.generate(dependent_variable, fixed_effects, random_effects, data, **options) ⇒ Object
Generates a linear mixed effects model, given its
dependent_variableandindependent_variablesand itsdata. - .pull_priority ⇒ Object
- .pull_variable(variable, type, klass) ⇒ Object
- .r_model_name ⇒ Object
Instance Method Summary collapse
Methods inherited from RegressionModel
#actuals, #backward_selection, #coefficients, #fitted, #initialize, #load_in_r_as, #method_missing, #model, #mse, #predict, #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
311 312 313 |
# File 'lib/rust/models/regression.rb', line 311 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.
346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 |
# File 'lib/rust/models/regression.rb', line 346 def self.generate(dependent_variable, fixed_effects, random_effects, data, **) 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, ** ) end |
.pull_priority ⇒ Object
315 316 317 |
# File 'lib/rust/models/regression.rb', line 315 def self.pull_priority 1 end |
.pull_variable(variable, type, klass) ⇒ Object
323 324 325 326 327 |
# File 'lib/rust/models/regression.rb', line 323 def self.pull_variable(variable, type, klass) model = Rust::RustDatatype.pull_variable(variable, Rust::S4Class) return LinearMixedEffectsModel.new(model) end |
.r_model_name ⇒ Object
319 320 321 |
# File 'lib/rust/models/regression.rb', line 319 def self.r_model_name "lmerModLmerTest" end |
Instance Method Details
#r_2 ⇒ Object
362 363 364 365 366 367 |
# File 'lib/rust/models/regression.rb', line 362 def r_2 Rust.exclusive do Rust._eval("tmp.rsq <- rsq(#{self.r_mirror}, adj=F)") return Rust['tmp.rsq'] end end |
#r_2_adjusted ⇒ Object
369 370 371 372 373 374 |
# File 'lib/rust/models/regression.rb', line 369 def r_2_adjusted Rust.exclusive do Rust._eval("tmp.rsq <- rsq(#{self.r_mirror}, adj=T)") return Rust['tmp.rsq'] end end |
#summary ⇒ Object
329 330 331 332 333 334 335 336 337 338 339 340 |
# File 'lib/rust/models/regression.rb', line 329 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 |