mixed_models
Fit statistical (linear) models with fixed and mixed (random) effects in Ruby.
Features
Linear mixed models
-
Support for the formula language of the
R
packagelme4
makes model specification convenient and user friendly. An expanation of thelme4
formula interface can be found in thelme4
vignette, or on stackexchange (example). Types of linear mixed models that can be fit bymixed_models
with the formula interface include:- Models with interaction fixed or random effects (e.g.
y ~ x + z + x:z + (x + z + x:z | g)
), - Models with multiple crossed random effects (e.g.
y ~ x + (x|g) + (x|h)
), - Models with nested random effects (e.g.
y ~ x + (x|g) + (x|g:h)
).
- Models with interaction fixed or random effects (e.g.
-
Flexible model specification capabilities with the possibility to pass the random effects covariance structure as a
Proc
, when fitting a model from raw madel matrices. -
Possibility of singular fits (i.e models with random effects variance equal to zero).
-
Likelihood ratio test for nested models (Chi squared or bootstrap based).
-
Many types of hypotheses tests for the fixed and random effects (based on LRT, bootstrap or the Wald Z statistic).
-
Four types of bootstrap confidence intervals for the fixed effects coefficient estimates, as well as Wald Z confidence intervals. All bootstrap based methods are performed in parallel by default.
-
Prediction on new data and prediction intervals.
Installation
To install the latest stable version:
$ gem install mixed_models
Alternatively, you can add the line gem 'mixed_models'
to your application's Gemfile, and then execute:
$ bundle
Ruby is required in version >=2.0 because keyword arguments are excessively used in mixed_models
.
Usage
Linear mixed models (LMM) tutorials
-
Fitting a linear mixed model, accessing the estimated parameters, and assessing the quality of the model fit (to some extent)
Analysis of real data
-
This IRuby notebook shows an application of
mixed_models
to real data, which originate from blog posts from various sources in 2010-2012. The analyzed data set is of nontrivial size (~50000x300) and nontrivial structure (redundant variables, missing values, data transformations, etc.).
More usage examples
Some other examples in form of Ruby code can be found in the examples folder.
Further examples can be found in several BLOG posts (see below).
Some relevant BLOG posts
-
Wald p-values and confidence intervals for fixed effects coefficients
-
Fitting linear mixed models with a user-friendly R-formula-like interface
-
A rudimentary linear mixed models fit from raw matrices and vectors
Development
The development version of mixed_models
can be installed using the command line:
git clone https://github.com/agisga/mixed_models.git
cd mixed_models/
bundle install
bundle exec rake install
The automatic tests can be run with bundle exec rspec spec
.
Contributing
- Fork it ( https://github.com/[my-github-username]/mixed_models/fork )
- Create your feature branch (
git checkout -b my-new-feature
) - Commit your changes (
git commit -am 'Add some feature'
) - Push to the branch (
git push origin my-new-feature
) - Create a new Pull Request