Learn R Programming

⚠️There's a newer version (4.5.27) of this package.Take me there.

sommer: Solving Mixed Model Equations in R

Structural multivariate-univariate linear mixed model solver for estimation of multiple random effects with unknown variance-covariance structures and known covariance among levels of random effects (e.g., pedigree and genomic relationship matrices) (Covarrubias-Pazaran, 2016; Maier et al., 2015; Jensen et al., 1997). REML estimates can be obtained using the Direct-Inversion Newton-Raphson and Direct-Inversion Average Information algorithms for the problems r x r (r being the number of records) or using the Henderson-based average information algorithm for the problem c x c (c being the number of coefficients to estimate). Spatial models can also be fitted using the two-dimensional spline functionality available.

Installation

You can install the development version of sommer from GitHub:

remotes::install_github('covaruber/sommer')

A first mixed model

Fit environment means and a random genotype effect, then obtain genotype predictions with their uncertainty:

library(sommer)
data("DT_example", package = "enhancer")

fit <- mmes(
  Yield ~ Env,
  random = ~ Name,
  data = DT_example,
  control = mmes_control(
    output = list(inverse = 2),
    diagnostics = list(verbose = FALSE, dateWarning = FALSE)
  )
)

summary(fit)
genotypes <- predict(fit, D = "Name")
head(genotypes$pvals)

Check fit$convergence before interpreting a fit. The explicit inverse request above makes coefficient uncertainty available; retaining a full inverse is appropriate for this small example, not a default recommendation for large models.

Choose the next step

Start with the default deterministic Henderson formulation. Use direct inversion when observation-space fitting suits the problem; use PCG only with its stochastic accuracy controls and diagnostics in mind. GPU support is optional.

Optional GPU Kernels

The Henderson solver uses one implementation for CPU and optional CUDA dense kernels. CPU is the default. Package startup checks NVIDIA hardware first, then CUDA readiness, and reports whether GPU use can be enabled.

On Linux, install a compatible NVIDIA driver and CUDA toolkit, then build from source:

SOMMER_CUDA_HOME=/path/to/cuda R CMD INSTALL --preclean .

Enable eligible kernels globally with options(sommer.mme.gpu = TRUE), or pass control = mmes_control(execution = list(gpu = TRUE, gpuMinSize = 256L)) to mmes(). Set gpu = FALSE in control$execution to override the global option. The threshold also defaults from options(sommer.mme.gpuMinSize = 256L).

CUDA runtime, cuBLAS, and cuSOLVER libraries load dynamically. CPU fitting does not require them, even in a CUDA-enabled build. Explicit GPU requests stop when unavailable. Only eligible dense kernels are accelerated; sparse work remains on CPU, and transfers can outweigh gains. Direct formulation and solve-only tasks remain CPU-only. See ?mmes and ?mmes_control for requirements and the gpuDiagnostics counters.

Direct-inversion fitting

Use mmes(..., control = mmes_control(formulation = "direct")) for the dense observation-level covariance engine. AI is the default, with on-demand EM/GEM recovery after unreliable information solves, exhausted line searches, or repeated poor progress. Configure recovery with update = list(recovery = "em", blendWeight = ...); use "pxem" for scalar PX-GEM. A zero blend weight requests AI only, one requests EM/GEM, and intermediate weights mix directions. Scalar/vector schedules and whole-number exponential tapers are supported. Proposal scaling belongs to proposal$stepWeight. Random-effect variances can reach the original-response-scale numerical floor, max(1e-8, control$execution$inverseTol), without freezing the remaining components. The assembled observation covariance must remain positive definite.

Convergence requires a small feasible score as well as a small likelihood change or AI proposal. A rejected update is not convergence: a stalled line search warns and returns the last accepted fit with convergence = FALSE. Reaching control$convergence$maxIters also returns the last evaluated point, not an unevaluated proposal. Inspect fit$engineDiagnostics$direct for the stop reason, score certificate, and line-search halving count.

Direct EM uses exact observation-space posterior moments, not a diagonal AI approximation or a Henderson solve. All direct covariance families support EM/GEM and PX-GEM under ML and REML, including structured residuals, custom covariance factors, and zero-specific reduced-rank terms. Eligible scalar, diagonal, and unstructured random updates have closed-form M-steps; other updates numerically increase the complete-data Q objective. ML profiles fixed effects inside the residual Q objective; REML includes fixed-effect posterior uncertainty. Final covariance standard errors still use clean AI. Inspect engineDiagnostics$blend for Q gains and M-step work, and engineDiagnostics$recovery for automatic recovery triggers and acceptance. Exact EM workspace obeys denseMemoryMB; structured/PX updates can cost more than AI despite needing fewer iterations. Henderson algorithms are unchanged.

Home website

Want to know more about the sommer project or you need professional services? Visit https://covaruber.github.io/sommer/

Using sommer code and the GPL license

Please be aware that the sommer project is open-source software released under the GNU General Public License (GPL). The GPL gives you the freedom to use, study, modify, and redistribute the software, subject to the conditions of the license.

In particular, if you copy, modify, or create a work based on GPL-covered sommer source code and distribute that work, the GPL imposes requirements on how the resulting work may be licensed and distributed. Among other things, recipients must retain the freedoms provided by the GPL, and when GPL-covered software is distributed in binary or other non-source form, the corresponding source code must also be made available in accordance with the GPL.

