Skip to main content

General-purpose linear mixed model solver (REML, BLUP, LMM).

Project description

pyreml

pyreml is a general-purpose linear mixed model solver. It fits linear mixed models for a wide range of applications: quantitative genetics, spatial statistics, health sciences, among others.

Models are fitted by direct differentiation of the Restricted Maximum Likelihood (REML), using PyTorch for variance parameter estimation. It benefits from PyTorch parallelization and GPU acceleration.

Installation

Install pyreml with pip or conda:

pip install pyreml

Main concepts

pyreml decomposes each random effect $\mathbf{a}$ (and the residual) with a Kronecker product:

$$ \mathbf{a} \sim \mathcal{N}(\mathbf{0}, \mathbf{G_a}), \qquad \mathbf{G_a} = \mathbf{\Sigma_a} \otimes \mathbf{K_a}, $$

where:

  • $\mathbf{\Sigma_a}$ is the left-hand factor, i.e. the covariance across the components of the effect

  • $\mathbf{K_a}$ is the right-hand factor, i.e. the covariance across its levels.

The two factors are set independently, through left_hand and right_hand arguments of the Random and Residual objects.

The philosophy behind this parameterization is to provide a simple, flexible and unified framework for a large variety of use cases.

pyreml natively supports multivariate (multiple response) analysis, random regression and heteroscedasticity specification using patsy idiom. Factor-analysis, i.e. the direct estimation of principal components of large $\mathbf{\Sigma_a}$, is also available.

pyreml also enables prediction of unobserved levels of a structured random effect, for instance in this geospatial analysis:

Kriging

Illustrative example

As an illustrative example, let's realize the genetic analysis of the larix dataset, using the genetic helpers provided by pyreml. This model provides a heteroscedastic structure to the residuals.

from pprint import pprint
from pyreml import (
    MixedModel,
    Random,
    Residual,
    A_pedigree,
    prepare_pedigree,
    larix as df,
)

df = df[df["year"] == 2000].copy()
ped = prepare_pedigree(df[["ID","SIRE","DAM"]])
K = A_pedigree(ped)

model = MixedModel.from_dataframe(
    data     = df,
    response = "height",
    fixed    = "1 + C(BLOC)",
    random   = Random(
        formula      = "1",
        unit         = "ID",
        right_hand   = "str",
        covariance   = K,
        matrix_index = ped["id"].tolist(),
    ),
    residual = Residual(
        right_hand = "het",
        het_formula = "1 + C(BLOC)",
    ),
    device = "cuda",
)

model.fit()

pprint(model.random[0].variance)
pprint(model.residual.variance)
model.random[0].table.head()

Documentation

The documentation is available at this address.

Citation

Please cite this package as:

Marchal, A., & Raimondi, D. (2026). pyreml - general-purpose linear mixed model solver [Computer software]. Zenodo. https://doi.org/10.5281/zenodo.20826541

Code

The code is available at this address.

License

Copyright © 2026 CNRS, University of Montpellier

This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with this program. If not, see https://www.gnu.org/licenses/.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

pyreml-0.1.0.tar.gz (52.5 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

pyreml-0.1.0-py3-none-any.whl (43.3 kB view details)

Uploaded Python 3

File details

Details for the file pyreml-0.1.0.tar.gz.

File metadata

  • Download URL: pyreml-0.1.0.tar.gz
  • Upload date:
  • Size: 52.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.5

File hashes

Hashes for pyreml-0.1.0.tar.gz
Algorithm Hash digest
SHA256 4955de9c7c52c54a3440c7c78074f5bf24fe000105cbd506b10da7b8f30a72d2
MD5 983d695cee625a56529f1ab8fbae39e5
BLAKE2b-256 1398df802f92d0beca3e9f3b42f88839c5f64fb529f1db4327a94b1c0c5ca9b5

See more details on using hashes here.

File details

Details for the file pyreml-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: pyreml-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 43.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.5

File hashes

Hashes for pyreml-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 d89fd08b3f584b1022a525212d09873aecdc5da724639d48e29e5204d6233bae
MD5 fd2d8037e9aa6dd2436b5352de0cef00
BLAKE2b-256 b75df95c7d0778ed5f5d4efab9e7687fe31d6ce0acdad558c1c536dfadbd11f2

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page