Learn R Programming

mashr: Multivariate Adaptive Shrinkage in R

This package implements methods to estimate and test many effects in many conditions (or many effects on many outcomes).

Empirical Bayes methods are used to estimate patterns of similarity among conditions, then exploit these patterns of similarity among conditions to improve accuracy of effect estimates. See Urbut et al for details.

Note: the R package used to generate the results for the manuscript is here.

Quick Start

  1. Install mashr from CRAN: install.packages("mashr"). For more

detailed setup instructions, see below.

  1. See the introductory vignette for an

introduction to mashr.

  1. Then walk through these vignettes to learn more about mashr:

Introduction to mash: data-driven covariances and Simulation with non-canonical matrices.

Citing this work

If you find the mashr package or any of the source code in this repository useful for your work, please cite:

Sarah Urbut, Gao Wang, Peter Carbonetto and Matthew Stephens (2019). Flexible statistical methods for estimating and testing effects in genomic studies with multiple conditions. Nature Genetics 51, 187-195.

Setup

The simplest and quickest to obtain mashr is to install it from CRAN:

install.packages("mashr")

For Mac and Windows, usually the package is precompiled, so no additional compiler setup is required. If you have Linux, and in some other rare cases, you will need to make sure that your R installation is properly set up to compile packages with C++ source; in particular, the C++ compiler programs supported by your version of R should be installed on your computer, and R should be correctly configured to call these compilers when installing packages from source. For more information, see the CRAN documentation.

Alternatively, you may use remotes to install the latest version of mashr from GitHub:

install.packages("remotes")
remotes::install_github("stephenslab/mashr")

This command should automatically install any missing dependencies that are available from CRAN and GitHub.

Developer notes

  • When any changes are made to roxygen2 markup or the C++ code in

the src directory, run devtools::document() to update the RcppExports.cpp, the package namespaces (see NAMESPACE), and the package documentation files (in the "man" subdirectory),

  • These are the R commands to build the website (make sure you are

connected to Internet while running these commands):

pkgdown::build_site(lazy=TRUE, examples=FALSE)
  • After editing C++ code in the src directory, please use

uncrustify to format the code using configuration file inst/misc/uncrustify_default.cfg. For example:

uncrustify -c uncrustify_default.cfg --replace --no-backup -l CPP mash.cpp
  • Prior to submitting the package to CRAN, the following modifications

need to be made: (1) remove the Remotes: entry in DESCRIPTION; and (2) remove the flash_mash.Rmd vignette.

Copy Link

Version

Install

install.packages('mashr')

Monthly Downloads

482

Version

0.2.79

License

BSD_3_clause + file LICENSE

Issues

Pull Requests

Stars

Forks

Maintainer

Peter Carbonetto

Last Published

October 18th, 2023

Functions in mashr (0.2.79)

get_estimated_pi

Return the estimated mixture proportions
expand_cov

Create expanded list of covariance matrices expanded by grid
cov_pca

Perform PCA on data and return list of candidate covariance matrices
get_log10bf

Return the Bayes Factor for each effect
extreme_deconvolution

Density estimation using Gaussian mixtures in the presence of noisy, heterogeneous and incomplete data
cov_udi

Compute a list of covariance matrices corresponding to the "Unassociated", "Directly associated" and "Indirectly associated" models
cov_udi_single

Computes the covariance matrix for a single UDI model
cov_simple_het

Compute covariance matrices with diagonal element 1 and off-diagonal element corr
cov_from_factors

produce list of rank-1 covariance matrices corresponding to rows of f
mash_compute_posterior_matrices

Compute posterior matrices for fitted mash object on new data
make_names

Create names for covariance matrices
estimate_null_correlation_simple

Estimate null correlations (simple)
mash_1by1

Perform condition-by-condition analyses
get_pairwise_sharing_from_samples

Compute the proportion of (significant) signals shared by magnitude in each pair of conditions
get_samples

Return samples from a mash object
get_pairwise_sharing

Compute the proportion of (significant) signals shared by magnitude in each pair of conditions, based on the poterior mean
get_n_significant_conditions

Count number of conditions each effect is significant in
mash

Apply mash method to data
get_significant_results

Find effects that are significant in at least one condition
mash_compute_loglik

Compute loglikelihood for fitted mash object on new data.
mash_compute_vloglik

Compute vector of loglikelihood for fitted mash object on new data
optimize_pi

Estimate mixture weights by maximum (penalized) likelihood
mash_estimate_corr_em

Fit mash model and estimate residual correlations using EM algorithm
mash_plot_meta

Plot metaplot for an effect based on posterior from mash
mash_update_data

Update the data object for mash analysis.
mash_set_data

Create a data object for mash analysis.
mash_set_data_contrast

Create a data object for mash contrast analysis
posterior_mean

posterior_mean
posterior_mean_matrix

posterior_mean_matrix
posterior_cov

posterior_cov
simple_sims

Create some simple simulated data for testing purposes
sim_contrast1

Create simplest simulation, cj = mu 1 data used for contrast analysis
simple_sims2

Create some more simple simulated data for testing purposes
sim_contrast2

Create simulation with signal data used for contrast analysis.
scale_cov

Scale each covariance matrix in list Ulist by a scalar in vector grid
udi_model_matrix

Create a matrix whose rows contain all possible combinations of the U,D,I models that are allowed.
teem_wrapper

Fit extreme deconvolution to mash data using TEEM method developed by Y. Yang and M Stephens
compute_alt_loglik_from_matrix_and_pi

Compute vector of alternative loglikelihoods from a matrix of log-likelihoods and fitted pi
cov_ed

Perform "extreme deconvolution" (Bovy et al) on a subset of the data
contrast_matrix

Create contrast matrix
cov_canonical

Compute a list of canonical covariance matrices
compute_loglik_from_matrix_and_pi

Compute the total loglikelihood from a matrix of log-likelihoods and fitted pi
bovy_wrapper

Fit extreme deconvolution to mash data using Bovy et al 2011
calc_relative_lik_matrix

Calculate matrix of relative likelihoods.
cov_equal_effects

Compute an R by R matrix of all 1s
compute_null_loglik_from_matrix

Compute a vector of null loglikelihoods from a matrix of log-likelihoods
calc_lik_matrix

Compute matrix of conditional likelihoods.
compute_vloglik_from_matrix_and_pi

Computes a vector of loglikelihoods from a matrix of log-likelihoods and fitted pi
compute_posterior_matrices_common_cov_R

Compute posterior matrices (when error covariance V_j is equal for all observations j)
compute_posterior_matrices_general_R

Compute posterior matrices (general version)
calc_lik_vector

Compute conditional likelihoods for bhat vector.
compute_posterior_weights

Compute posterior probabilities that each effect came from each component
compute_posterior_matrices

Compute posterior matrices.
calc_lik_matrix_common_cov

calc_lik_matrix_common_cov
cov_flash

Perform Empirical Bayes Matrix Factorization using flashier, and return a list of candidate covariance matrices
cov_first_singleton

Compute all the singleton matrices corresponding to condition-specific effects in first condition only; used for testing purposes
cov_all_zeros

Compute an R by R matrix of all 0s