snipar.slmm module
- class snipar.slmm.GradHessComponents(P_y, P_varcomp_mats)[source]
Bases:
NamedTuple- P_varcomp_mats: Tuple[ndarray, ...]
Alias for field number 1
- P_y: ndarray
Alias for field number 0
- class snipar.slmm.LinearMixedModel(y: ndarray, varcomp_arr_lst: Sequence[Tuple[ndarray, ndarray, ndarray]], varcomps: Sequence[float] | None = None, covar_X: ndarray | None = None, add_intercept: bool = False, add_jitter: bool = False)[source]
Bases:
objectWrapper of data and functions that compute estimates of variance components or SNP effects. Core functions: fit_snp_eff, robust_est, sib_diff_est
- property P_attrs
Compute ingredients for gradient and hessian (Vinv_y, Vinv_varcomp_mats).
- Returns:
GradHessComponents: a NameTuple holding the computation results
- property V
Compute V.
- Returns:
csc_matrix: V in sparse csc format
- property V_logdet
Compute log determinant of V using LU.
- Returns:
float: log determinant of V
- property V_lu
Compute sparse LU factorization of V.
- Returns:
SuperLU: wrapper object holding LU factorization of V
- property Vinv_Z
- property Vinv_e
Compute matrix-vector product of inverse of V and one-vector
- Returns:
np.ndarray: Vinv_e
- Vinv_mat(dense_mat: ndarray) ndarray[source]
Calculate matrix-matrix product of inverse of V and a dense matrix
- Args:
dense_mat (np.ndarray): 2-d array in the dense format
- Raises:
ValueError: dense_mat must be a 2-d array ValueError: dimensions of V and dense_mat must match
- Returns:
np.ndarray: matrix product in the dense format
- property Vinv_varcomp_mats
Compute matrix multiplications of inverse of V and all variance component matrices.
- Returns:
Tuple[csc_matrix, …]: a tuple holding all Vinv_varcomp_mat
- property Vinv_y
Compute matrix-vector product of inverse of V and y
- Returns:
np.ndarray: Vinv_e
- ai_reml() None[source]
Perform AI-REML algorithm to obtain maximum likelihood estimates of variance components.
- dense_reml_loglik(method: typing_extensions.Literal[chol, cg] = 'cg') float[source]
Dense version of reml_loglik
- Args:
method (Literal[‘chol’, ‘cg’], optional): a string specifying method for computing V inverse. Defaults to ‘cg’.
- Raises:
RuntimeError: Conjugate gradient did not converge RuntimeError: Illigal input for conjugate gradient
- Returns:
float: REML log likelihood
- fit_snps_eff(gts: ndarray, standard_gwas: bool = False) Tuple[ndarray, ndarray, ndarray][source]
Perform repeated OLS to estimate SNP effects and sampling variance-covariance.
- Args:
gts (np.ndarray): 3-d array of genetic data.
- Returns:
Tuple[np.ndarray, np.ndarray, np.ndarray]: 3 arrays of SNP effects, covarinaces and standard errors.
- property grad
Compute gradient.
- Returns:
np.ndarray: 1-d array of gradient
- property hessian
Compute hessian.
- Returns:
np.ndarray: 2-d n_varcomps-by-n_varcomps array
- property reml_loglik
Compute REML log likelihood
- Returns:
float: REML log likelihood
- static sp_mul_dense3d(sps_mat: csc_matrix, dense_mat: ndarray) ndarray[source]
Compute product of given sparse matrix and given 3-d dense array; used for repeated OLS.
- Args:
sps_mat (csc_matrix): 2-d sparse matrix. dense_mat (np.ndarray): 3-d dense array.
- Raises:
ValueError: dense_mat should be 3-d. ValueError: 2nd dimensions of both inputs should match.
- Returns:
np.ndarray: 3-d dense array.
- static sp_solve_dense3d(sps_mat: csc_matrix, dense_mat: ndarray) ndarray[source]
Compute product of the inverse of given sparse matrix and given 3-d dense array; used for repeated OLS.
- Args:
sps_mat (csc_matrix): 2-d sparse matrix. dense_mat (np.ndarray): 3-d dense array.
- Raises:
ValueError: dense_mat should be 3-d. ValueError: 2nd dimensions of both inputs should match.
- Returns:
np.ndarray: 3-d dense array.
- static sp_solve_dense3d_lu(sps_mat: csc_matrix, dense_mat: ndarray) ndarray[source]
Compute product of the inverse of given sparse matrix and given 3-d dense array uisng LU; used for repeated OLS.
- Args:
sps_mat (csc_matrix): 2-d sparse matrix. dense_mat (np.ndarray): 3-d dense array.
- Raises:
ValueError: dense_mat should be 3-d. ValueError: 2nd dimensions of both inputs should match.
- Returns:
np.ndarray: 3-d dense array.
- trios_sibs_est(gts: ndarray, complete_trios_inds: ndarray, sibs_inds: ndarray) Tuple[ndarray, ndarray, ndarray][source]
Perform default regression on trios and sib-pairs.
- Args:
gts (np.ndarray): 3-d array of genetic data.
- Returns:
Tuple[np.ndarray, np.ndarray, np.ndarray]: 3 arrays of SNP effects, covarinaces and standard errors.
- property varcomps: Tuple[float, ...]
Return optimized variance components.
- Raises:
ValueError: self.optimized should be True
- Returns:
Tuple[float, …]: a tuple of variance components
- snipar.slmm.build_grm_arr(grm_path: str, id_dict: Dict[str, int], thres: float) Tuple[ndarray, ndarray, ndarray][source]
Build GRM data array and corresponding indices.
- snipar.slmm.build_ibdrel_arr(ibdrel_path: str, id_dict: Dict[str, int], keep: ndarray, thres: float = 0.05) Tuple[ndarray, ndarray, ndarray][source]
Build ibd relatedness array (lower triangular entries) and corresponding indices from KING ibdseg output.
- Args:
ibdrel_path (str): Path to ibdseg output. id_dict (IdDict): dictionary of id-index pairs. keep (Ids): list of ids to keep. ignore_sib (bool): whether to set sibling entries to 0. thres (float, optional): sparsity threshold. Defaults to 0.0205.
- Returns:
SparseGRMRepr: sparse GRM representation.