Learn R Programming

⚠️There's a newer version (0.2.79) of this package.Take me there.

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) set eval = FALSE in the flash_mash.Rmd vignette.

Copy Link

Version

Install

install.packages('mashr')

Monthly Downloads

427

Version

0.2.50

License

BSD_3_clause + file LICENSE

Issues

Pull Requests

Stars

Forks

Maintainer

Peter Carbonetto

Last Published

May 24th, 2021

Functions in mashr (0.2.50)

contrast_matrix

Create contrast matrix
compute_posterior_matrices_general_R

Compute posterior matrices (general version)
compute_posterior_weights

Compute posterior probabilities that each effect came from each component
compute_vloglik_from_matrix_and_pi

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

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

Perform condition-by-condition analyses
get_estimated_pi

Return the estimated mixture proportions
calc_lik_matrix_common_cov

calc_lik_matrix_common_cov
cov_simple_het

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

Compute posterior matrices.
calc_lik_vector

Compute conditional likelihoods for bhat vector.
calc_lik_matrix

Compute matrix of conditional likelihoods.
get_log10bf

Return the Bayes Factor for each effect
cov_all_zeros

Compute an R by R matrix of all 0s
mash_compute_loglik

Compute loglikelihood for fitted mash object on new data.
udi_model_matrix

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

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

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

Create some more simple simulated data for testing purposes
mash_plot_meta

Plot metaplot for an effect based on posterior from mash
mash_set_data

Create a data object for mash analysis.
get_pairwise_sharing

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

Compute a list of canonical covariance matrices
cov_udi_single

Computes the covariance matrix for a single UDI model
get_pairwise_sharing_from_samples

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

Estimate null correlations
get_n_significant_conditions

Count number of conditions each effect is significant in
cov_first_singleton

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

Return samples from a mash object
cov_flash

Perform Empirical Bayes Matrix Factorization via FLASH and return a list of candidate covariance matrices
get_significant_results

Find effects that are significant in at least one condition
cov_pca

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

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

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

posterior_cov
sim_contrast2

Create simulation with signal data used for contrast analysis.
simple_sims

Create some simple simulated data for testing purposes
optimize_pi

Estimate mixture weights by maximum (penalized) likelihood
make_names

Create names for covariance matrices
cov_udi

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

Apply mash method to data
mash_set_data_contrast

Create a data object for mash contrast analysis
cov_ed

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

posterior_mean
teem_wrapper

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

Compute an R by R matrix of all 1s
estimate_null_correlation_simple

Estimate null correlations (simple)
expand_cov

Create expanded list of covariance matrices expanded by grid, Sigma_lk = omega_l U_k
mash_compute_vloglik

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

Compute posterior matrices for fitted mash object on new data
mash_update_data

Update the data object for mash analysis.
posterior_mean_matrix

posterior_mean_matrix
scale_cov

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

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

Calculate matrix of relative likelihoods.
compute_alt_loglik_from_matrix_and_pi

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

Fit extreme deconvolution to mash data using Bovy et al 2011