Title: | Solve the Empirical Bayes Normal Means Problem |
---|---|
Description: | Provides simple, fast, and stable functions to fit the normal means model using empirical Bayes. For available models and details, see function ebnm(). A detailed introduction to the package is provided by Willwerscheid and Stephens (2023) <arXiv:2110.00152>. |
Authors: | Jason Willwerscheid [aut], Matthew Stephens [aut], Peter Carbonetto [aut, cre], Andrew Goldstein [ctb], Yusha Liu [ctb] |
Maintainer: | Peter Carbonetto <[email protected]> |
License: | GPL (>=3) |
Version: | 1.1-34 |
Built: | 2024-11-14 04:30:13 UTC |
Source: | https://github.com/stephenslab/ebnm |
The coef
method for class ebnm
.
## S3 method for class 'ebnm' coef(object, ...)
## S3 method for class 'ebnm' coef(object, ...)
object |
The fitted |
... |
Not used. Included for consistency as an S3 method. |
The confint
method for class ebnm
.
Estimates posterior "credible intervals" for each "true mean" .
We define the
% credible interval for
as
the narrowest continuous interval
such that
with posterior probability at least
, where
. We estimate these credible
intervals using Monte Carlo sampling. Note
that by default,
ebnm
does not return a posterior
sampler; one can be added to the ebnm
object using function
ebnm_add_sampler
.
## S3 method for class 'ebnm' confint(object, parm, level = 0.95, nsim = 1000, ...)
## S3 method for class 'ebnm' confint(object, parm, level = 0.95, nsim = 1000, ...)
object |
The fitted |
parm |
A vector of numeric indices specifying which means |
level |
The "confidence level" |
nsim |
The number of samples to use to estimate confidence intervals. |
... |
Additional arguments to be passed to the posterior sampler
function. Since |
A matrix with columns giving lower and upper confidence limits for
each mean . These will be labelled as "CI.lower" and
"CI.upper".
Solves the empirical Bayes normal means (EBNM) problem using a specified family of priors. For an article-length introduction to the package, see Willwerscheid and Stephens (2021), cited in References below.
ebnm( x, s = 1, prior_family = c("point_normal", "point_laplace", "point_exponential", "normal", "horseshoe", "normal_scale_mixture", "unimodal", "unimodal_symmetric", "unimodal_nonnegative", "unimodal_nonpositive", "generalized_binary", "npmle", "deconvolver", "flat", "point_mass", "ash"), mode = 0, scale = "estimate", g_init = NULL, fix_g = FALSE, output = ebnm_output_default(), optmethod = NULL, control = NULL, ... ) ebnm_output_default() ebnm_output_all()
ebnm( x, s = 1, prior_family = c("point_normal", "point_laplace", "point_exponential", "normal", "horseshoe", "normal_scale_mixture", "unimodal", "unimodal_symmetric", "unimodal_nonnegative", "unimodal_nonpositive", "generalized_binary", "npmle", "deconvolver", "flat", "point_mass", "ash"), mode = 0, scale = "estimate", g_init = NULL, fix_g = FALSE, output = ebnm_output_default(), optmethod = NULL, control = NULL, ... ) ebnm_output_default() ebnm_output_all()
x |
A vector of observations. Missing observations ( |
s |
A vector of standard errors (or a scalar if all are equal).
Standard errors may not be exactly zero, and
missing standard errors are not allowed. Two prior families have
additional restrictions: when horseshoe priors are used, errors
must be homoskedastic; and since function
|
prior_family |
A character string that specifies the prior family
|
mode |
A scalar specifying the mode of the prior |
scale |
A scalar or vector specifying the scale parameter(s) of the
prior or The interpretation of |
g_init |
The prior distribution |
fix_g |
If |
output |
A character vector indicating which values are to be returned.
Function |
optmethod |
A string specifying which optimization function is to be used. For parametric families other than the horseshoe and generalized binary
(normal, point-normal, point-Laplace, and point-exponential), options
include Since the horseshoe, generalized binary, and point mass families only require
one parameter to be estimated (at most), the only available optimization method
is For most nonparametric families (scale mixtures of normals; unimodal,
symmetric unimodal, nonnegative unimodal, and nonpositive unimodal families;
and the NPMLE), The nonparametric exception is the the "deconvolveR" family. Since
the |
control |
A list of control parameters to be passed to the optimization
function specified by parameter |
... |
Additional parameters. When a |
Given vectors of data x
and standard errors s
, ebnm
solves the "empirical Bayes normal means" (EBNM) problem for various
choices of prior family.
The model is
where , which is referred to as the
"prior distribution" for
, is to be estimated from among
some specified family of prior distributions
. Several options
for
are implemented, some parametric and others non-parametric;
see below for examples.
Solving the EBNM problem involves
two steps. First, is estimated via maximum marginal likelihood:
where
Second, posterior distributions
and/or summaries
such as posterior means and posterior second moments are computed.
Implemented prior families include:
point_normal
The family of mixtures where one
component is a point mass at and the other is a normal
distribution centered at
.
point_laplace
The family of mixtures where one
component is a point mass at and the other is a
double-exponential distribution centered at
.
point_exponential
The family of mixtures where one
component is a point mass at and the other is a
(nonnegative) exponential distribution with mode
.
normal
The family of normal distributions.
horseshoe
The family of horseshoe distributions.
normal_scale_mixture
The family of scale mixtures of normals.
unimodal
The family of all unimodal distributions.
unimodal_symmetric
The family of symmetric unimodal distributions.
unimodal_nonnegative
The family of unimodal distributions with support constrained to be greater than the mode.
unimodal_nonpositive
The family of unimodal distributions with support constrained to be less than the mode.
generalized_binary
The family of mixtures where one component is a point mass at zero and the other is a truncated normal distribution with lower bound zero and nonzero mode. See Liu et al. (2023), cited in References below.
npmle
The family of all distributions.
deconvolver
A non-parametric exponential family with
a natural spline basis. Like npmle
, there is no unimodal
assumption, but whereas npmle
produces spiky estimates for
,
deconvolver
estimates are much more regular. See
deconvolveR-package
for details and
references.
flat
The "non-informative" improper uniform prior, which yields posteriors
point_mass
The family of point masses .
Posteriors are point masses at
.
ash
Calls into function ash
in
package ashr
. Can be used to make direct comparisons of
ebnm
and ashr
implementations of prior families such as
scale mixtures of normals and the NPMLE.
An ebnm
object. Depending on the argument to output
, the
object is a list containing elements:
data
A data frame containing the observations x
and standard errors s
.
posterior
A data frame of summary results (posterior means, standard deviations, second moments, and local false sign rates).
fitted_g
The fitted prior (an object of
class
normalmix
, laplacemix
,
gammamix
, unimix
,
tnormalmix
, or horseshoe
).
log_likelihood
The optimal log likelihood attained,
.
posterior_sampler
A function that can be used to
produce samples from the posterior. For all prior families other
than the horseshoe, the sampler takes a single parameter
nsamp
, the number of posterior samples to return per
observation. Since ebnm_horseshoe
returns an MCMC sampler,
it additionally takes parameter burn
, the number of burn-in
samples to discard.
S3 methods coef
, confint
, fitted
, logLik
,
nobs
, plot
, predict
, print
, quantile
,
residuals
, simulate
, summary
, and vcov
have been implemented for ebnm
objects. For details, see the
respective help pages, linked below under See Also.
ebnm_output_default()
: Lists the default return values.
ebnm_output_all()
: Lists all valid return values.
Jason Willwerscheid, Peter Carbonetto and Matthew Stephens (2023).
ebnm
: an R
Package for solving the empirical Bayes
normal means problem using a variety of prior families.
arXiv:2110.00152.
Yusha Liu, Peter Carbonetto, Jason Willwerscheid, Scott A Oakes, Kay F Macleod, and Matthew Stephens (2023). Dissecting tumor transcriptional heterogeneity from single-cell RNA-seq data by generalized binary covariance decomposition. bioRxiv 2023.08.15.553436.
A plotting method is available for ebnm
objects: see
plot.ebnm
.
For other methods, see coef.ebnm
, confint.ebnm
,
fitted.ebnm
, logLik.ebnm
,
nobs.ebnm
, predict.ebnm
,
print.ebnm
, print.summary.ebnm
,
quantile.ebnm
, residuals.ebnm
,
simulate.ebnm
,
summary.ebnm
, and vcov.ebnm
.
Calling into functions ebnm_point_normal
,
ebnm_point_laplace
,
ebnm_point_exponential
, ebnm_normal
,
ebnm_horseshoe
,
ebnm_normal_scale_mixture
, ebnm_unimodal
,
ebnm_unimodal_symmetric
,
ebnm_unimodal_nonnegative
,
ebnm_unimodal_nonpositive
,
ebnm_generalized_binary
, ebnm_npmle
,
ebnm_deconvolver
, ebnm_flat
,
ebnm_point_mass
, and ebnm_ash
is equivalent to calling into ebnm
with prior_family
set
accordingly.
theta <- c(rep(0, 100), rexp(100)) s <- 1 x <- theta + rnorm(200, 0, s) # The following are equivalent: pn.res <- ebnm(x, s, prior_family = "point_normal") pn.res <- ebnm_point_normal(x, s) # Inspect results: logLik(pn.res) plot(pn.res) # Fix the scale parameter: pl.res <- ebnm_point_laplace(x, s, scale = 1) # Estimate the mode: normal.res <- ebnm_normal(x, s, mode = "estimate") plot(normal.res) # posterior means shrink to a value different from zero # Use an initial g (this fixes mode and scale for ash priors): normalmix.res <- ebnm_normal_scale_mixture(x, s, g_init = pn.res) # Fix g and get different output (including a posterior sampler): pn.res <- ebnm_point_normal(x, s, g_init = pn.res, fix_g = TRUE, output = ebnm_output_all()) # Sample from the posterior: pn.samp <- simulate(pn.res, nsim = 100) # Quantiles and HPD confidence intervals can be obtained via sampling: set.seed(1) pn.quantiles <- quantile(pn.res, probs = c(0.1, 0.9)) pn.quantiles[1:5, ] confint(pn.res, level = 0.8, parm = 1:5) # Examples of usage of control parameter: # point_normal uses nlm: pn.res <- ebnm_point_normal(x, s, control = list(print.level = 1)) # unimodal uses mixsqp: unimodal.res <- ebnm_unimodal(x, s, control = list(verbose = TRUE))
theta <- c(rep(0, 100), rexp(100)) s <- 1 x <- theta + rnorm(200, 0, s) # The following are equivalent: pn.res <- ebnm(x, s, prior_family = "point_normal") pn.res <- ebnm_point_normal(x, s) # Inspect results: logLik(pn.res) plot(pn.res) # Fix the scale parameter: pl.res <- ebnm_point_laplace(x, s, scale = 1) # Estimate the mode: normal.res <- ebnm_normal(x, s, mode = "estimate") plot(normal.res) # posterior means shrink to a value different from zero # Use an initial g (this fixes mode and scale for ash priors): normalmix.res <- ebnm_normal_scale_mixture(x, s, g_init = pn.res) # Fix g and get different output (including a posterior sampler): pn.res <- ebnm_point_normal(x, s, g_init = pn.res, fix_g = TRUE, output = ebnm_output_all()) # Sample from the posterior: pn.samp <- simulate(pn.res, nsim = 100) # Quantiles and HPD confidence intervals can be obtained via sampling: set.seed(1) pn.quantiles <- quantile(pn.res, probs = c(0.1, 0.9)) pn.quantiles[1:5, ] confint(pn.res, level = 0.8, parm = 1:5) # Examples of usage of control parameter: # point_normal uses nlm: pn.res <- ebnm_point_normal(x, s, control = list(print.level = 1)) # unimodal uses mixsqp: unimodal.res <- ebnm_unimodal(x, s, control = list(verbose = TRUE))
Adds a posterior sampler to a fitted ebnm
object.
ebnm_add_sampler(ebnm_res)
ebnm_add_sampler(ebnm_res)
ebnm_res |
The fitted |
The ebnm
object with an additional field
posterior_sampler
.
A wrapper to function ash
in package ashr
.
Identical to function ebnm
with argument
prior_family = "ash"
.
ebnm_ash( x, s = 1, mode = 0, scale = "estimate", g_init = NULL, fix_g = FALSE, output = ebnm_output_default(), control = NULL, ... )
ebnm_ash( x, s = 1, mode = 0, scale = "estimate", g_init = NULL, fix_g = FALSE, output = ebnm_output_default(), control = NULL, ... )
x |
A vector of observations. Missing observations ( |
s |
A vector of standard errors (or a scalar if all are equal). Standard errors may not be exactly zero, and missing standard errors are not allowed. |
mode |
Passed to |
scale |
Passed to |
g_init |
Passed to |
fix_g |
Passed to |
output |
A character vector indicating which values are to be returned.
Function |
control |
Passed to |
... |
Additional parameters to be passed to |
An ebnm
object. Depending on the argument to output
, the
object is a list containing elements:
data
A data frame containing the observations x
and standard errors s
.
posterior
A data frame of summary results (posterior means, standard deviations, second moments, and local false sign rates).
fitted_g
The fitted prior .
log_likelihood
The optimal log likelihood attained,
.
posterior_sampler
A function that can be used to
produce samples from the posterior. The sampler takes a single
parameter nsamp
, the number of posterior samples to return per
observation.
S3 methods coef
, confint
, fitted
, logLik
,
nobs
, plot
, predict
, print
, quantile
,
residuals
, simulate
, summary
, and vcov
have been implemented for ebnm
objects. For details, see the
respective help pages, linked below under See Also.
See ebnm
for examples of usage and model details.
Available S3 methods include coef.ebnm
,
confint.ebnm
,
fitted.ebnm
, logLik.ebnm
,
nobs.ebnm
, plot.ebnm
,
predict.ebnm
, print.ebnm
,
print.summary.ebnm
, quantile.ebnm
,
residuals.ebnm
, simulate.ebnm
,
summary.ebnm
, and vcov.ebnm
.
Checks inputs and outputs of an ebnm-style function. Designed to
troubleshoot custom functions, especially those that are intended for use
in the flashier
package (e.g., as argument to the ebnm_fn
parameter in function flash
).
ebnm_check_fn(fn, x, s)
ebnm_check_fn(fn, x, s)
fn |
The function to be checked. |
x |
A test set (vector) of observations. |
s |
A test set of standard errors. Typically, ebnm-style functions should be able to accept a vector of standard errors or a scalar if all standard errors are identical. This is not always the case; for example, the horseshoe prior family requires homoskedastic standard errors. |
Prints a success message and silently returns 1 if all checks pass. Otherwise the function errors out.
ebnm_check_fn(ebnm_normal, x = rnorm(10, sd = 2), s = 1)
ebnm_check_fn(ebnm_normal, x = rnorm(10, sd = 2), s = 1)
Solves the empirical Bayes normal means (EBNM) problem using a non-parametric
exponential family with a natural spline basis.
Like ebnm_npmle
, there is no unimodal assumption, but whereas
ebnm_npmle
produces spiky estimates for ,
ebnm_deconvolver
estimates are much more regular. See
deconvolveR-package
for details and
references. Identical to function ebnm
with argument
prior_family = "deconvolver"
.
ebnm_deconvolver( x, s = 1, scale = "estimate", g_init = NULL, fix_g = FALSE, output = ebnm_output_default(), control = NULL, ... )
ebnm_deconvolver( x, s = 1, scale = "estimate", g_init = NULL, fix_g = FALSE, output = ebnm_output_default(), control = NULL, ... )
x |
A vector of observations. Missing observations ( |
s |
Standard errors, which must be uniformly equal to 1 (i.e.,
|
scale |
A deconvolveR prior is a finite mixture of point masses
where parameters |
g_init |
The prior distribution |
fix_g |
If |
output |
A character vector indicating which values are to be returned.
Function |
control |
A list of control parameters to be passed to optimization
function |
... |
Additional parameters to be passed to function
|
An ebnm
object. Depending on the argument to output
, the
object is a list containing elements:
data
A data frame containing the observations x
and standard errors s
.
posterior
A data frame of summary results (posterior means, standard deviations, second moments, and local false sign rates).
fitted_g
The fitted prior .
log_likelihood
The optimal log likelihood attained,
.
posterior_sampler
A function that can be used to
produce samples from the posterior. The sampler takes a single
parameter nsamp
, the number of posterior samples to return per
observation.
S3 methods coef
, confint
, fitted
, logLik
,
nobs
, plot
, predict
, print
, quantile
,
residuals
, simulate
, summary
, and vcov
have been implemented for ebnm
objects. For details, see the
respective help pages, linked below under See Also.
See ebnm
for examples of usage and model details.
Available S3 methods include coef.ebnm
,
confint.ebnm
,
fitted.ebnm
, logLik.ebnm
,
nobs.ebnm
, plot.ebnm
,
predict.ebnm
, print.ebnm
,
print.summary.ebnm
, quantile.ebnm
,
residuals.ebnm
, simulate.ebnm
,
summary.ebnm
, and vcov.ebnm
.
Solves the empirical Bayes normal means (EBNM) problem using a "non-informative" improper uniform prior, which yields posteriors
Identical to function
ebnm
with argument prior_family = "flat"
. For details
about the model, see ebnm
.
ebnm_flat( x, s = 1, g_init = NULL, fix_g = FALSE, output = ebnm_output_default() )
ebnm_flat( x, s = 1, g_init = NULL, fix_g = FALSE, output = ebnm_output_default() )
x |
A vector of observations. Missing observations ( |
s |
A vector of standard errors (or a scalar if all are equal). Standard errors may not be exactly zero, and missing standard errors are not allowed. |
g_init |
Not used by |
fix_g |
Not used by |
output |
A character vector indicating which values are to be returned.
Function |
An ebnm
object. Depending on the argument to output
, the
object is a list containing elements:
data
A data frame containing the observations x
and standard errors s
.
posterior
A data frame of summary results (posterior means, standard deviations, second moments, and local false sign rates).
fitted_g
The fitted prior .
log_likelihood
The optimal log likelihood attained,
.
posterior_sampler
A function that can be used to
produce samples from the posterior. The sampler takes a single
parameter nsamp
, the number of posterior samples to return per
observation.
S3 methods coef
, confint
, fitted
, logLik
,
nobs
, plot
, predict
, print
, quantile
,
residuals
, simulate
, summary
, and vcov
have been implemented for ebnm
objects. For details, see the
respective help pages, linked below under See Also.
See ebnm
for examples of usage and model details.
Available S3 methods include coef.ebnm
,
confint.ebnm
,
fitted.ebnm
, logLik.ebnm
,
nobs.ebnm
, plot.ebnm
,
predict.ebnm
, print.ebnm
,
print.summary.ebnm
, quantile.ebnm
,
residuals.ebnm
, simulate.ebnm
,
summary.ebnm
, and vcov.ebnm
.
Solves the empirical Bayes normal means (EBNM) problem using the family of
nonnegative distributions consisting of mixtures where one component is a
point mass at zero and the other is a truncated normal distribution with
lower bound zero and nonzero mode. Typically, the mode is positive, with
the ratio of the mode to the standard deviation taken to be large, so that
posterior estimates are strongly shrunk towards one of two values (zero or
the mode of the normal component).
Identical to function ebnm
with argument
prior_family = "generalized_binary"
.
For details, see Liu et al. (2023), cited in References below.
ebnm_generalized_binary( x, s = 1, mode = "estimate", scale = 0.1, g_init = NULL, fix_g = FALSE, output = ebnm_output_default(), control = NULL, ... )
ebnm_generalized_binary( x, s = 1, mode = "estimate", scale = 0.1, g_init = NULL, fix_g = FALSE, output = ebnm_output_default(), control = NULL, ... )
x |
A vector of observations. Missing observations ( |
s |
A vector of standard errors (or a scalar if all are equal). Standard errors may not be exactly zero, and missing standard errors are not allowed. |
mode |
A scalar specifying the mode of the truncated normal component,
or |
scale |
A scalar specifying the ratio of the (untruncated) standard
deviation of the normal component to its mode. This ratio must be
fixed in advance (i.e., it is not possible to set |
g_init |
The prior distribution |
fix_g |
If |
output |
A character vector indicating which values are to be returned.
Function |
control |
A list of control parameters to be passed to function
|
... |
The following additional arguments act as control parameters for
the outer EM loops in the fitting algorithm. Each loop iteratively updates
parameters
|
An ebnm
object. Depending on the argument to output
, the
object is a list containing elements:
data
A data frame containing the observations x
and standard errors s
.
posterior
A data frame of summary results (posterior means, standard deviations, second moments, and local false sign rates).
fitted_g
The fitted prior .
log_likelihood
The optimal log likelihood attained,
.
posterior_sampler
A function that can be used to
produce samples from the posterior. The sampler takes a single
parameter nsamp
, the number of posterior samples to return per
observation.
S3 methods coef
, confint
, fitted
, logLik
,
nobs
, plot
, predict
, print
, quantile
,
residuals
, simulate
, summary
, and vcov
have been implemented for ebnm
objects. For details, see the
respective help pages, linked below under See Also.
Yusha Liu, Peter Carbonetto, Jason Willwerscheid, Scott A Oakes, Kay F Macleod, and Matthew Stephens (2023). Dissecting tumor transcriptional heterogeneity from single-cell RNA-seq data by generalized binary covariance decomposition. bioRxiv 2023.08.15.553436.
See ebnm
for examples of usage and model details.
Available S3 methods include coef.ebnm
,
confint.ebnm
,
fitted.ebnm
, logLik.ebnm
,
nobs.ebnm
, plot.ebnm
,
predict.ebnm
, print.ebnm
,
print.summary.ebnm
, quantile.ebnm
,
residuals.ebnm
, simulate.ebnm
,
summary.ebnm
, and vcov.ebnm
.
Solves the empirical Bayes normal means (EBNM) problem for observations belonging to distinct groups.
ebnm_group( x, s = 1, group, prior_family = "point_normal", mode = 0, scale = "estimate", g_init = NULL, fix_g = FALSE, output = ebnm_output_default(), ... )
ebnm_group( x, s = 1, group, prior_family = "point_normal", mode = 0, scale = "estimate", g_init = NULL, fix_g = FALSE, output = ebnm_output_default(), ... )
x |
A vector of observations. Missing observations ( |
s |
A vector of standard errors (or a scalar if all are equal).
Standard errors may not be exactly zero, and
missing standard errors are not allowed. Two prior families have
additional restrictions: when horseshoe priors are used, errors
must be homoskedastic; and since function
|
group |
A vector of character strings that gives the group to which each
observation belongs. It must have the same length as argument |
prior_family |
A named vector that specifies the prior family |
mode |
A named list that specifies, for each group, the mode of the
respective prior |
scale |
A named list that specifies, for each group, the scale
parameter(s) of the respective prior, or |
g_init |
The prior distributions |
fix_g |
If |
output |
A character vector indicating which values are to be returned.
Function |
... |
Additional parameters. When a |
The EBNM model for grouped data, with observations belonging to
groups
, is
Solving the EBNM problem for grouped data is equivalent to solving a
separate EBNM problem for each group , with the optimal
log likelihood equal to the sum of the optimal log likelihoods for each
separate problem.
An ebnm
object. Depending on the argument to output
, the
object is a list containing elements:
data
A data frame containing the observations x
and standard errors s
.
posterior
A data frame of summary results (posterior means, standard deviations, second moments, and local false sign rates).
fitted_g
The fitted prior (an object of
class
normalmix
, laplacemix
,
gammamix
, unimix
,
tnormalmix
, or horseshoe
).
log_likelihood
The optimal log likelihood attained,
.
posterior_sampler
A function that can be used to
produce samples from the posterior. For all prior families other
than the horseshoe, the sampler takes a single parameter
nsamp
, the number of posterior samples to return per
observation. Since ebnm_horseshoe
returns an MCMC sampler,
it additionally takes parameter burn
, the number of burn-in
samples to discard.
S3 methods coef
, confint
, fitted
, logLik
,
nobs
, plot
, predict
, print
, quantile
,
residuals
, simulate
, summary
, and vcov
have been implemented for ebnm
objects. For details, see the
respective help pages, linked below under See Also.
group <- c(rep("small_sd", 100), rep("large_sd", 100)) theta <- c(rnorm(100, sd = 1), rnorm(100, sd = 10)) s <- 1 x <- theta + rnorm(200, 0, s) ebnm.group.res <- ebnm_group(x, s, group) # Use different prior families for each group: ebnm.group.res <- ebnm_group( x, s, group, prior_family = list(small_sd = "normal", large_sd = "normal_scale_mixture") ) # Different modes and scales can be set similarly: ebnm.group.res <- ebnm_group( x, s, group, mode = list(small_sd = 0, large_sd = "estimate"), scale = list(small_sd = 1, large_sd = "estimate") )
group <- c(rep("small_sd", 100), rep("large_sd", 100)) theta <- c(rnorm(100, sd = 1), rnorm(100, sd = 10)) s <- 1 x <- theta + rnorm(200, 0, s) ebnm.group.res <- ebnm_group(x, s, group) # Use different prior families for each group: ebnm.group.res <- ebnm_group( x, s, group, prior_family = list(small_sd = "normal", large_sd = "normal_scale_mixture") ) # Different modes and scales can be set similarly: ebnm.group.res <- ebnm_group( x, s, group, mode = list(small_sd = 0, large_sd = "estimate"), scale = list(small_sd = 1, large_sd = "estimate") )
Solves the empirical Bayes normal means (EBNM) problem using the family of
horseshoe distributions. Identical to function ebnm
with argument prior_family = "horseshoe"
. For details about the
model, see ebnm
.
ebnm_horseshoe( x, s = 1, scale = "estimate", g_init = NULL, fix_g = FALSE, output = ebnm_output_default(), control = NULL )
ebnm_horseshoe( x, s = 1, scale = "estimate", g_init = NULL, fix_g = FALSE, output = ebnm_output_default(), control = NULL )
x |
A vector of observations. Missing observations ( |
s |
A scalar specifying the standard error of the observations (observations must be homoskedastic). |
scale |
A scalar corresponding to |
g_init |
The prior distribution |
fix_g |
If |
output |
A character vector indicating which values are to be returned.
Function |
control |
A list of control parameters to be passed to function
|
An ebnm
object. Depending on the argument to output
, the
object is a list containing elements:
data
A data frame containing the observations x
and standard errors s
.
posterior
A data frame of summary results (posterior means, standard deviations, second moments, and local false sign rates).
fitted_g
The fitted prior .
log_likelihood
The optimal log likelihood attained,
.
posterior_sampler
A function that can be used to
produce samples from the posterior. The function takes parameters
nsamp
, the number of posterior samples to return per
observation, and burn
, the number of burn-in samples to
discard (an MCMC sampler is used).
S3 methods coef
, confint
, fitted
, logLik
,
nobs
, plot
, predict
, print
, quantile
,
residuals
, simulate
, summary
, and vcov
have been implemented for ebnm
objects. For details, see the
respective help pages, linked below under See Also.
See ebnm
for examples of usage and model details.
Available S3 methods include coef.ebnm
,
confint.ebnm
,
fitted.ebnm
, logLik.ebnm
,
nobs.ebnm
, plot.ebnm
,
predict.ebnm
, print.ebnm
,
print.summary.ebnm
, quantile.ebnm
,
residuals.ebnm
, simulate.ebnm
,
summary.ebnm
, and vcov.ebnm
.
Solves the empirical Bayes normal means (EBNM) problem using the family of
normal distributions. Identical to function ebnm
with
argument prior_family = "normal"
. For details about the model, see
ebnm
.
ebnm_normal( x, s = 1, mode = 0, scale = "estimate", g_init = NULL, fix_g = FALSE, output = ebnm_output_default(), optmethod = NULL, control = NULL )
ebnm_normal( x, s = 1, mode = 0, scale = "estimate", g_init = NULL, fix_g = FALSE, output = ebnm_output_default(), optmethod = NULL, control = NULL )
x |
A vector of observations. Missing observations ( |
s |
A vector of standard errors (or a scalar if all are equal). Standard errors may not be exactly zero, and missing standard errors are not allowed. |
mode |
A scalar specifying the mode of the prior |
scale |
A scalar specifying the standard deviation of the normal prior
or |
g_init |
The prior distribution |
fix_g |
If |
output |
A character vector indicating which values are to be returned.
Function |
optmethod |
A string specifying which optimization function is to be
used. Options include |
control |
A list of control parameters to be passed to the
optimization function specified by parameter |
An ebnm
object. Depending on the argument to output
, the
object is a list containing elements:
data
A data frame containing the observations x
and standard errors s
.
posterior
A data frame of summary results (posterior means, standard deviations, second moments, and local false sign rates).
fitted_g
The fitted prior .
log_likelihood
The optimal log likelihood attained,
.
posterior_sampler
A function that can be used to
produce samples from the posterior. The sampler takes a single
parameter nsamp
, the number of posterior samples to return per
observation.
S3 methods coef
, confint
, fitted
, logLik
,
nobs
, plot
, predict
, print
, quantile
,
residuals
, simulate
, summary
, and vcov
have been implemented for ebnm
objects. For details, see the
respective help pages, linked below under See Also.
See ebnm
for examples of usage and model details.
Available S3 methods include coef.ebnm
,
confint.ebnm
,
fitted.ebnm
, logLik.ebnm
,
nobs.ebnm
, plot.ebnm
,
predict.ebnm
, print.ebnm
,
print.summary.ebnm
, quantile.ebnm
,
residuals.ebnm
, simulate.ebnm
,
summary.ebnm
, and vcov.ebnm
.
Solves the empirical Bayes normal means (EBNM) problem using the family of
scale mixtures of normals. Identical to function ebnm
with argument prior_family = "normal_scale_mixture"
. For details
about the model, see ebnm
.
ebnm_normal_scale_mixture( x, s = 1, mode = 0, scale = "estimate", g_init = NULL, fix_g = FALSE, output = ebnm_output_default(), optmethod = NULL, control = NULL, ... )
ebnm_normal_scale_mixture( x, s = 1, mode = 0, scale = "estimate", g_init = NULL, fix_g = FALSE, output = ebnm_output_default(), optmethod = NULL, control = NULL, ... )
x |
A vector of observations. Missing observations ( |
s |
A vector of standard errors (or a scalar if all are equal). Standard errors may not be exactly zero, and missing standard errors are not allowed. |
mode |
A scalar specifying the mode of the prior |
scale |
The nonparametric family of scale mixtures of normals is approximated via a finite mixture of normal distributions
where parameters |
g_init |
The prior distribution |
fix_g |
If |
output |
A character vector indicating which values are to be returned.
Function |
optmethod |
A string specifying which optimization function is to be
used. Options are provided by package
|
control |
A list of control parameters to be passed to the
optimization function specified by parameter |
... |
When parameter |
An ebnm
object. Depending on the argument to output
, the
object is a list containing elements:
data
A data frame containing the observations x
and standard errors s
.
posterior
A data frame of summary results (posterior means, standard deviations, second moments, and local false sign rates).
fitted_g
The fitted prior .
log_likelihood
The optimal log likelihood attained,
.
posterior_sampler
A function that can be used to
produce samples from the posterior. The sampler takes a single
parameter nsamp
, the number of posterior samples to return per
observation.
S3 methods coef
, confint
, fitted
, logLik
,
nobs
, plot
, predict
, print
, quantile
,
residuals
, simulate
, summary
, and vcov
have been implemented for ebnm
objects. For details, see the
respective help pages, linked below under See Also.
See ebnm
for examples of usage and model details.
Available S3 methods include coef.ebnm
,
confint.ebnm
,
fitted.ebnm
, logLik.ebnm
,
nobs.ebnm
, plot.ebnm
,
predict.ebnm
, print.ebnm
,
print.summary.ebnm
, quantile.ebnm
,
residuals.ebnm
, simulate.ebnm
,
summary.ebnm
, and vcov.ebnm
.
Solves the empirical Bayes normal means (EBNM) problem using the family
of all distributions. Identical to function ebnm
with argument
prior_family = "npmle"
. For details about the model, see
ebnm
.
ebnm_npmle( x, s = 1, scale = "estimate", g_init = NULL, fix_g = FALSE, output = ebnm_output_default(), optmethod = NULL, control = NULL )
ebnm_npmle( x, s = 1, scale = "estimate", g_init = NULL, fix_g = FALSE, output = ebnm_output_default(), optmethod = NULL, control = NULL )
x |
A vector of observations. Missing observations ( |
s |
A vector of standard errors (or a scalar if all are equal). Standard errors may not be exactly zero, and missing standard errors are not allowed. |
scale |
The nonparametric family of all distributions is approximated via a finite mixture of point masses
where parameters |
g_init |
The prior distribution |
fix_g |
If |
output |
A character vector indicating which values are to be returned.
Function |
optmethod |
A string specifying which optimization function is to be
used. Options are provided by package
|
control |
A list of control parameters to be passed to the
optimization function specified by parameter |
An ebnm
object. Depending on the argument to output
, the
object is a list containing elements:
data
A data frame containing the observations x
and standard errors s
.
posterior
A data frame of summary results (posterior means, standard deviations, second moments, and local false sign rates).
fitted_g
The fitted prior .
log_likelihood
The optimal log likelihood attained,
.
posterior_sampler
A function that can be used to
produce samples from the posterior. The sampler takes a single
parameter nsamp
, the number of posterior samples to return per
observation.
S3 methods coef
, confint
, fitted
, logLik
,
nobs
, plot
, predict
, print
, quantile
,
residuals
, simulate
, summary
, and vcov
have been implemented for ebnm
objects. For details, see the
respective help pages, linked below under See Also.
See ebnm
for examples of usage and model details.
Available S3 methods include coef.ebnm
,
confint.ebnm
,
fitted.ebnm
, logLik.ebnm
,
nobs.ebnm
, plot.ebnm
,
predict.ebnm
, print.ebnm
,
print.summary.ebnm
, quantile.ebnm
,
residuals.ebnm
, simulate.ebnm
,
summary.ebnm
, and vcov.ebnm
.
Solves the empirical Bayes normal means (EBNM) problem using the
family of point-exponential priors (the family of mixtures where
one component is a point mass at and the other is a
(nonnegative) exponential distribution with mode
). Identical to function
ebnm
with argument
prior_family = "point_exponential"
. For details about the
model, see ebnm
.
ebnm_point_exponential( x, s = 1, mode = 0, scale = "estimate", g_init = NULL, fix_g = FALSE, output = ebnm_output_default(), optmethod = NULL, control = NULL )
ebnm_point_exponential( x, s = 1, mode = 0, scale = "estimate", g_init = NULL, fix_g = FALSE, output = ebnm_output_default(), optmethod = NULL, control = NULL )
x |
A vector of observations. Missing observations ( |
s |
A vector of standard errors (or a scalar if all are equal). Standard errors may not be exactly zero, and missing standard errors are not allowed. |
mode |
A scalar specifying the mode of the prior |
scale |
A scalar specifying the scale parameter of the
exponential component or |
g_init |
The prior distribution |
fix_g |
If |
output |
A character vector indicating which values are to be returned.
Function |
optmethod |
A string specifying which optimization function is to be
used. Options include |
control |
A list of control parameters to be passed to the
optimization function specified by parameter |
An ebnm
object. Depending on the argument to output
, the
object is a list containing elements:
data
A data frame containing the observations x
and standard errors s
.
posterior
A data frame of summary results (posterior means, standard deviations, second moments, and local false sign rates).
fitted_g
The fitted prior .
log_likelihood
The optimal log likelihood attained,
.
posterior_sampler
A function that can be used to
produce samples from the posterior. The sampler takes a single
parameter nsamp
, the number of posterior samples to return per
observation.
S3 methods coef
, confint
, fitted
, logLik
,
nobs
, plot
, predict
, print
, quantile
,
residuals
, simulate
, summary
, and vcov
have been implemented for ebnm
objects. For details, see the
respective help pages, linked below under See Also.
See ebnm
for examples of usage and model details.
Available S3 methods include coef.ebnm
,
confint.ebnm
,
fitted.ebnm
, logLik.ebnm
,
nobs.ebnm
, plot.ebnm
,
predict.ebnm
, print.ebnm
,
print.summary.ebnm
, quantile.ebnm
,
residuals.ebnm
, simulate.ebnm
,
summary.ebnm
, and vcov.ebnm
.
Solves the empirical Bayes normal means (EBNM) problem using the family of
point-Laplace priors (the family of mixtures where one component is a point
mass at and the other is a double-exponential distribution
centered at
). Identical to function
ebnm
with argument
prior_family = "point_laplace"
. For details about the model, see
ebnm
.
ebnm_point_laplace( x, s = 1, mode = 0, scale = "estimate", g_init = NULL, fix_g = FALSE, output = ebnm_output_default(), optmethod = NULL, control = NULL )
ebnm_point_laplace( x, s = 1, mode = 0, scale = "estimate", g_init = NULL, fix_g = FALSE, output = ebnm_output_default(), optmethod = NULL, control = NULL )
x |
A vector of observations. Missing observations ( |
s |
A vector of standard errors (or a scalar if all are equal). Standard errors may not be exactly zero, and missing standard errors are not allowed. |
mode |
A scalar specifying the mode of the prior |
scale |
A scalar specifying the scale parameter of the Laplace
component or |
g_init |
The prior distribution |
fix_g |
If |
output |
A character vector indicating which values are to be returned.
Function |
optmethod |
A string specifying which optimization function is to be
used. Options include |
control |
A list of control parameters to be passed to the
optimization function specified by parameter |
An ebnm
object. Depending on the argument to output
, the
object is a list containing elements:
data
A data frame containing the observations x
and standard errors s
.
posterior
A data frame of summary results (posterior means, standard deviations, second moments, and local false sign rates).
fitted_g
The fitted prior .
log_likelihood
The optimal log likelihood attained,
.
posterior_sampler
A function that can be used to
produce samples from the posterior. The sampler takes a single
parameter nsamp
, the number of posterior samples to return per
observation.
S3 methods coef
, confint
, fitted
, logLik
,
nobs
, plot
, predict
, print
, quantile
,
residuals
, simulate
, summary
, and vcov
have been implemented for ebnm
objects. For details, see the
respective help pages, linked below under See Also.
See ebnm
for examples of usage and model details.
Available S3 methods include coef.ebnm
,
confint.ebnm
,
fitted.ebnm
, logLik.ebnm
,
nobs.ebnm
, plot.ebnm
,
predict.ebnm
, print.ebnm
,
print.summary.ebnm
, quantile.ebnm
,
residuals.ebnm
, simulate.ebnm
,
summary.ebnm
, and vcov.ebnm
.
Solves the empirical Bayes normal means (EBNM) problem using the family of
point masses . Posteriors are simply point masses at
.
Identical to function
ebnm
with argument
prior_family = "point_mass"
. For details about the model, see
ebnm
.
ebnm_point_mass( x, s = 1, mode = 0, g_init = NULL, fix_g = FALSE, output = ebnm_output_default(), control = NULL )
ebnm_point_mass( x, s = 1, mode = 0, g_init = NULL, fix_g = FALSE, output = ebnm_output_default(), control = NULL )
x |
A vector of observations. Missing observations ( |
s |
A vector of standard errors (or a scalar if all are equal). Standard errors may not be exactly zero, and missing standard errors are not allowed. |
mode |
A scalar specifying the location of the point mass or
|
g_init |
The prior distribution |
fix_g |
If |
output |
A character vector indicating which values are to be returned.
Function |
control |
A list of control parameters to be passed to function
|
An ebnm
object. Depending on the argument to output
, the
object is a list containing elements:
data
A data frame containing the observations x
and standard errors s
.
posterior
A data frame of summary results (posterior means, standard deviations, second moments, and local false sign rates).
fitted_g
The fitted prior .
log_likelihood
The optimal log likelihood attained,
.
posterior_sampler
A function that can be used to
produce samples from the posterior. The sampler takes a single
parameter nsamp
, the number of posterior samples to return per
observation.
S3 methods coef
, confint
, fitted
, logLik
,
nobs
, plot
, predict
, print
, quantile
,
residuals
, simulate
, summary
, and vcov
have been implemented for ebnm
objects. For details, see the
respective help pages, linked below under See Also.
See ebnm
for examples of usage and model details.
Available S3 methods include coef.ebnm
,
confint.ebnm
,
fitted.ebnm
, logLik.ebnm
,
nobs.ebnm
, plot.ebnm
,
predict.ebnm
, print.ebnm
,
print.summary.ebnm
, quantile.ebnm
,
residuals.ebnm
, simulate.ebnm
,
summary.ebnm
, and vcov.ebnm
.
Solves the empirical Bayes normal means (EBNM) problem using the family of
point-normal priors (the family of mixtures where one component is a point
mass at and the other is a normal distribution centered at
). Identical to function
ebnm
with argument
prior_family = "point_normal"
. For details about the model, see
ebnm
.
ebnm_point_normal( x, s = 1, mode = 0, scale = "estimate", g_init = NULL, fix_g = FALSE, output = ebnm_output_default(), optmethod = NULL, control = NULL )
ebnm_point_normal( x, s = 1, mode = 0, scale = "estimate", g_init = NULL, fix_g = FALSE, output = ebnm_output_default(), optmethod = NULL, control = NULL )
x |
A vector of observations. Missing observations ( |
s |
A vector of standard errors (or a scalar if all are equal). Standard errors may not be exactly zero, and missing standard errors are not allowed. |
mode |
A scalar specifying the mode of the prior |
scale |
A scalar specifying the standard deviation of the normal
component or |
g_init |
The prior distribution |
fix_g |
If |
output |
A character vector indicating which values are to be returned.
Function |
optmethod |
A string specifying which optimization function is to be
used. Options include |
control |
A list of control parameters to be passed to the
optimization function specified by parameter |
An ebnm
object. Depending on the argument to output
, the
object is a list containing elements:
data
A data frame containing the observations x
and standard errors s
.
posterior
A data frame of summary results (posterior means, standard deviations, second moments, and local false sign rates).
fitted_g
The fitted prior .
log_likelihood
The optimal log likelihood attained,
.
posterior_sampler
A function that can be used to
produce samples from the posterior. The sampler takes a single
parameter nsamp
, the number of posterior samples to return per
observation.
S3 methods coef
, confint
, fitted
, logLik
,
nobs
, plot
, predict
, print
, quantile
,
residuals
, simulate
, summary
, and vcov
have been implemented for ebnm
objects. For details, see the
respective help pages, linked below under See Also.
See ebnm
for examples of usage and model details.
Available S3 methods include coef.ebnm
,
confint.ebnm
,
fitted.ebnm
, logLik.ebnm
,
nobs.ebnm
, plot.ebnm
,
predict.ebnm
, print.ebnm
,
print.summary.ebnm
, quantile.ebnm
,
residuals.ebnm
, simulate.ebnm
,
summary.ebnm
, and vcov.ebnm
.
The default method for setting the scale
parameter for function
ebnm_normal_scale_mixture
.
ebnm_scale_normalmix( x, s, mode = 0, min_K = 3, max_K = 300, KLdiv_target = 1/length(x) )
ebnm_scale_normalmix( x, s, mode = 0, min_K = 3, max_K = 300, KLdiv_target = 1/length(x) )
x |
A vector of observations. Missing observations ( |
s |
A vector of standard errors (or a scalar if all are equal). Standard errors may not be exactly zero, and missing standard errors are not allowed. |
mode |
A scalar specifying the mode of the prior |
min_K |
The minimum number of components |
max_K |
The maximum number of components |
KLdiv_target |
The desired bound
where
we have that
where |
Jason Willwerscheid (2021). Empirical Bayes Matrix Factorization: Methods and Applications. University of Chicago, PhD dissertation.
The default method for setting the scale
parameter for functions
ebnm_npmle
and ebnm_deconvolver
.
ebnm_scale_npmle( x, s, min_K = 3, max_K = 300, KLdiv_target = 1/length(x), pointmass = TRUE )
ebnm_scale_npmle( x, s, min_K = 3, max_K = 300, KLdiv_target = 1/length(x), pointmass = TRUE )
x |
A vector of observations. Missing observations ( |
s |
A vector of standard errors (or a scalar if all are equal). Standard errors may not be exactly zero, and missing standard errors are not allowed. |
min_K |
The minimum number of components |
max_K |
The maximum number of components |
KLdiv_target |
The desired bound
where
we have that
where |
pointmass |
When the range of the data is so large that To be exact,
for a
rationale, see References below. Note however that |
Jason Willwerscheid (2021). Empirical Bayes Matrix Factorization: Methods and Applications. University of Chicago, PhD dissertation.
The default method for setting the scale
parameter for functions
ebnm_unimodal
, ebnm_unimodal_symmetric
,
ebnm_unimodal_nonnegative
, and
ebnm_unimodal_nonpositive
.
ebnm_scale_unimix( x, s, mode = 0, min_K = 3, max_K = 300, KLdiv_target = 1/length(x) )
ebnm_scale_unimix( x, s, mode = 0, min_K = 3, max_K = 300, KLdiv_target = 1/length(x) )
x |
A vector of observations. Missing observations ( |
s |
A vector of standard errors (or a scalar if all are equal). Standard errors may not be exactly zero, and missing standard errors are not allowed. |
mode |
A scalar specifying the mode of the prior |
min_K |
The minimum number of components |
max_K |
The maximum number of components |
KLdiv_target |
The desired bound
where
we have that
where |
Jason Willwerscheid (2021). Empirical Bayes Matrix Factorization: Methods and Applications. University of Chicago, PhD dissertation.
Solves the empirical Bayes normal means (EBNM) problem using the family of
all unimodal distributions. Identical to function ebnm
with argument prior_family = "unimodal"
. For details
about the model, see ebnm
.
ebnm_unimodal( x, s = 1, mode = 0, scale = "estimate", g_init = NULL, fix_g = FALSE, output = ebnm_output_default(), optmethod = NULL, control = NULL, ... )
ebnm_unimodal( x, s = 1, mode = 0, scale = "estimate", g_init = NULL, fix_g = FALSE, output = ebnm_output_default(), optmethod = NULL, control = NULL, ... )
x |
A vector of observations. Missing observations ( |
s |
A vector of standard errors (or a scalar if all are equal). Standard errors may not be exactly zero, and missing standard errors are not allowed. |
mode |
A scalar specifying the mode of the prior |
scale |
The nonparametric family of unimodal distributions is approximated via a finite mixture of uniform distributions
where parameters |
g_init |
The prior distribution |
fix_g |
If |
output |
A character vector indicating which values are to be returned.
Function |
optmethod |
A string specifying which optimization function is to be
used. Options are provided by package
|
control |
A list of control parameters to be passed to the
optimization function specified by parameter |
... |
Additional parameters to be passed to function
|
An ebnm
object. Depending on the argument to output
, the
object is a list containing elements:
data
A data frame containing the observations x
and standard errors s
.
posterior
A data frame of summary results (posterior means, standard deviations, second moments, and local false sign rates).
fitted_g
The fitted prior .
log_likelihood
The optimal log likelihood attained,
.
posterior_sampler
A function that can be used to
produce samples from the posterior. The sampler takes a single
parameter nsamp
, the number of posterior samples to return per
observation.
S3 methods coef
, confint
, fitted
, logLik
,
nobs
, plot
, predict
, print
, quantile
,
residuals
, simulate
, summary
, and vcov
have been implemented for ebnm
objects. For details, see the
respective help pages, linked below under See Also.
See ebnm
for examples of usage and model details.
Available S3 methods include coef.ebnm
,
confint.ebnm
,
fitted.ebnm
, logLik.ebnm
,
nobs.ebnm
, plot.ebnm
,
predict.ebnm
, print.ebnm
,
print.summary.ebnm
, quantile.ebnm
,
residuals.ebnm
, simulate.ebnm
,
summary.ebnm
, and vcov.ebnm
.
Solves the empirical Bayes normal means (EBNM) problem using the family of
unimodal distributions with support constrained to be greater than the
mode. Identical to function ebnm
with argument
prior_family = "unimodal_nonnegative"
. For details about the model,
see ebnm
.
ebnm_unimodal_nonnegative( x, s = 1, mode = 0, scale = "estimate", g_init = NULL, fix_g = FALSE, output = ebnm_output_default(), optmethod = NULL, control = NULL, ... )
ebnm_unimodal_nonnegative( x, s = 1, mode = 0, scale = "estimate", g_init = NULL, fix_g = FALSE, output = ebnm_output_default(), optmethod = NULL, control = NULL, ... )
x |
A vector of observations. Missing observations ( |
s |
A vector of standard errors (or a scalar if all are equal). Standard errors may not be exactly zero, and missing standard errors are not allowed. |
mode |
A scalar specifying the mode of the prior |
scale |
The nonparametric family of nonnegative unimodal distributions is approximated via a finite mixture of uniform distributions
where parameters |
g_init |
The prior distribution |
fix_g |
If |
output |
A character vector indicating which values are to be returned.
Function |
optmethod |
A string specifying which optimization function is to be
used. Options are provided by package
|
control |
A list of control parameters to be passed to the
optimization function specified by parameter |
... |
Additional parameters to be passed to function
|
An ebnm
object. Depending on the argument to output
, the
object is a list containing elements:
data
A data frame containing the observations x
and standard errors s
.
posterior
A data frame of summary results (posterior means, standard deviations, second moments, and local false sign rates).
fitted_g
The fitted prior .
log_likelihood
The optimal log likelihood attained,
.
posterior_sampler
A function that can be used to
produce samples from the posterior. The sampler takes a single
parameter nsamp
, the number of posterior samples to return per
observation.
S3 methods coef
, confint
, fitted
, logLik
,
nobs
, plot
, predict
, print
, quantile
,
residuals
, simulate
, summary
, and vcov
have been implemented for ebnm
objects. For details, see the
respective help pages, linked below under See Also.
See ebnm
for examples of usage and model details.
Available S3 methods include coef.ebnm
,
confint.ebnm
,
fitted.ebnm
, logLik.ebnm
,
nobs.ebnm
, plot.ebnm
,
predict.ebnm
, print.ebnm
,
print.summary.ebnm
, quantile.ebnm
,
residuals.ebnm
, simulate.ebnm
,
summary.ebnm
, and vcov.ebnm
.
Solves the empirical Bayes normal means (EBNM) problem using the family of
unimodal distributions with support constrained to be less than the
mode. Identical to function ebnm
with argument
prior_family = "unimodal_nonpositive"
. For details about the model,
see ebnm
.
ebnm_unimodal_nonpositive( x, s = 1, mode = 0, scale = "estimate", g_init = NULL, fix_g = FALSE, output = ebnm_output_default(), optmethod = NULL, control = NULL, ... )
ebnm_unimodal_nonpositive( x, s = 1, mode = 0, scale = "estimate", g_init = NULL, fix_g = FALSE, output = ebnm_output_default(), optmethod = NULL, control = NULL, ... )
x |
A vector of observations. Missing observations ( |
s |
A vector of standard errors (or a scalar if all are equal). Standard errors may not be exactly zero, and missing standard errors are not allowed. |
mode |
A scalar specifying the mode of the prior |
scale |
The nonparametric family of nonnpositive unimodal distributions is approximated via a finite mixture of uniform distributions
where parameters |
g_init |
The prior distribution |
fix_g |
If |
output |
A character vector indicating which values are to be returned.
Function |
optmethod |
A string specifying which optimization function is to be
used. Options are provided by package
|
control |
A list of control parameters to be passed to the
optimization function specified by parameter |
... |
Additional parameters to be passed to function
|
An ebnm
object. Depending on the argument to output
, the
object is a list containing elements:
data
A data frame containing the observations x
and standard errors s
.
posterior
A data frame of summary results (posterior means, standard deviations, second moments, and local false sign rates).
fitted_g
The fitted prior .
log_likelihood
The optimal log likelihood attained,
.
posterior_sampler
A function that can be used to
produce samples from the posterior. The sampler takes a single
parameter nsamp
, the number of posterior samples to return per
observation.
S3 methods coef
, confint
, fitted
, logLik
,
nobs
, plot
, predict
, print
, quantile
,
residuals
, simulate
, summary
, and vcov
have been implemented for ebnm
objects. For details, see the
respective help pages, linked below under See Also.
See ebnm
for examples of usage and model details.
Available S3 methods include coef.ebnm
,
confint.ebnm
,
fitted.ebnm
, logLik.ebnm
,
nobs.ebnm
, plot.ebnm
,
predict.ebnm
, print.ebnm
,
print.summary.ebnm
, quantile.ebnm
,
residuals.ebnm
, simulate.ebnm
,
summary.ebnm
, and vcov.ebnm
.
Solves the empirical Bayes normal means (EBNM) problem using the family of
symmetric unimodal distributions. Identical to function ebnm
with argument prior_family = "unimodal_symmetric"
. For details
about the model, see ebnm
.
ebnm_unimodal_symmetric( x, s = 1, mode = 0, scale = "estimate", g_init = NULL, fix_g = FALSE, output = ebnm_output_default(), optmethod = NULL, control = NULL, ... )
ebnm_unimodal_symmetric( x, s = 1, mode = 0, scale = "estimate", g_init = NULL, fix_g = FALSE, output = ebnm_output_default(), optmethod = NULL, control = NULL, ... )
x |
A vector of observations. Missing observations ( |
s |
A vector of standard errors (or a scalar if all are equal). Standard errors may not be exactly zero, and missing standard errors are not allowed. |
mode |
A scalar specifying the mode of the prior |
scale |
The nonparametric family of symmetric unimodal distributions is approximated via a finite mixture of uniform distributions
where parameters |
g_init |
The prior distribution |
fix_g |
If |
output |
A character vector indicating which values are to be returned.
Function |
optmethod |
A string specifying which optimization function is to be
used. Options are provided by package
|
control |
A list of control parameters to be passed to the
optimization function specified by parameter |
... |
Additional parameters to be passed to function
|
An ebnm
object. Depending on the argument to output
, the
object is a list containing elements:
data
A data frame containing the observations x
and standard errors s
.
posterior
A data frame of summary results (posterior means, standard deviations, second moments, and local false sign rates).
fitted_g
The fitted prior .
log_likelihood
The optimal log likelihood attained,
.
posterior_sampler
A function that can be used to
produce samples from the posterior. The sampler takes a single
parameter nsamp
, the number of posterior samples to return per
observation.
S3 methods coef
, confint
, fitted
, logLik
,
nobs
, plot
, predict
, print
, quantile
,
residuals
, simulate
, summary
, and vcov
have been implemented for ebnm
objects. For details, see the
respective help pages, linked below under See Also.
See ebnm
for examples of usage and model details.
Available S3 methods include coef.ebnm
,
confint.ebnm
,
fitted.ebnm
, logLik.ebnm
,
nobs.ebnm
, plot.ebnm
,
predict.ebnm
, print.ebnm
,
print.summary.ebnm
, quantile.ebnm
,
residuals.ebnm
, simulate.ebnm
,
summary.ebnm
, and vcov.ebnm
.
The fitted
method for class ebnm
.
Returns a data frame that includes posterior means, standard deviations,
and local false sign rates (when available).
## S3 method for class 'ebnm' fitted(object, ...)
## S3 method for class 'ebnm' fitted(object, ...)
object |
The fitted |
... |
Not used. Included for consistency as an S3 method. |
Creates a finite mixture of gamma distributions.
gammamix(pi, shape, scale, shift = rep(0, length(pi)))
gammamix(pi, shape, scale, shift = rep(0, length(pi)))
pi |
A vector of mixture proportions. |
shape |
A vector of shape parameters. |
scale |
A vector of scale parameters. |
shift |
A vector of shift parameters. |
An object of class gammamix
(a list with elements
pi
, shape
, scale
, and shift
, described above).
Creates a horseshoe prior (see Carvalho, Polson, and Scott (2010)). The
horseshoe is usually parametrized as
,
,
with
the variance of the error distribution. We use a single
parameter
scale
, which corresponds to and thus does
not depend on the error distribution.
horseshoe(scale)
horseshoe(scale)
scale |
The scale parameter (must be a scalar). |
An object of class horseshoe
(a list with a single element
scale
, described above).
Creates a finite mixture of Laplace distributions.
laplacemix(pi, mean, scale)
laplacemix(pi, mean, scale)
pi |
A vector of mixture proportions. |
mean |
A vector of means. |
scale |
A vector of scale parameters. |
An object of class laplacemix
(a list with elements
pi
, mean
, and scale
, described above).
The logLik
method for class ebnm
.
## S3 method for class 'ebnm' logLik(object, ...)
## S3 method for class 'ebnm' logLik(object, ...)
object |
The fitted |
... |
Not used. Included for consistency as an S3 method. |
An object of class logLik
, which includes attributes df
,
the degrees of freedom — i.e., number of parameters in the model —, and
nobs
, the number of observations in the data.
The nobs
method for class ebnm
.
## S3 method for class 'ebnm' nobs(object, ...)
## S3 method for class 'ebnm' nobs(object, ...)
object |
The fitted |
... |
Not used. Included for consistency as an S3 method. |
The number of observations used to fit the ebnm
object.
Given one or more fitted ebnm
object(s), produces a plot of
posterior means vs. observations. If desired, a plot of cumulative
distribution functions of fitted prior(s) can also be produced.
## S3 method for class 'ebnm' plot( x, ..., incl_pm = TRUE, incl_cdf = FALSE, subset = NULL, remove_abline = FALSE )
## S3 method for class 'ebnm' plot( x, ..., incl_pm = TRUE, incl_cdf = FALSE, subset = NULL, remove_abline = FALSE )
x |
The fitted |
... |
Additional |
incl_pm |
Plot posterior means vs. observations? |
incl_cdf |
Plot the cumulative distribution functions? |
subset |
The subset of observations to include on the plot of posterior
means vs. observations. Can be a numeric vector corresponding to indices
of observations to plot, or a character vector if observations are named.
If |
remove_abline |
To better illustrate shrinkage effects, the plot of
posterior means vs. observations includes the line |
theta <- c(rep(0, 100), rexp(100)) theta[1:50] <- 0 s <- 1 x <- theta + rnorm(200, 0, s) pn.res <- ebnm_point_normal(x, s) plot(pn.res) pe.res <- ebnm_point_exponential(x, s) plot(pn.res, pe.res) # Customize plot: library(ggplot2) plot(pn.res, pe.res, remove_abline = TRUE) + theme_bw() + labs(x = "Simulated data")
theta <- c(rep(0, 100), rexp(100)) theta[1:50] <- 0 s <- 1 x <- theta + rnorm(200, 0, s) pn.res <- ebnm_point_normal(x, s) plot(pn.res) pe.res <- ebnm_point_exponential(x, s) plot(pn.res, pe.res) # Customize plot: library(ggplot2) plot(pn.res, pe.res, remove_abline = TRUE) + theme_bw() + labs(x = "Simulated data")
The predict
method for class ebnm
.
## S3 method for class 'ebnm' predict(object, newdata, s = 1, ...)
## S3 method for class 'ebnm' predict(object, newdata, s = 1, ...)
object |
The fitted |
newdata |
A vector of new observations. Missing observations
( |
s |
A vector of standard errors (or a scalar if all are equal).
Standard errors may not be exactly zero, and
missing standard errors are not allowed. Two prior families have
additional restrictions: when horseshoe priors are used, errors
must be homoskedastic; and since function
|
... |
Not used. Included for consistency as an S3 method. |
A data frame that includes posterior means, posterior standard
deviations, and local false sign rates for the observations in newdata
.
The print
method for class ebnm
.
## S3 method for class 'ebnm' print(x, digits = 2, ...)
## S3 method for class 'ebnm' print(x, digits = 2, ...)
x |
The fitted |
digits |
Number of significant digits to use. |
... |
Not used. Included for consistency as an S3 method. |
The print
method for class summary.ebnm
.
## S3 method for class 'summary.ebnm' print(x, digits = 2, ...)
## S3 method for class 'summary.ebnm' print(x, digits = 2, ...)
x |
The |
digits |
Number of significant digits to use. |
... |
Not used. Included for consistency as an S3 method. |
The quantile
method for class ebnm
.
Quantiles for posterior distributions are
estimated via sampling. By default,
ebnm
does not return a
posterior sampler; one can be added to the ebnm
object using
function ebnm_add_sampler
.
## S3 method for class 'ebnm' quantile( x, probs = seq(0, 1, 0.25), names = TRUE, type = 7, digits = 7, nsim = 1000, ... )
## S3 method for class 'ebnm' quantile( x, probs = seq(0, 1, 0.25), names = TRUE, type = 7, digits = 7, nsim = 1000, ... )
x |
The fitted |
probs |
numeric vector of probabilities with values in
|
names |
logical; if true, the result has a |
type |
An integer between 1 and 9 selecting one of the nine quantile
algorithms detailed in |
digits |
used only when |
nsim |
The number of samples to use to estimate quantiles. |
... |
Additional arguments to be passed to the posterior sampler
function. Since |
A matrix with columns giving quantiles for each posterior
.
The residuals
method for class ebnm
.
Calculates "residuals" .
## S3 method for class 'ebnm' residuals(object, ...)
## S3 method for class 'ebnm' residuals(object, ...)
object |
The fitted |
... |
Not used. Included for consistency as an S3 method. |
The simulate
method for class ebnm
.
Extracts the posterior sampler from an object of class ebnm
and returns a specified number of samples.
## S3 method for class 'ebnm' simulate(object, nsim = 1, seed = NULL, ...)
## S3 method for class 'ebnm' simulate(object, nsim = 1, seed = NULL, ...)
object |
The fitted |
nsim |
The number of posterior samples to return per observation. |
seed |
Either |
... |
Additional arguments to be passed to the posterior sampler
function. Since |
A matrix of posterior samples, with rows corresponding to distinct samples and columns corresponding to observations.
The summary
method for class ebnm
.
## S3 method for class 'ebnm' summary(object, ...)
## S3 method for class 'ebnm' summary(object, ...)
object |
The fitted |
... |
Not used. Included for consistency as an S3 method. |
A summary.ebnm
object.
The vcov
method for class ebnm
.
## S3 method for class 'ebnm' vcov(object, ...)
## S3 method for class 'ebnm' vcov(object, ...)
object |
The fitted |
... |
Not used. Included for consistency as an S3 method. |
Weighted on-base average (wOBA) for hitters from the 2022 Major League Baseball (MLB) season. Standard errors are calculated by modeling hitting outcomes as multinomially distributed and plugging in empirical proportions as the “true” outcome probabilities. To handle small sample sizes, standard errors are lower bounded by the errors that would be obtained using league-wide proportions rather than the plug-in estimates.
wOBA
is a data frame with 688 rows and 6 columns:
The hitter's FanGraphs identifier.
The hitter's name.
The hitter's MLB team (given as a three-letter code) or
NA
if the hitter played for multiple teams.
The hitter's number of plate appearances over the 2022 season.
The hitter's wOBA over the 2022 season.
The standard error for the hitter's wOBA.
<https://fangraphs.com>
data(wOBA) summary(wOBA)
data(wOBA) summary(wOBA)