Documentation for ‘hetlmm’ module

Documentation for the heteroskedastic linear mixed model class.

class hetlmm.model(y, X, V, G)[source]

Define a heteroskedastic linear mixed model and calculate likelihood, gradients, and maximum likelihood estimates of parameters.

Parameters:
y : array

1D array of phenotype observations

X : array

Design matrix for the fixed mean effects.

V : array

Design matrix for the fixed variance effects.

G : array

Design matrix for the random effects.

Returns:
model : hetlmm.model

heteroskedastic linear mixed model class with input data

Methods

alpha_mle(beta, h2) Compute the maximum likelihood estimate of the fixed mean effect parameters, given particular fixed variance effect parameters and variance of random effects
alpha_ols() Compute the ordinary least squares (OLS) estimate of the fixed mean effect parameters
likelihood(beta, h2[, negative]) Compute the log of the profile likelihood, the likelihood at the maximum likelihood for the fixed mean effects
likelihood_and_gradient(beta, h2[, return_grad]) Compute the function that is minimized to find the MLE, LL=-2*L/n-log(2*pi), where L is the log of the profile likelihood, the likelihood at the maximum for the fixed mean effects.
optimize_model(h2[, SEs, dx]) Find the maximum likelihood estimate (MLE) of the parameters and their sampling distribution.
parameter_covariance(alpha, beta, h2[, dx])
alpha_mle(beta, h2)[source]

Compute the maximum likelihood estimate of the fixed mean effect parameters, given particular fixed variance effect parameters and variance of random effects

Parameters:
beta : array

value of fixed variance effects

h2: :class:`float`

value of variance explained by random effects to compute likelihood for

Returns:
alpha : array

maximum likelihood estimate of alpha given beta and h2

alpha_ols()[source]

Compute the ordinary least squares (OLS) estimate of the fixed mean effect parameters

Returns:
alpha : array

ordinary least-squares estimate of alpha

likelihood(beta, h2, negative=False)[source]

Compute the log of the profile likelihood, the likelihood at the maximum likelihood for the fixed mean effects

Parameters:
beta : array

value of fixed variance effects to compute likelihood for

h2: :class:`float`

value of variance explained by random effects to compute likelihood for

negative : bool

compute -2*L/n-log(2*pi), where L is the log-likelihood, the function that is minimized to find the MLE. Default is False.

Returns:
L : float

log-likelihood of data given parameters.

likelihood_and_gradient(beta, h2, return_grad=True)[source]

Compute the function that is minimized to find the MLE, LL=-2*L/n-log(2*pi), where L is the log of the profile likelihood, the likelihood at the maximum for the fixed mean effects. Further, compute the gradient with respect to the fixed variance effects and the variance of the random effects. This forms the basis of the function passed to L-BFGS-B in order to find the maximum likelihood parameter estimates.

Parameters:
beta : array

value of fixed variance effects to compute likelihood for

h2: :class:`float`

value of variance explained by random effects to compute likelihood for

Returns:
[LL,gradient] : list

the value of the function to be minimized, LL, and its gradient. The gradient is a 1d array that has the gradient with respect to beta first followed by the gradient with respect to h2.

optimize_model(h2, SEs=True, dx=1e-06)[source]

Find the maximum likelihood estimate (MLE) of the parameters and their sampling distribution.

Parameters:
h2 : float

initial value of variance explained by random effects

SEs : bool

whether to compute sampling distribution of parameter estimates. Default is True.

dx : float

the step size used to compute the Hessian for the computing the parameter sampling distribution

Returns:
optim : dict

keys: MLEs (‘alpha’, fixed mean effects; ‘beta’, fixed variance effects; ‘h2’, variance explained by random effects), their standard errors (‘alpha_se’, ‘beta_se’, ‘h2_se’), covariance matrix for sampling distribution of parameter vector (‘par_cov’, in order: alpha, beta, h2), maximum likelihood (‘likelihood’), whether optimisation was successful (‘success’), warnings from L-BFGS-B optimisation (‘warnflag’).

hetlmm.simulate(n, l, alpha, beta, h2)[source]

Simulate from a heteroskedastic linear mixed model given a set of parameters. This uses a singular value decomposition to do the simulation quickly when l<<n.

The function simulates fixed and random effects design matrices of specified dimensions with independent Gaussian entries.

Parameters:
n : int

sample size

l : int

number of random effects

alpha : array

value of fixed mean effects

beta : array

value of fixed variance effects

h2 : float

value of variance explained by random effects

Returns:
model : hetlmm.model

heteroskedastic linear mixed model with data simulated from given parameters