• Stars
    star
    402
  • Rank 107,380 (Top 3 %)
  • Language
    Julia
  • License
    MIT License
  • Created over 11 years ago
  • Updated 3 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

A Julia package for fitting (statistical) mixed-effects models

Mixed-effects models in Julia

Documentation Citation Build Status Code Coverage Style Guide
Stable Docs Dev Docs DOI Julia Current Julia Minimum Supported Version Julia Nightly PkgEval CodeCov Code Style: Blue

This package defines linear mixed models (LinearMixedModel) and generalized linear mixed models (GeneralizedLinearMixedModel). Users can use the abstraction for statistical model API to build, fit (fit/fit!), and query the fitted models.

A mixed-effects model is a statistical model for a response variable as a function of one or more covariates. For a categorical covariate the coefficients associated with the levels of the covariate are sometimes called effects, as in "the effect of using Treatment 1 versus the placebo". If the potential levels of the covariate are fixed and reproducible, e.g. the levels for Sex could be "F" and "M", they are modeled with fixed-effects parameters. If the levels constitute a sample from a population, e.g. the Subject or the Item at a particular observation, they are modeled as random effects.

A mixed-effects model contains both fixed-effects and random-effects terms.

With fixed-effects it is the coefficients themselves or combinations of coefficients that are of interest. For random effects it is the variability of the effects over the population that is of interest.

In this package random effects are modeled as independent samples from a multivariate Gaussian distribution of the form 𝓑 ~ 𝓝(0, 𝚺). For the response vector, 𝐲, only the mean of conditional distribution, 𝓨|𝓑 = 𝐛 depends on 𝐛 and it does so through a linear predictor expression, 𝛈 = 𝐗𝛃 + 𝐙𝐛, where 𝛃 is the fixed-effects coefficient vector and 𝐗 and 𝐙 are model matrices of the appropriate sizes,

In a LinearMixedModel the conditional mean, 𝛍 = 𝔼[𝓨|𝓑 = 𝐛], is the linear predictor, 𝛈, and the conditional distribution is multivariate Gaussian, (𝓨|𝓑 = 𝐛) ~ 𝓝(𝛍, σ²𝐈).

In a GeneralizedLinearMixedModel, the conditional mean, 𝔼[𝓨|𝓑 = 𝐛], is related to the linear predictor via a link function. Typical distribution forms are Bernoulli for binary data or Poisson for count data.

Currently Tested Platforms

OS OS Version Arch Julia
Linux Ubuntu 20.04 x64 v1.8
Linux Ubuntu 20.04 x64 current release
Linux Ubuntu 20.04 x64 nightly
macOS Catalina 10.15 x64 v1.8
Windows Server 2019 x64 v1.8

Note that previous releases still support older Julia versions.

Version 4.0.0

Version 4.0.0 contains some user-visible changes and many changes in the underlying code.

Please see NEWS for a complete overview, but a few key points are:

  • The internal storage of the model matrices in LinearMixedModel has changed and been optimized. This change should be transparent to users who are not manipulating the fields of the model struct directly.
  • The handling of rank deficiency continues to evolve.
  • Additional predict and simulate methods have been added for generalizing to new data.
  • saveoptsum and restoreoptsum! provide for saving and restoring the optsum and thus offer a way to serialize a model fit.
  • There is improved support for the runtime construction of model formula, especially RandomEffectsTerms and nested terms (methods for Base.|(::AbstractTerm, ::AbstractTerm) and Base./(::AbstractTerm, ::AbstractTerm)).
  • A progress display is shown by default for models taking more than a few hundred milliseconds to fit. This can be disabled with the keyword argument progress=false.

Quick Start

julia> using MixedModels

julia> m1 = fit(MixedModel, @formula(yield ~ 1 + (1|batch)), MixedModels.dataset(:dyestuff))
Linear mixed model fit by maximum likelihood
 yield ~ 1 + (1 | batch)
   logLik   -2 logLik     AIC       AICc        BIC
  -163.6635   327.3271   333.3271   334.2501   337.5307

