Package 'lmmlite'

Title: Simple LMM Fitter for QTL Mapping
Description: A port of parts of 'pylmm' for fitting linear mixed models relevant to genome-wide association studies (GWAS) and quantitative trait locus (QTL) mapping.
Authors: Karl W Broman [aut, cre] (ORCID: <https://orcid.org/0000-0002-4914-6671>, (closely following the pylmm code by Nick Furlotte))
Maintainer: Karl W Broman <[email protected]>
License: AGPL-3
Version: 0.2-2
Built: 2026-06-05 11:27:44 UTC
Source: https://github.com/kbroman/lmmlite

Help Index


Calculate log likelihood for a given heritability

Description

Calculate the log likelihood for a given value of the heritability, hsq.

Usage

calcLL(hsq, Kva, y, X, reml = TRUE, use_cpp = TRUE)

Arguments

hsq

heritability

Kva

eigenvalues of K (calculated by eigen_rotation())

y

rotated phenotypes (calculated by eigen_rotation())

X

rotated covariate matrix (calculated by eigen_rotation())

reml

If TRUE, use REML; otherwise use ordinary maximum likelihood.

use_cpp

= if TRUE, use c++ version of code

Value

The log likelihood value, with the corresponding estimates of beta and sigmasq included as attributes.

Examples

data(recla)
e <- eigen_rotation(recla$kinship, recla$pheno[,1], recla$covar)
loglik <- calcLL(0.5, e$Kva, e$y, e$X)
many_loglik <- calcLL(seq(0, 1, by=0.1), e$Kva, e$y, e$X)

eigen decomposition + rotation

Description

Do eigen decomposition of kinship matrix and rotate X and y by that, i.e., pre-multiply by the transpose of the matrix of eigenvectors. If Kva and Kve_t provided, just do the "rotation".

Usage

eigen_rotation(K, y, X = NULL, Kva = NULL, Kve_t = NULL, use_cpp = TRUE)

Arguments

K

Kinship matrix (required if use_cpp=TRUE)

y

Phenotypes

X

Numeric matrix with covariates. If NULL, use a column of 1's (for intercept).

Kva

Eigenvalues of K (optional, ignored if use_cpp=TRUE)

Kve_t

= transposed eigenvectors of K (optional, ignored if use_cpp=TRUE)

use_cpp

= if TRUE, use c++ version of code

Value

List containing Kva, Kve_t and rotated y and X.

Examples

data(recla)
e <- eigen_rotation(recla$kinship, recla$pheno[,1], recla$covar)

Fit a linear mixed model

Description

Fit a linear mixed model of the form y = Xb + e where e follows a multivariate normal distribution with mean 0 and variance matrix ⁠sigmasq_g K + sigmasq_e I⁠, where K is a known kniship matrix and I is the identity matrix.

Usage

fitLMM(
  Kva,
  y,
  X,
  reml = TRUE,
  check_boundary = TRUE,
  tol = 0.0001,
  use_cpp = TRUE,
  compute_se = FALSE
)

Arguments

Kva

Eigenvalues of K (calculated by eigen_rotation())

y

Rotated phenotypes (calculated by eigen_rotation())

X

Rotated covariate matrix (calculated by eigen_rotation())

reml

If TRUE, use REML; otherwise use ordinary maximum likelihood.

check_boundary

If TRUE, explicitly check log likelihood at 0 and 1.

tol

Tolerance for convergence

use_cpp

= if TRUE, use c++ version of code

compute_se

= if TRUE, return the standard error of the hsq estimate using the Fisher Information matrix of the MLE estimate. The standard error will be in an attr of hsq in the output. Currently requires use_cpp = FALSE, and so if compute_se=TRUE we take use_cpp=FALSE.

Value

List containing estimates of beta, sigmasq, hsq, sigmasq_g, and sigmasq_e, as well as the log likelihood (loglik). If compute_se=TRUE, the output also contains hsq_se.

Examples

data(recla)
e <- eigen_rotation(recla$kinship, recla$pheno[,1], recla$covar)
result <- fitLMM(e$Kva, e$y, e$X)

# also compute SE
wSE <- fitLMM(e$Kva, e$y, e$X, compute_se = TRUE, use_cpp=FALSE)
c(hsq=wSE$hsq, SE=wSE$hsq_se)

Get MLEs for coefficients and variance

Description

For a fixed value for hsq, the heritability, calculate the corresponding maximum likelihood estimates of beta and sigmasq, with the latter being the total variance, sigmasq_g + sigmasq_e.

Usage

getMLsoln(hsq, Kva, y, X, reml = TRUE, use_cpp = TRUE)

Arguments

hsq

heritability

Kva

eigenvalues of K (calculated by eigen_rotation())

y

rotated phenotypes (calculated by eigen_rotation())

X

rotated covariate matrix (calculated by eigen_rotation())

reml

If TRUE, use REML; otherwise use ordinary maximum likelihood.

use_cpp

= if TRUE, use c++ version of code

Value

list containing beta and sigmasq, with residual sum of squares and (if reml=TRUE, ⁠log det (XSX)⁠) as attributes.

Examples

data(recla)
e <- eigen_rotation(recla$kinship, recla$pheno[,1], recla$covar)
ml <- getMLsoln(0.5, e$Kva, e$y, e$X)

Example kinship, phenotype, and covariate data

Description

Estimated kinship matrix, phenotypes, and covariates for diversity outcross mice, taken from Recla et al. (2014) and Logan et al. (2013)

Format

A list with three components, kinship, pheno, and covar, each a matrix.

Details

These are data for a set of diversity outcross mice. The kinship matrix was calculated from MUGA array data, using the R/qtl2 package.

Source

QTL Archive, https://phenome.jax.org/projects/Recla1

References

Recla JM, Robledo RF, Gatti DM, Bult CJ, Churchill GA, Chesler EJ (2014) Precise genetic mapping and integrative bioinformatics in Diversity Outbred mice reveals Hydin as a novel pain gene. Mamm Genome 25:211-222

Logan RW, Robledo RF, Recla JM, Philip VM, Bubier JA, Jay JJ, Harwood C, Wilcox T, Gatti DM, Bult CJ, Churchill GA, Chesler EJ (2013) High-precision genetic mapping of behavioral traits in the diversity outbred mouse population. Genes Brain Behav 12:424-437

Examples

data(recla)