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:
- y
array
vector of phenotype values
- X:
array
regression design matrix for fixed effects
- fam_labels
array
vector of family labels: residual correlations in y are modelled between family members (that share a fam_label)
- add_intercept
bool
whether to add an intercept to the fixed effect design matrix
- y
- Returns:
- model
snipar.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
- alpha
array
MLE of fixed effects, if return_fixed=True
- alpha_cov
array
sampling variance-covariance matrix for MLE of fixed effects, if return_fixed=True
- model
- class snipar.lmm.model(y, X, labels, add_intercept=False)[source]
Bases:
object
Define a linear model with within-class correlations.
- Args:
- y
array
1D array of phenotype observations
- X
array
Design matrix for the fixed mean effects.
- labels
array
1D array of sample labels
- y
- Returns:
model :
snipar.model
- alpha_mle(tau, sigma2, compute_cov=False, xtx_out=False)[source]
Compute the MLE of alpha given variance parameters
- Args:
- sigma2
float
variance of model residuals
- tau
float
ratio of variance of model residuals to variance explained by mean differences between classes
- sigma2
- Returns:
- alpha
array
MLE of alpha
- alpha
- likelihood_and_gradient(sigma2, tau)[source]
Compute the loss function, which is -2 times the likelihood along with its gradient
- Args:
- sigma2
float
variance of model residuals
- tau
float
ratio of variance of model residuals to variance explained by mean differences between classes
- sigma2
- Returns:
- L, grad
float
loss function and gradient, divided by sample size
- L, grad
- optimize_model(init_params)[source]
Find the parameters that minimise the loss function for a given regularisation parameter
- Args:
- init_param
array
initial values for residual variance (sigma^2_epsilon) followed by ratio of residual variance to within-class variance (tau)
- init_param
- Returns:
- optim
dict
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.
- optim
- 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:
- n
int
sample size
- alpha
array
value of regression coefficeints
- sigma2
float
variance of residuals
- tau
float
ratio of variance of residuals to variance of distribution of between individual means
- n
- Returns:
- model
regrnd.model
linear model with repeated observations
- model