Variance components:
            Column    Variance Std.Dev.
batch    (Intercept)  1388.3332 37.2603
Residual              2451.2501 49.5101
 Number of obs: 30; levels of grouping factors: 6

  Fixed-effects parameters:
────────────────────────────────────────────────
              Coef.  Std. Error      z  Pr(>|z|)
────────────────────────────────────────────────
(Intercept)  1527.5     17.6946  86.33    <1e-99
────────────────────────────────────────────────

julia> using Random

julia> bs = parametricbootstrap(MersenneTwister(42), 1000, m1);
Progress: 100%%|████████████████████████████████████████████████| Time: 0:00:00

julia> propertynames(bs)
13-element Vector{Symbol}:
 :allpars
 :objective
 :σ
 :β
 :se
 :coefpvalues
 :θ
 :σs
 :λ
 :inds
 :lowerbd
 :fits
 :fcnames

julia> bs.coefpvalues # returns a row table
1000-element Vector{NamedTuple{(:iter, :coefname, :β, :se, :z, :p), Tuple{Int64, Symbol, Float64, Float64, Float64, Float64}}}:
 (iter = 1, coefname = Symbol("(Intercept)"), β = 1517.0670832927115, se = 20.76271142094811, z = 73.0669059804057, p = 0.0)
 (iter = 2, coefname = Symbol("(Intercept)"), β = 1503.5781855888436, se = 8.1387737362628, z = 184.7425956676446, p = 0.0)
 (iter = 3, coefname = Symbol("(Intercept)"), β = 1529.2236379016574, se = 16.523824785737837, z = 92.54659001356465, p = 0.0)
 ⋮
 (iter = 998, coefname = Symbol("(Intercept)"), β = 1498.3795009457242, se = 25.649682012258104, z = 58.417079019913054, p = 0.0)
 (iter = 999, coefname = Symbol("(Intercept)"), β = 1526.1076747922416, se = 16.22412120273579, z = 94.06411945042063, p = 0.0)
 (iter = 1000, coefname = Symbol("(Intercept)"), β = 1557.7546433870125, se = 12.557577103806015, z = 124.04898098653763, p = 0.0)

julia> using DataFrames

julia> DataFrame(bs.coefpvalues) # puts it into a DataFrame
1000×6 DataFrame
│ Row  │ iter  │ coefname    │ β       │ se      │ z       │ p       │
│      │ Int64 │ Symbol      │ Float64 │ Float64 │ Float64 │ Float64 │
├──────┼───────┼─────────────┼─────────┼─────────┼─────────┼─────────┤
│ 1    │ 1     │ (Intercept) │ 1517.07 │ 20.7627 │ 73.0669 │ 0.0     │
│ 2    │ 2     │ (Intercept) │ 1503.58 │ 8.13877 │ 184.743 │ 0.0     │
│ 3    │ 3     │ (Intercept) │ 1529.22 │ 16.5238 │ 92.5466 │ 0.0     │
⋮
│ 998  │ 998   │ (Intercept) │ 1498.38 │ 25.6497 │ 58.4171 │ 0.0     │
│ 999  │ 999   │ (Intercept) │ 1526.11 │ 16.2241 │ 94.0641 │ 0.0     │
│ 1000 │ 1000  │ (Intercept) │ 1557.75 │ 12.5576 │ 124.049 │ 0.0     │

julia> DataFrame(bs.β)
1000×3 DataFrame
│ Row  │ iter  │ coefname    │ β       │
│      │ Int64 │ Symbol      │ Float64 │
├──────┼───────┼─────────────┼─────────┤
│ 1    │ 1     │ (Intercept) │ 1517.07 │
│ 2    │ 2     │ (Intercept) │ 1503.58 │
│ 3    │ 3     │ (Intercept) │ 1529.22 │
⋮
│ 998  │ 998   │ (Intercept) │ 1498.38 │
│ 999  │ 999   │ (Intercept) │ 1526.11 │
│ 1000 │ 1000  │ (Intercept) │ 1557.75 │