Therefore, the fact that sommer is free and open-source does not mean that its source code can be copied into another software package, modified, redistributed as a proprietary product, and kept secret. If your project contains or is based on GPL-covered sommer code, please carefully review the GPL requirements before distributing it.

The purpose of the sommer project is to encourage open collaboration, reproducibility, and continued improvement of statistical and quantitative-genetics software. Contributions and derivative work are welcome, but they should respect the freedoms and obligations established by the GPL.

Please read the full GPL license distributed with sommer before incorporating sommer source code into another project.

Copy Link

Version

Install

install.packages('sommer')

Monthly Downloads

6,016

Version

4.5.12

License

GPL-3

Issues

Pull Requests

Stars

Forks

Maintainer

Giovanny Covarrubias-Pazaran

Last Published

October 25th, 2026

Functions in sommer (4.5.12)

covm

Covariance Between Two Random Effects
csr

User-specified covariance-component structure for mmer and vsr
dfToMatrix

data frame to matrix
covparams_mmes_se

Native-scale covariance parameters and standard errors
coef.mmes

coef form a GLMM fitted with mmes
corgm

General positive-definite correlation structure
csm

Compound-symmetry covariance structure
corImputation

Imputing a matrix using correlations
covparams_mmes

Extract native-scale covariance parameters from an mmes fit
covmatrix_mmes

Covariance and correlation matrix of a fitted term with standard errors
loadings_mmes

Extract factor-analytic loadings from a fitted mmes model
dsr

Diagonal covariance structure for mmer and vsr
fixm

fixed indication matrix
fam

Factor-analytic covariance structure
dsumm

Direct sum of residual covariance structures across sections
ism

Identity covariance structure
familym

Different distribution families for the traits of a multi-trait model
generate_mme_workload

Generate Parameterized MME Workloads for Solver Evaluation
dsm

Diagonal heterogeneous covariance structure
fitted.mmes

fitted form a LMM fitted with mmes
metricm

Distance-based (metric) spatial correlation structures
ownm

User-defined covariance structure
maternm

Matern spatial covariance structure
mam

Moving-average covariance structures of order one or two
mmer

mixed model equations for r records
mmes

mixed model equations solver
mmes_control

Modular Numerical Controls for Mixed Models
mme_workload_grid

Generate a Factorial Grid of MME Workloads
pmonitor

plot the change of VC across iterations
meffects_mmes

Marker effects recovered from a fitted relationship-based term
postVarU

Post-fit Sampling Covariance of BLUPs
print.sommer_mmes_control

Print Modular Numerical Controls
r2

Reliability
print.sommer_mme_profile

Print method for sommer_mme_profile
print.sommer_mme_benchmark

Print method for sommer_mme_benchmark
postPEV

Post-fit prediction error variances and inverse coefficient matrix
profile_mme_workload

Profile an MME Workload by Phase
print.sommer_mme_crossover

Print method for sommer_mme_crossover
predict.mmes

Predict form of a LMM fitted with mmes
plot.mmes

plot form a LMM plot with mmes
sar

Simultaneous autoregressive spatial covariance structure
rotate_back_mmes

Back-transform rotated mmes random effects
sommer-package

Solving Mixed Model Equations in R
Figure: mai.png
randef

extracting random effects
scores_mmes

Predict factor-analytic scores from a fitted mmes model
run_mme_benchmark

Run Experimental MME Benchmark Suite
spl2Dc

Two-dimensional penalised tensor-product of marginal B-Spline basis.
spl2Dmats

Get Tensor Product Spline Mixed Model Incidence Matrices
rrm

Reduced-rank covariance structure
residuals.mmes

Residuals form a GLMM fitted with mmes
usr

Unstructured covariance structure for mmer and vsr
toeplitzm

General positive-definite Toeplitz correlation structure
usm

Unstructured positive-definite covariance structure
tpsmmbwrapper

Get Tensor Product Spline Mixed Model Incidence Matrices
strm

Covariance structure spanning several random terms
unsm

unstructured indication matrix
vcc

Equality and scaling constraints between variance parameters
stackTraits

Stack several trait columns into the long format used by multi-trait models
vpredict

vpredict form of a LMM fitted with mmes
summary.mmes

summary form a GLMM fitted with mmes
vsm

Variance-structure model with arbitrary Kronecker covariance factors
wald_mmes

Wald tests for fixed effects with optional small-sample denominator df
vsr

variance structure specification
H.mat

Combined relationship matrix H
D.mat

Dominance relationship matrix
vs

variance structure specification
summary.mmer

summary form a GLMM fitted with mmer
GWAS

Genome wide association study analysis
A.mat

Additive relationship matrix
MNR

Multivariate Newton-Raphson algorithm
E.mat

Epistatic relationship matrix
APY

Construct an APY Relationship Precision Matrix
analyze_mme_crossovers

Analyze Crossover Frontiers from MME Benchmarks
atm

Selected-level diagonal covariance structure
ar1m

First-order autoregressive covariance structure
anova.mmes

anova form a GLMM fitted with mmes
atr

Selected-level diagonal covariance structure for mmer and vsr
ar2m

Second-order autoregressive covariance structure
car

Proper conditional autoregressive spatial covariance structure
antem

Antedependence covariance structure
binm

Binomial proportion response with its number of trials
ar3m

Third-order autoregressive covariance structure