Skip to content

Commit

Permalink
add ash_pois function
Browse files Browse the repository at this point in the history
  • Loading branch information
stephens999 committed Sep 19, 2019
1 parent ed51fee commit 42207cb
Show file tree
Hide file tree
Showing 4 changed files with 72 additions and 16 deletions.
1 change: 1 addition & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ S3method(prune,default)
S3method(summary,ash)
export(ash)
export(ash.workhorse)
export(ash_pois)
export(ashci)
export(calc_logLR)
export(calc_loglik)
Expand Down
23 changes: 23 additions & 0 deletions R/ash_pois.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#' @title Performs adaptive shrinkage on Poisson data
#' @description Uses Empirical Bayes to fit the model \deqn{y_j | \lambda_j ~ Poi(c_j \lambda_j)} with \deqn{h(lambda_j) ~ g()}
#' where \eqn{h} is a specified link function (either "identity" or "log" are permitted).

#' @details The model is fit in two stages: i) estimate \eqn{g} by maximum likelihood (over the set of symmetric
#' unimodal distributions) to give estimate \eqn{\hat{g}};
#' ii) Compute posterior distributions for \eqn{\lambda_j} given \eqn{y_j,\hat{g}}.
#' Note that the link function \eqn{h} affects the prior assumptions (because, e.g., assuming a unimodal prior on \eqn{\lambda} is
#' different from assuming unimodal on \eqn{\log\lambda}), but posterior quantities are always computed for the
#' for \eqn{\lambda} and *not* \eqn{h(\lambda)}.
#' @param y vector of Poisson observations.
#' @param scale vector of scale factors for Poisson observations: the model is \eqn{y[j]~Pois(scale[j]*lambda[j])}.
#' @param link string, either "identity" or "log", indicating the link function.
#'
#' @examples
#' beta = c(rep(0,50),rexp(50))
#' y = rpois(100,beta) # simulate Poisson observations
#' y.ash = ash_pois(y,scale=1)
#' @export
ash_pois = function(y, scale=1, link=c("identity","log"), ...){
link = match.arg(link)
ash(rep(0,length(y)),1,lik=lik_pois(y,scale,link))
}
32 changes: 16 additions & 16 deletions man/ash.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

32 changes: 32 additions & 0 deletions man/ash_pois.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 42207cb

Please sign in to comment.