Funding Acknowledgement

The development of this package was supported by the Center for Interdisciplinary Research, Bielefeld (ZiF)/Cooperation Group "Statistical models for psychological and linguistic data".

More Repositories

1

Distributions.jl

A Julia package for probability distributions and associated functions.
Julia
1,073
star
2

GLM.jl

Generalized linear models in Julia
Julia
574
star
3

StatsBase.jl

Basic statistics for Julia
Julia
565
star
4

Distances.jl

A Julia package for evaluating distances (metrics) between vectors.
Julia
410
star
5

MultivariateStats.jl

A Julia package for multivariate statistics and data analysis (e.g. dimension reduction)
Julia
370
star
6

Clustering.jl

A Julia package for data clustering
Julia
343
star
7

TimeSeries.jl

Time series toolkit for Julia
Julia
342
star
8

HypothesisTests.jl

Hypothesis tests for Julia
Julia
287
star
9

StatsModels.jl

Specifying, fitting, and evaluating statistical models in Julia
Julia
245
star
10

StatsFuns.jl

Mathematical functions related to statistics.
Julia
224
star
11

MLBase.jl

A set of functions to support the development of machine learning algorithms
Julia
186
star
12

KernelDensity.jl

Kernel density estimators for Julia
Julia
169
star
13

Klara.jl

MCMC inference in Julia
Julia
168
star
14

RDatasets.jl

Julia package for loading many of the data sets available in R
R
160
star
15

Lasso.jl

Lasso/Elastic Net linear and generalized linear models
Julia
141
star
16

StatsKit.jl

Convenience meta-package to load essential packages for statistics
Julia
136
star
17

PDMats.jl

Uniform Interface for positive definite matrices of various structures
Julia
103
star
18

Loess.jl

Local regression, so smooooth!
Julia
99
star
19

GLMNet.jl

Julia wrapper for fitting Lasso/ElasticNet GLM models using glmnet
Julia
96
star
20

NMF.jl

A Julia package for non-negative matrix factorization
Julia
89
star
21

Survival.jl

Survival analysis in Julia
Julia
73
star
22

LogExpFunctions.jl

Julia package for various special functions based on `log` and `exp`.
Julia
73
star
23

Statistics.jl

The Statistics stdlib that ships with Julia.
Julia
69
star
24

TimeModels.jl

Modeling time series in Julia
Julia
57
star
25

DataArrays.jl

DEPRECATED: Data structures that allow missing values
Julia
53
star
26

PGM.jl

A Julia framework for probabilistic graphical models.
Julia
52
star
27

ConjugatePriors.jl

A Julia package to support conjugate prior distributions.
Julia
46
star
28

SVM.jl

SVM's for Julia
Julia
41
star
29

Roadmap.jl

A centralized location for planning the direction of JuliaStats
35
star
30

NullableArrays.jl

DEPRECATED Prototype of the new JuliaStats NullableArrays package
Julia
35
star
31

Distance.jl

Julia module for Distance evaluation
Julia
27
star
32

DimensionalityReduction.jl

Deprecated in favor of MultivariateStats.jl
Julia
27
star
33

Rmath-julia

The Rmath library from R
C
25
star
34

RegERMs.jl

DEPRECATED: Regularised Empirical Risk Minimisation Framework (SVMs, LogReg, Linear Regression) in Julia
Julia
17
star
35

StatsAPI.jl

A statistics-focused namespace for packages to share functions
Julia
17
star
36

Rmath.jl

Archive of functions that emulate R's d-p-q-r functions for probability distributions
Julia
16
star
37

JuliaStats.github.io

The home page of JuliaStats
CSS
11
star
38

NullableStats.jl

DEPRECATED: Statistical functionality for NullableArrays
Julia
4
star
39

RmathBuilder

Builder repository for rmath-julia
Julia
3
star
40

RmathDist.jl

Julia interface to Rmath distribution functions
Julia
3
star