snipar.lmm module

snipar.lmm.fit_model(y, X, fam_labels, add_intercept=False, tau_init=1, return_model=True, return_vcomps=True, return_fixed=True)[source]

Compute the MLE for the fixed effects in a family-based linear mixed model.

Args:
yarray

vector of phenotype values

X: array

regression design matrix for fixed effects

fam_labelsarray

vector of family labels: residual correlations in y are modelled between family members (that share a fam_label)

add_interceptbool

whether to add an intercept to the fixed effect design matrix

Returns:
modelsnipar.model

the snipar model object, if return_model=True

vcomps: float

the MLEs for the variance parameters: sigma2 (residual variance) and tau (ratio between sigma2 and family variance), if return_vcomps=True

alphaarray

MLE of fixed effects, if return_fixed=True

alpha_covarray

sampling variance-covariance matrix for MLE of fixed effects, if return_fixed=True

snipar.lmm.lik_and_grad(pars, *args)[source]
class snipar.lmm.model(y, X, labels, add_intercept=False)[source]

Bases: object

Define a linear model with within-class correlations.

Args:
yarray

1D array of phenotype observations

Xarray

Design matrix for the fixed mean effects.

labelsarray

1D array of sample labels

Returns:

model : snipar.model

alpha_mle(tau, sigma2, compute_cov=False, xtx_out=False)[source]

Compute the MLE of alpha given variance parameters

Args:
sigma2float

variance of model residuals

taufloat

ratio of variance of model residuals to variance explained by mean differences between classes

Returns:
alphaarray

MLE of alpha

likelihood_and_gradient(sigma2, tau)[source]

Compute the loss function, which is -2 times the likelihood along with its gradient

Args:
sigma2float

variance of model residuals

taufloat

ratio of variance of model residuals to variance explained by mean differences between classes

Returns:
L, gradfloat

loss function and gradient, divided by sample size

optimize_model(init_params)[source]

Find the parameters that minimise the loss function for a given regularisation parameter

Args:
init_paramarray

initial values for residual variance (sigma^2_epsilon) followed by ratio of residual variance to within-class variance (tau)

Returns:
optimdict

dictionary with keys: ‘success’, whether optimisation was successful (bool); ‘warnflag’, output of L-BFGS-B algorithm giving warnings; ‘sigma2’, MLE of residual variance; ‘tau’, MLE of ratio of residual variance to within-class variance; ‘likelihood’, maximum of likelihood.

predict(X)[source]

Predict new observations based on model regression coefficients

Args:
Xarray

matrix of covariates to predict from

Returns:
yarray

predicted values

set_alpha(alpha)[source]
sigma_inv_root(tau, sigma2)[source]
snipar.lmm.simulate(n, alpha, sigma2, tau)[source]
Simulate from a linear model with correlated observations within-class. The mean for each class

is drawn from a normal distribution.

Args:
nint

sample size

alphaarray

value of regression coefficeints

sigma2float

variance of residuals

taufloat

ratio of variance of residuals to variance of distribution of between individual means

Returns:
modelregrnd.model

linear model with repeated observations