Compute weights with mr.mash using a precomputed prior grid and mixture prior.
Usage
mrmash_wrapper(
X,
Y,
V = NULL,
sumstats = NULL,
data_driven_prior_matrices = NULL,
prior_grid = NULL,
nthreads = 1,
canonical_prior_matrices = FALSE,
standardize = FALSE,
update_w0 = TRUE,
w0_threshold = 1e-08,
update_V = TRUE,
update_V_method = "full",
B_init_method = "enet",
max_iter = 5000,
tol = 0.01,
verbose = FALSE,
...
)Arguments
- X
An n x p matrix of genotype data, where n is the total number of individuals and p is the number of SNPs.
- Y
An n x r matrix of residual expression data, where n is the total number of individuals and r is the total number of conditions (tissue/cell-types).
- data_driven_prior_matrices
A list of data-driven covariance matrices. Default is NULL.
- prior_grid
A vector of scaling factors to be used in fitting the mr.mash model. Default is NULL.
- nthreads
The number of threads to use for parallel computation. Default is 2.
- canonical_prior_matrices
A logical indicating whether to use canonical matrices as priors. Default is FALSE.
- standardize
A logical indicating whether to standardize the input data. Default is FALSE.
- update_w0
A logical indicating whether to update the prior mixture weights. Default is TRUE.
- w0_threshold
The threshold for updating prior mixture weights. Default is 1e-8.
- update_V
A logical indicating whether to update the residual covariance matrix. Default is TRUE.
- update_V_method
The method for updating the residual covariance matrix. Default is "full".
- B_init_method
The method for initializing the coefficient matrix. Default is "enet".
- max_iter
The maximum number of iterations. Default is 5000.
- tol
The tolerance for convergence. Default is 0.01.
- verbose
A logical indicating whether to print verbose output. Default is FALSE.
- ...
Additional arguments to be passed to mr.mash.
Value
A mr.mash fit, stored as a list with some or all of the following elements:
- mu1
A p x r matrix of posterior means for the regression coefficients.
- S1
An r x r x p array of posterior covariances for the regression coefficients.
- w1
A p x K matrix of posterior assignment probabilities to the mixture components.
- V
An r x r residual covariance matrix.
- w0
A K-vector with (updated, if
update_w0=TRUE) prior mixture weights, each associated with the respective covariance matrix inS0.- S0
An r x r x K array of prior covariance matrices on the regression coefficients.
- intercept
An r-vector containing the posterior mean estimate of the intercept.
- fitted
An n x r matrix of fitted values.
- G
An r x r covariance matrix of fitted values.
- pve
An r-vector of proportion of variance explained by the covariates.
- ELBO
The Evidence Lower Bound (ELBO) at the last iteration.
- progress
A data frame including information regarding convergence criteria at each iteration.
- converged
A logical indicating whether the optimization algorithm converged to a solution within the chosen tolerance level.
- elapsed_time
The computation runtime for fitting mr.mash.
- Y
An n x r matrix of responses at the last iteration (only relevant when missing values are present in the input Y).
Examples
set.seed(123)
prior_grid <- runif(17, 0.00005, 0.05)
sample_id <- paste0("P000", str_pad(1:400, 3, pad = "0"))
#> Error in str_pad(1:400, 3, pad = "0"): could not find function "str_pad"
X <- matrix(sample(0:2, size = n * p, replace = TRUE, prob = c(0.65, 0.30, 0.05)), nrow = n)
#> Error: object 'n' not found
rownames(X) <- sample_id
#> Error: object 'sample_id' not found
colnames(X) <- paste0("rs", sample(10000:100000, p))
#> Error: object 'p' not found
tissues <- c(
"Adipose Tissue", "Muscle Tissue", "Brain Tissue", "Liver Tissue",
"Kidney Tissue", "Heart Tissue", "Lung Tissue"
)
Y <- matrix(runif(n * r, -2, 2), nrow = n)
#> Error: object 'n' not found
Y <- scale(Y)
#> Error: object 'Y' not found
colnames(Y) <- tissues
#> Error: object 'Y' not found
rownames(Y) <- sample_id
#> Error: object 'sample_id' not found
set.seed(Sys.time())
components <- c(
"XtX", "tFLASH_default", "FLASH_default", "tFLASH_nonneg",
"FLASH_nonneg", "PCA"
)
data_driven_prior_matrices <- list()
for (i in components) {
A <- matrix(runif(r^2) * 2 - 1, ncol = r)
cov <- t(A) %*% A
colnames(cov) <- tissues
rownames(cov) <- tissues
data_driven_prior_matrices[[i]] <- cov
}
#> Error: object 'r' not found
res <- mrmash_wrapper(
X = X, Y = Y,
data_driven_prior_matrices = data_driven_prior_matrices,
prior_grid = prior_grid
)
#> Error: object 'X' not found