Encoding: | UTF-8 |
Type: | Package |
Version: | 1.1-2 |
Date: | 2023-10-12 |
Title: | Solve the Empirical Bayes Normal Means Problem |
URL: | https://github.com/stephenslab/ebnm |
BugReports: | https://github.com/stephenslab/ebnm/issues |
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 (2021) <doi:10.48550/arXiv.2110.00152>. |
License: | GPL (≥ 3) |
NeedsCompilation: | no |
Depends: | R (≥ 3.3.0) |
Imports: | stats, ashr, mixsqp, truncnorm, trust, horseshoe, deconvolveR, magrittr, rlang, dplyr, ggplot2 |
Suggests: | testthat, numDeriv, REBayes, knitr, rmarkdown, cowplot |
RoxygenNote: | 7.2.3 |
VignetteBuilder: | knitr |
LazyData: | true |
Packaged: | 2023-10-12 17:28:03 UTC; pcarbo |
Author: | Jason Willwerscheid [aut], Matthew Stephens [aut], Peter Carbonetto [aut, cre], Andrew Goldstein [ctb], Yusha Liu [ctb] |
Maintainer: | Peter Carbonetto <peter.carbonetto@gmail.com> |
Repository: | CRAN |
Date/Publication: | 2023-10-12 21:10:02 UTC |
Extract posterior means from a fitted EBNM model
Description
The coef
method for class ebnm
.
Usage
## S3 method for class 'ebnm'
coef(object, ...)
Arguments
object |
The fitted |
... |
Not used. Included for consistency as an S3 method. |
Obtain confidence intervals using a fitted EBNM model
Description
The confint
method for class ebnm
.
Estimates the highest posterior density (HPD) intervals by sampling from
the posterior. By default, ebnm
does not return a posterior
sampler; one can be added to the ebnm
object using function
ebnm_add_sampler
.
Usage
## S3 method for class 'ebnm'
confint(object, parm, level = 0.95, nsim = 1000, ...)
Arguments
object |
The fitted |
parm |
A vector of numeric indices specifying which means |
level |
The confidence level required. |
nsim |
The number of samples to use to estimate confidence intervals. |
... |
Additional arguments to be passed to the posterior sampler
function. Since |
Value
A matrix with columns giving lower and upper confidence limits for
each mean \theta_i
. These will be labelled as "CI.lower" and
"CI.upper".
Solve the EBNM problem
Description
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.
Usage
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()
Arguments
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. Since all non-parametric families rely upon external packages, this
parameter is only available for parametric families (point-normal,
point-Laplace, point-exponential, and normal). Options include |
control |
A list of control parameters to be passed to the optimization
function. |
... |
Additional parameters. When a |
Details
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
x_j | \theta_j, s_j \sim N(\theta_j, s_j^2)
\theta_j \sim g \in G,
where g
, which is referred to as the
"prior distribution" for \theta
, is to be estimated from among
some specified family of prior distributions G
. Several options
for G
are implemented, some parametric and others non-parametric;
see below for examples.
Solving the EBNM problem involves
two steps. First, g \in G
is estimated via maximum marginal likelihood:
\hat{g} := \arg\max_{g \in G} L(g),
where
L(g) := \prod_j \int p(x_j | \theta_j, s_j) g(d\theta_j).
Second, posterior distributions
p(\theta_j | x_j, s_j, \hat{g})
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
\mu
and the other is a normal distribution centered at\mu
.point_laplace
The family of mixtures where one component is a point mass at
\mu
and the other is a double-exponential distribution centered at\mu
.point_exponential
The family of mixtures where one component is a point mass at
\mu
and the other is a (nonnegative) exponential distribution with mode\mu
.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 whereasnpmle
produces spiky estimates forg
,deconvolver
estimates are much more regular. SeedeconvolveR-package
for details and references.flat
The "non-informative" improper uniform prior, which yields posteriors
\theta_j | x_j, s_j \sim N(x_j, s_j^2).
point_mass
The family of point masses
\delta_\mu
. Posteriors are point masses at\mu
.ash
Calls into function
ash
in packageashr
. Can be used to make direct comparisons ofebnm
andashr
implementations of prior families such as scale mixtures of normals and the NPMLE.
Value
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 errorss
.posterior
A data frame of summary results (posterior means, standard deviations, second moments, and local false sign rates).
fitted_g
The fitted prior
\hat{g}
(an object of classnormalmix
,laplacemix
,gammamix
,unimix
,tnormalmix
, orhorseshoe
).log_likelihood
The optimal log likelihood attained,
L(\hat{g})
.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. Sinceebnm_horseshoe
returns an MCMC sampler, it additionally takes parameterburn
, 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.
Functions
-
ebnm_output_default()
: Lists the default return values. -
ebnm_output_all()
: Lists all valid return values.
References
Jason Willwerscheid and Matthew Stephens (2021).
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.
See Also
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.
Examples
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))
Add sampler to an ebnm_object
Description
Adds a posterior sampler to a fitted ebnm
object.
Usage
ebnm_add_sampler(ebnm_res)
Arguments
ebnm_res |
The fitted |
Value
The ebnm
object with an additional field
posterior_sampler
.
Solve the EBNM problem using an ash family of distributions
Description
A wrapper to function ash
in package ashr
.
Identical to function ebnm
with argument
prior_family = "ash"
.
Usage
ebnm_ash(
x,
s = 1,
mode = 0,
scale = "estimate",
g_init = NULL,
fix_g = FALSE,
output = ebnm_output_default(),
control = NULL,
...
)
Arguments
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 |
Value
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 errorss
.posterior
A data frame of summary results (posterior means, standard deviations, second moments, and local false sign rates).
fitted_g
The fitted prior
\hat{g}
.log_likelihood
The optimal log likelihood attained,
L(\hat{g})
.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 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
.
Solve the EBNM problem using the "deconvolveR" family of distributions
Description
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 g
,
ebnm_deconvolver
estimates are much more regular. See
deconvolveR-package
for details and
references. Identical to function ebnm
with argument
prior_family = "deconvolver"
.
Usage
ebnm_deconvolver(
x,
s = 1,
scale = "estimate",
g_init = NULL,
fix_g = FALSE,
output = ebnm_output_default(),
control = NULL,
...
)
Arguments
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
|
Value
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 errorss
.posterior
A data frame of summary results (posterior means, standard deviations, second moments, and local false sign rates).
fitted_g
The fitted prior
\hat{g}
.log_likelihood
The optimal log likelihood attained,
L(\hat{g})
.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 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
.
Solve the EBNM problem using a flat prior
Description
Solves the empirical Bayes normal means (EBNM) problem using a "non-informative" improper uniform prior, which yields posteriors
\theta_j | x_j, s_j \sim N(x_j, s_j^2).
Identical to function
ebnm
with argument prior_family = "flat"
. For details
about the model, see ebnm
.
Usage
ebnm_flat(
x,
s = 1,
g_init = NULL,
fix_g = FALSE,
output = ebnm_output_default()
)
Arguments
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 |
Value
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 errorss
.posterior
A data frame of summary results (posterior means, standard deviations, second moments, and local false sign rates).
fitted_g
The fitted prior
\hat{g}
.log_likelihood
The optimal log likelihood attained,
L(\hat{g})
.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 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
.
Solve the EBNM problem using generalized binary priors
Description
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.
Usage
ebnm_generalized_binary(
x,
s = 1,
mode = "estimate",
scale = 0.1,
g_init = NULL,
fix_g = FALSE,
output = ebnm_output_default(),
control = NULL,
...
)
Arguments
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
|
Value
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 errorss
.posterior
A data frame of summary results (posterior means, standard deviations, second moments, and local false sign rates).
fitted_g
The fitted prior
\hat{g}
.log_likelihood
The optimal log likelihood attained,
L(\hat{g})
.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.
References
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 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
.
Solve the EBNM problem for grouped data
Description
Solves the empirical Bayes normal means (EBNM) problem for observations belonging to distinct groups.
Usage
ebnm_group(
x,
s = 1,
group,
prior_family = "point_normal",
mode = 0,
scale = "estimate",
g_init = NULL,
fix_g = FALSE,
output = ebnm_output_default(),
...
)
Arguments
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 |
Details
The EBNM model for grouped data, with observations x_j
belonging to
groups k = 1, ..., K
, is
x_j | \theta_j, s_j \sim N(\theta_j, s_j^2)
\theta_j \sim g_{k(j)} \in G_{k(j)}.
Solving the EBNM problem for grouped data is equivalent to solving a
separate EBNM problem for each group k = 1, ..., K
, with the optimal
log likelihood equal to the sum of the optimal log likelihoods for each
separate problem.
Value
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 errorss
.posterior
A data frame of summary results (posterior means, standard deviations, second moments, and local false sign rates).
fitted_g
The fitted prior
\hat{g}
(an object of classnormalmix
,laplacemix
,gammamix
,unimix
,tnormalmix
, orhorseshoe
).log_likelihood
The optimal log likelihood attained,
L(\hat{g})
.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. Sinceebnm_horseshoe
returns an MCMC sampler, it additionally takes parameterburn
, 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.
See Also
Examples
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")
)
Solve the EBNM problem using horseshoe priors
Description
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
.
Usage
ebnm_horseshoe(
x,
s = 1,
scale = "estimate",
g_init = NULL,
fix_g = FALSE,
output = ebnm_output_default(),
control = NULL
)
Arguments
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
|
Value
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 errorss
.posterior
A data frame of summary results (posterior means, standard deviations, second moments, and local false sign rates).
fitted_g
The fitted prior
\hat{g}
.log_likelihood
The optimal log likelihood attained,
L(\hat{g})
.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, andburn
, 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 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
.
Solve the EBNM problem using normal priors
Description
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
.
Usage
ebnm_normal(
x,
s = 1,
mode = 0,
scale = "estimate",
g_init = NULL,
fix_g = FALSE,
output = ebnm_output_default(),
optmethod = NULL,
control = NULL
)
Arguments
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 |
Value
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 errorss
.posterior
A data frame of summary results (posterior means, standard deviations, second moments, and local false sign rates).
fitted_g
The fitted prior
\hat{g}
.log_likelihood
The optimal log likelihood attained,
L(\hat{g})
.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 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
.
Solve the EBNM problem using scale mixtures of normals
Description
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
.
Usage
ebnm_normal_scale_mixture(
x,
s = 1,
mode = 0,
scale = "estimate",
g_init = NULL,
fix_g = FALSE,
output = ebnm_output_default(),
control = NULL,
...
)
Arguments
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 |
control |
A list of control parameters to be passed to optimization
function |
... |
When parameter |
Value
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 errorss
.posterior
A data frame of summary results (posterior means, standard deviations, second moments, and local false sign rates).
fitted_g
The fitted prior
\hat{g}
.log_likelihood
The optimal log likelihood attained,
L(\hat{g})
.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 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
.
Solve the EBNM problem using the family of all distributions
Description
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
.
Usage
ebnm_npmle(
x,
s = 1,
scale = "estimate",
g_init = NULL,
fix_g = FALSE,
output = ebnm_output_default(),
optmethod = NULL,
control = NULL
)
Arguments
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 |
Not used by |
control |
A list of control parameters to be passed to optimization
function |
Value
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 errorss
.posterior
A data frame of summary results (posterior means, standard deviations, second moments, and local false sign rates).
fitted_g
The fitted prior
\hat{g}
.log_likelihood
The optimal log likelihood attained,
L(\hat{g})
.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 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
.
Solve the EBNM problem using point-exponential priors
Description
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 \mu
and the other is a (nonnegative) exponential
distribution with mode \mu
). Identical to function ebnm
with argument prior_family = "point_exponential"
. For details about
the model, see ebnm
.
Usage
ebnm_point_exponential(
x,
s = 1,
mode = 0,
scale = "estimate",
g_init = NULL,
fix_g = FALSE,
output = ebnm_output_default(),
optmethod = NULL,
control = NULL
)
Arguments
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 |
Value
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 errorss
.posterior
A data frame of summary results (posterior means, standard deviations, second moments, and local false sign rates).
fitted_g
The fitted prior
\hat{g}
.log_likelihood
The optimal log likelihood attained,
L(\hat{g})
.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 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
.
Solve the EBNM problem using point-Laplace priors
Description
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 \mu
and the other is a double-exponential distribution
centered at \mu
). Identical to function ebnm
with argument
prior_family = "point_laplace"
. For details about the model, see
ebnm
.
Usage
ebnm_point_laplace(
x,
s = 1,
mode = 0,
scale = "estimate",
g_init = NULL,
fix_g = FALSE,
output = ebnm_output_default(),
optmethod = NULL,
control = NULL
)
Arguments
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 |
Value
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 errorss
.posterior
A data frame of summary results (posterior means, standard deviations, second moments, and local false sign rates).
fitted_g
The fitted prior
\hat{g}
.log_likelihood
The optimal log likelihood attained,
L(\hat{g})
.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 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
.
Solve the EBNM problem using a point mass prior
Description
Solves the empirical Bayes normal means (EBNM) problem using the family of
point masses \delta_\mu
. Posteriors are simply point masses at \mu
.
Identical to function ebnm
with argument
prior_family = "point_mass"
. For details about the model, see
ebnm
.
Usage
ebnm_point_mass(
x,
s = 1,
mode = 0,
g_init = NULL,
fix_g = FALSE,
output = ebnm_output_default()
)
Arguments
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 |
Value
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 errorss
.posterior
A data frame of summary results (posterior means, standard deviations, second moments, and local false sign rates).
fitted_g
The fitted prior
\hat{g}
.log_likelihood
The optimal log likelihood attained,
L(\hat{g})
.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 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
.
Solve the EBNM problem using point-normal priors
Description
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 \mu
and the other is a normal distribution centered at
\mu
). Identical to function ebnm
with argument
prior_family = "point_normal"
. For details about the model, see
ebnm
.
Usage
ebnm_point_normal(
x,
s = 1,
mode = 0,
scale = "estimate",
g_init = NULL,
fix_g = FALSE,
output = ebnm_output_default(),
optmethod = NULL,
control = NULL
)
Arguments
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 |
Value
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 errorss
.posterior
A data frame of summary results (posterior means, standard deviations, second moments, and local false sign rates).
fitted_g
The fitted prior
\hat{g}
.log_likelihood
The optimal log likelihood attained,
L(\hat{g})
.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 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
.
Set scale parameter for scale mixtures of normals
Description
The default method for setting the scale
parameter for function
ebnm_normal_scale_mixture
.
Usage
ebnm_scale_normalmix(
x,
s,
mode = 0,
min_K = 3,
max_K = 300,
KLdiv_target = 1/length(x)
)
Arguments
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 |
References
Jason Willwerscheid (2021). Empirical Bayes Matrix Factorization: Methods and Applications. University of Chicago, PhD dissertation.
Set scale parameter for NPMLE and deconvolveR prior family
Description
The default method for setting the scale
parameter for functions
ebnm_npmle
and ebnm_deconvolver
.
Usage
ebnm_scale_npmle(
x,
s,
min_K = 3,
max_K = 300,
KLdiv_target = 1/length(x),
pointmass = TRUE
)
Arguments
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 |
References
Jason Willwerscheid (2021). Empirical Bayes Matrix Factorization: Methods and Applications. University of Chicago, PhD dissertation.
Set scale parameter for nonparametric unimodal prior families
Description
The default method for setting the scale
parameter for functions
ebnm_unimodal
, ebnm_unimodal_symmetric
,
ebnm_unimodal_nonnegative
, and
ebnm_unimodal_nonpositive
.
Usage
ebnm_scale_unimix(
x,
s,
mode = 0,
min_K = 3,
max_K = 300,
KLdiv_target = 1/length(x)
)
Arguments
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 |
References
Jason Willwerscheid (2021). Empirical Bayes Matrix Factorization: Methods and Applications. University of Chicago, PhD dissertation.
Solve the EBNM problem using unimodal distributions
Description
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
.
Usage
ebnm_unimodal(
x,
s = 1,
mode = 0,
scale = "estimate",
g_init = NULL,
fix_g = FALSE,
output = ebnm_output_default(),
control = NULL,
...
)
Arguments
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 |
control |
A list of control parameters to be passed to optimization
function |
... |
Additional parameters to be passed to function
|
Value
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 errorss
.posterior
A data frame of summary results (posterior means, standard deviations, second moments, and local false sign rates).
fitted_g
The fitted prior
\hat{g}
.log_likelihood
The optimal log likelihood attained,
L(\hat{g})
.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 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
.
Solve the EBNM problem using unimodal nonnegative distributions
Description
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
.
Usage
ebnm_unimodal_nonnegative(
x,
s = 1,
mode = 0,
scale = "estimate",
g_init = NULL,
fix_g = FALSE,
output = ebnm_output_default(),
control = NULL,
...
)
Arguments
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 |
control |
A list of control parameters to be passed to optimization
function |
... |
Additional parameters to be passed to function
|
Value
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 errorss
.posterior
A data frame of summary results (posterior means, standard deviations, second moments, and local false sign rates).
fitted_g
The fitted prior
\hat{g}
.log_likelihood
The optimal log likelihood attained,
L(\hat{g})
.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 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
.
Solve the EBNM problem using unimodal nonpositive distributions
Description
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
.
Usage
ebnm_unimodal_nonpositive(
x,
s = 1,
mode = 0,
scale = "estimate",
g_init = NULL,
fix_g = FALSE,
output = ebnm_output_default(),
control = NULL,
...
)
Arguments
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 |
control |
A list of control parameters to be passed to optimization
function |
... |
Additional parameters to be passed to function
|
Value
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 errorss
.posterior
A data frame of summary results (posterior means, standard deviations, second moments, and local false sign rates).
fitted_g
The fitted prior
\hat{g}
.log_likelihood
The optimal log likelihood attained,
L(\hat{g})
.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 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
.
Solve the EBNM problem using symmetric unimodal distributions
Description
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
.
Usage
ebnm_unimodal_symmetric(
x,
s = 1,
mode = 0,
scale = "estimate",
g_init = NULL,
fix_g = FALSE,
output = ebnm_output_default(),
control = NULL,
...
)
Arguments
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 |
control |
A list of control parameters to be passed to optimization
function |
... |
Additional parameters to be passed to function
|
Value
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 errorss
.posterior
A data frame of summary results (posterior means, standard deviations, second moments, and local false sign rates).
fitted_g
The fitted prior
\hat{g}
.log_likelihood
The optimal log likelihood attained,
L(\hat{g})
.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 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
.
Extract posterior estimates from a fitted EBNM model
Description
The fitted
method for class ebnm
.
Returns a data frame that includes posterior means, standard deviations,
and local false sign rates (when available).
Usage
## S3 method for class 'ebnm'
fitted(object, ...)
Arguments
object |
The fitted |
... |
Not used. Included for consistency as an S3 method. |
Constructor for gammamix class
Description
Creates a finite mixture of gamma distributions.
Usage
gammamix(pi, shape, scale, shift = rep(0, length(pi)))
Arguments
pi |
A vector of mixture proportions. |
shape |
A vector of shape parameters. |
scale |
A vector of scale parameters. |
shift |
A vector of shift parameters. |
Value
An object of class gammamix
(a list with elements
pi
, shape
, scale
, and shift
, described above).
Constructor for horseshoe class
Description
Creates a horseshoe prior (see Carvalho, Polson, and Scott (2010)). The
horseshoe is usually parametrized as
\theta_i \sim N(0, s^2 \tau^2 \lambda_i^2)
,
\lambda_i \sim \mathrm{Cauchy}^+(0, 1)
,
with s^2
the variance of the error distribution. We use a single
parameter scale
, which corresponds to s\tau
and thus does
not depend on the error distribution.
Usage
horseshoe(scale)
Arguments
scale |
The scale parameter (must be a scalar). |
Value
An object of class horseshoe
(a list with a single element
scale
, described above).
Constructor for laplacemix class
Description
Creates a finite mixture of Laplace distributions.
Usage
laplacemix(pi, mean, scale)
Arguments
pi |
A vector of mixture proportions. |
mean |
A vector of means. |
scale |
A vector of scale parameters. |
Value
An object of class laplacemix
(a list with elements
pi
, mean
, and scale
, described above).
Extract the log likelihood from a fitted EBNM model
Description
The logLik
method for class ebnm
.
Usage
## S3 method for class 'ebnm'
logLik(object, ...)
Arguments
object |
The fitted |
... |
Not used. Included for consistency as an S3 method. |
Value
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.
Get the number of observations used to fit an EBNM model
Description
The nobs
method for class ebnm
.
Usage
## S3 method for class 'ebnm'
nobs(object, ...)
Arguments
object |
The fitted |
... |
Not used. Included for consistency as an S3 method. |
Value
The number of observations used to fit the ebnm
object.
Plot an ebnm object
Description
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.
Usage
## S3 method for class 'ebnm'
plot(
x,
...,
incl_pm = TRUE,
incl_cdf = FALSE,
subset = NULL,
remove_abline = FALSE
)
Arguments
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 |
Examples
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")
Use the estimated prior from a fitted EBNM model to solve the EBNM problem for new data
Description
The predict
method for class ebnm
.
Usage
## S3 method for class 'ebnm'
predict(object, newdata, s = 1, ...)
Arguments
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. |
Value
A data frame that includes posterior means, posterior standard
deviations, and local false sign rates for the observations in newdata
.
Print an ebnm object
Description
The print
method for class ebnm
.
Usage
## S3 method for class 'ebnm'
print(x, digits = 2, ...)
Arguments
x |
The fitted |
digits |
Number of significant digits to use. |
... |
Not used. Included for consistency as an S3 method. |
Print a summary.ebnm object
Description
The print
method for class summary.ebnm
.
Usage
## S3 method for class 'summary.ebnm'
print(x, digits = 2, ...)
Arguments
x |
The |
digits |
Number of significant digits to use. |
... |
Not used. Included for consistency as an S3 method. |
Obtain posterior quantiles using a fitted EBNM model
Description
The quantile
method for class ebnm
.
Quantiles for posterior distributions \theta_i \mid x_i, s_i, g
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
.
Usage
## S3 method for class 'ebnm'
quantile(
x,
probs = seq(0, 1, 0.25),
names = TRUE,
type = 7,
digits = 7,
nsim = 1000,
...
)
Arguments
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 |
Value
A matrix with columns giving quantiles for each posterior
\theta_i \mid x_i, s_i, g
.
Calculate residuals for a fitted EBNM model
Description
The residuals
method for class ebnm
.
Calculates "residuals" x_i - \hat{\theta_i}
.
Usage
## S3 method for class 'ebnm'
residuals(object, ...)
Arguments
object |
The fitted |
... |
Not used. Included for consistency as an S3 method. |
Sample from the posterior of a fitted EBNM model
Description
The simulate
method for class ebnm
.
Extracts the posterior sampler from an object of class ebnm
and returns a specified number of samples.
Usage
## S3 method for class 'ebnm'
simulate(object, nsim = 1, seed = NULL, ...)
Arguments
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 |
Value
A matrix of posterior samples, with rows corresponding to distinct samples and columns corresponding to observations.
Summarize an ebnm object
Description
The summary
method for class ebnm
.
Usage
## S3 method for class 'ebnm'
summary(object, ...)
Arguments
object |
The fitted |
... |
Not used. Included for consistency as an S3 method. |
Value
A summary.ebnm
object.
Extract posterior variances from a fitted EBNM model
Description
The vcov
method for class ebnm
.
Usage
## S3 method for class 'ebnm'
vcov(object, ...)
Arguments
object |
The fitted |
... |
Not used. Included for consistency as an S3 method. |
2022 MLB wOBA Data
Description
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.
Format
wOBA
is a data frame with 688 rows and 6 columns:
- FanGraphsID
The hitter's FanGraphs identifier.
- Name
The hitter's name.
- Team
The hitter's MLB team (given as a three-letter code) or
NA
if the hitter played for multiple teams.- PA
The hitter's number of plate appearances over the 2022 season.
- x
The hitter's wOBA over the 2022 season.
- s
The standard error for the hitter's wOBA.
Source
<https://fangraphs.com>
Examples
data(wOBA)
summary(wOBA)