stephenslab / mashr

An R package for multivariate adaptive shrinkage.
https://stephenslab.github.io/mashr
Other
88 stars 19 forks source link

allow numeric prior #119

Closed ajaynadig closed 1 year ago

ajaynadig commented 1 year ago

It appears that while the set_prior function can handle a user-supplied numeric vector prior, mashr throws an error unless prior is equal to "nullbiased" or "uniform"

In the ashR package, this is handled by running match.arg(prior) only in the case that prior is not numeric.

The sole change in this PR is amending mashr to match ashr in this way, e.g. wrapping match.arg(prior) in an if statement checking that prior is not numeric.

(First PR, apologies for any misformatting or broken etiquette rules)

pcarbo commented 1 year ago

Thanks @ajaynadig. Can you please provide a small example reproducing the error?

ajaynadig commented 1 year ago

Sure! Running this script:

library(mashr)

Bhat     = matrix(rnorm(100),ncol=5) # create some simulated data
Shat     = matrix(rep(1,100),ncol=5)
data     = mash_set_data(Bhat,Shat, alpha=1)
U.c      = cov_canonical(data)

#Example: set prior where all non-zero components have weight 2, and the zero component has weight 1
prior = c(1,rep(2,13*length(U.c)))
res.mash = mash(data,U.c,prior = prior)

I get this error:

Error in match.arg(prior) : 'arg' must be NULL or a character vector

With no such error when the modification from the PR is made.

pcarbo commented 1 year ago

@ajaynadig Yes that makes sense. I'll accept your PR.

Note I updated your example though because you need to factor in the grid of scaling factors in your prior (which here has 13 grid points).