Version: | 0.42.3 |
Date: | 2023-10-19 |
Author: | Samuel Pawel |
Maintainer: | Samuel Pawel <samuel.pawel@uzh.ch> |
Title: | Analysis of Replication Studies using Power Priors |
Description: | Provides functionality for Bayesian analysis of replication studies using power prior approaches (Pawel et al., 2023) <doi:10.1007/s11749-023-00888-5>. |
License: | GPL-3 |
Encoding: | UTF-8 |
Imports: | hypergeo |
Suggests: | roxygen2, tinytest, cubature |
NeedsCompilation: | no |
RoxygenNote: | 7.2.3 |
URL: | https://github.com/SamCH93/ppRep |
BugReports: | https://github.com/SamCH93/ppRep/issues |
Packaged: | 2023-10-19 14:05:19 UTC; sam |
Repository: | CRAN |
Date/Publication: | 2023-10-19 17:20:02 UTC |
Bayes factor for testing power parameter
Description
This function computes the Bayes factor contrasting
H_1\colon \alpha = 1
to H_0\colon \alpha <
1
for the replication data assuming a normal likelihood.
The power parameter \alpha
indicates how much the normal
likelihood of the original data is raised to and then incorporated in the
prior for the effect size \theta
(e.g., for \alpha =
0
the original data are completely discounted). Under
H_0
, the power parameter can either be fixed to 0, or it can
have a beta distribution \alpha | H_0 \sim \mbox{Beta}(1,
\code{y})
. For the fixed power parameter
case, the specification of an unit-information prior \theta \sim
\mathrm{N}(0, \code{uv})
for the effect size
\theta
is required as the prior is otherwise not proper.
Usage
bfPPalpha(tr, sr, to, so, y = 2, uv = NA, ...)
Arguments
tr |
Effect estimate of the replication study. |
sr |
Standard error of the replication effect estimate. |
to |
Effect estimate of the original study. |
so |
Standard error of the replication effect estimate. |
y |
Number of failures parameter for beta prior of power parameter under
|
uv |
Variance of the unit-information prior for the effect size that is
used for testing the simple hypothesis |
... |
Additional arguments passed to |
Value
Bayes factor (BF > 1 indicates evidence for H_0
, whereas BF
< 1 indicates evidence for H_1
)
Author(s)
Samuel Pawel
See Also
Examples
## use unit variance of 2
bfPPalpha(tr = 0.09, sr = 0.0518, to = 0.205, so = 0.0506, uv = 2)
## use beta prior alpha|H1 ~ Be(1, y = 2)
bfPPalpha(tr = 0.09, sr = 0.0518, to = 0.205, so = 0.0506, y = 2)
Bayes factor for testing effect size
Description
This function computes the Bayes factor contrasting
H_0\colon \theta = 0
to H_1\colon \theta \sim
f(\theta | \code{to}, \code{so}, \alpha)
for the replication data assuming a normal likelihood. The
prior of the effect size \theta
under H_1
is the
posterior of the effect size obtained from combining a normal likelihood
of the original data raised to the power of \alpha
with a
flat initial prior with a. Under H_1
, the power parameter can
either be fixed to some value between 0 and 1, or it can have a beta
distribution \alpha | H_1 \sim \mbox{Beta}(\code{x},
\code{y})
.
Usage
bfPPtheta(tr, sr, to, so, x = 1, y = 1, alpha = NA, ...)
Arguments
tr |
Effect estimate of the replication study. |
sr |
Standard error of the replication effect estimate. |
to |
Effect estimate of the original study. |
so |
Standard error of the replication effect estimate. |
x |
Number of successes parameter for beta prior of power parameter
under |
y |
Number of failures parameter for beta prior of power parameter under
|
alpha |
Power parameter under |
... |
Additional arguments passed to |
Value
Bayes factor (BF > 1 indicates evidence for H_0
, whereas BF
< 1 indicates evidence for H_1
)
Author(s)
Samuel Pawel
See Also
Examples
## uniform prior on power parameter
bfPPtheta(tr = 0.09, sr = 0.0518, to = 0.205, so = 0.0506)
## power parameter fixed to alpha = 1
bfPPtheta(tr = 0.090, sr = 0.0518, to = 0.205, so = 0.0506, alpha = 1)
Marginal likelihood of replication effect estimate
Description
This function computes the marginal likelihood of the
replication effect estimate tr
under the power prior model
f(\code{tr}|\code{to}, \code{so}, \code{sr}, \code{x}, \code{y}) =
\int_0^1 \int_{-\infty}^{\infty} \mathrm{N}(\code{tr}; \theta,
\code{sr}^2) \times \mathrm{N}(\theta; \mu, \phi)
\times \mbox{Beta}(\alpha; \code{x}, \code{y}) ~\mbox{d}\theta~
\mbox{d}\alpha
with \phi = 1/(1/\code{v} +
\alpha/\code{so}^2)
and \mu =
\phi\{(\alpha\times\code{to})/\code{so}^2 + \code{m}/\code{v}\}
using numerical integration.
Usage
margLik(tr, to, sr, so, x = 1, y = 1, m = 0, v = Inf, ...)
Arguments
tr |
Effect estimate of the replication study. |
to |
Effect estimate of the original study. |
sr |
Standard error of the replication effect estimate. |
so |
Standard error of the replication effect estimate. |
x |
Number of successes parameter of beta prior for |
y |
Number of failures parameter of beta prior for |
m |
Mean parameter of initial normal prior for |
v |
Variance parameter of initial normal prior for |
... |
Additional arguments passed to |
Value
Marginal likelihood
Author(s)
Samuel Pawel
Plot joint and marginal posterior distributions
Description
This convenience function computes and, if desired, visualizes
the joint posterior density of effect size \theta
and power
parameter \alpha
, as well as the marginal posterior
densities of effect size \theta
and power parameter
\alpha
individually. See the functions postPP
,
postPPalpha
, and postPPtheta
for more details
on their computation.
Usage
plotPP(
tr,
sr,
to,
so,
x = 1,
y = 1,
m = 0,
v = Inf,
thetaRange = c(tr - 3 * sr, tr + 3 * sr),
alphaRange = c(0, 1),
nGrid = 100,
plot = TRUE,
CI = FALSE,
...
)
Arguments
tr |
Effect estimate of the replication study. |
sr |
Standard error of the replication effect estimate. |
to |
Effect estimate of the original study. |
so |
Standard error of the replication effect estimate. |
x |
Number of successes parameter of beta prior for |
y |
Number of failures parameter of beta prior for |
m |
Mean parameter of initial normal prior for |
v |
Variance parameter of initial normal prior for |
thetaRange |
Range of effect sizes. Defaults to three standard errors around the replication effect estimate. |
alphaRange |
Range of power parameters. Defaults to the range between zero and one. |
nGrid |
Number of grid points. Defaults to |
plot |
Logical indicating whether data should be plotted. If
|
CI |
Logical indicating whether 95% highest posterior credible
intervals should be plotted. Defaults to |
... |
Additional arguments passed to |
Value
Plots joint and marginal posterior densities, invisibly returns a list with the data for the plots.
Author(s)
Samuel Pawel
See Also
postPP
, postPPalpha
, postPPtheta
Examples
plotPP(tr = 0.2, sr = 0.05, to = 0.15, so = 0.05)
Mean of normalized power prior
Description
This function computes the mean of a normalized power prior conditional on a fixed power parameter and an initial normal prior for the effect size.
Usage
postNormMean(dat, vardata, priormean, priorvar, alpha = 1)
Arguments
dat |
Data. |
vardata |
Variance of the data. |
priormean |
Mean parameter of initial normal prior. Defaults to
|
priorvar |
Variance parameter of initial normal prior. Defaults to
|
alpha |
Power parameter. Indicates to which power the likelihood of the
data is raised. Can be set to a number in [0, 1]. Defaults to |
Value
Prior mean
Author(s)
Samuel Pawel
Variance of normalized power prior
Description
This function computes the variance of a normalized power prior conditional on a fixed power parameter and an initial normal prior for the effect size.
Usage
postNormVar(vardata, priorvar, alpha = 1)
Arguments
vardata |
Variance of the data. |
priorvar |
Variance parameter of initial normal prior. Defaults to
|
alpha |
Power parameter. Indicates to which power the likelihood of the
data is raised. Can be set to a number in [0, 1]. Defaults to |
Value
Prior variance
Author(s)
Samuel Pawel
Posterior density of effect size and power parameter
Description
This function computes the posterior density of effect size
\theta
and power parameter \alpha
assuming a
normal likelihood for original and replication effect estimate. A power
prior for \theta
is constructed by updating an initial
normal prior \theta \sim \mathrm{N}(\code{m}, \code{v})
with the likelihood of the original data raised to the power of
\alpha
. A marginal beta prior \alpha \sim
\mbox{Beta}(\code{x},\code{y})
is assumed.
Usage
postPP(theta, alpha, tr, sr, to, so, x = 1, y = 1, m = 0, v = Inf, ...)
Arguments
theta |
Effect size. Has to be of length one or the same length as
|
alpha |
Power parameter. Has to be of length one or the same length as
|
tr |
Effect estimate of the replication study. |
sr |
Standard error of the replication effect estimate. |
to |
Effect estimate of the original study. |
so |
Standard error of the replication effect estimate. |
x |
Number of successes parameter of beta prior for |
y |
Number of failures parameter of beta prior for |
m |
Mean parameter of initial normal prior for |
v |
Variance parameter of initial normal prior for |
... |
Additional arguments passed to |
Value
Posterior density
Author(s)
Samuel Pawel
See Also
postPPalpha
, postPPtheta
, plotPP
Examples
alpha <- seq(0, 1, length.out = 200)
theta <- seq(0, 0.3, length.out = 200)
parGrid <- expand.grid(alpha = alpha, theta = theta)
postdens <- postPP(theta = parGrid$theta, alpha = parGrid$alpha, tr = 0.1,
sr = 0.05, to = 0.2, so = 0.05)
postdensMat <- matrix(data = postdens, ncol = 200, byrow = TRUE)
filled.contour(x = theta, y = alpha, z = postdensMat,
xlab = bquote("Effect size" ~ theta),
ylab = bquote("Power parameter" ~ alpha), nlevels = 15,
color.palette = function(n) hcl.colors(n = n, palette = "viridis"))
Marginal posterior distribution of power parameter
Description
These functions compute the marginal posterior of the power
parameter \alpha
. A power prior for \theta
is
constructed by updating an initial normal prior \theta \sim
\mathrm{N}(\code{m}, \code{v})
with the likelihood of
the original data raised to the power of \alpha
. A marginal
beta prior \alpha \sim \mbox{Beta}(\code{x},\code{y})
is assumed.
Usage
postPPalpha(alpha, tr, sr, to, so, x = 1, y = 1, m = 0, v = Inf, ...)
postPPalphaHPD(level = 0.95, tr, sr, to, so, x = 1, y = 1, m = 0, v = Inf, ...)
Arguments
alpha |
Power parameter. Can be a vector. |
tr |
Effect estimate of the replication study. |
sr |
Standard error of the replication effect estimate. |
to |
Effect estimate of the original study. |
so |
Standard error of the replication effect estimate. |
x |
Number of successes parameter of beta prior |
y |
Number of failures parameter of beta prior |
m |
Mean parameter of initial normal prior for |
v |
Variance parameter of initial normal prior for |
... |
Additional arguments passed to |
level |
Credibility level of the highest posterior density interval.
Defaults to |
Value
postPPalpha
returns the marginal posterior density of the power
parameter.
postPPalphaHPD
returns the highest marginal posterior density
interval of the power parameter.
Author(s)
Samuel Pawel
See Also
Examples
alpha <- seq(0, 1, 0.001)
margpostdens <- postPPalpha(alpha = alpha, tr = 0.1, to = 0.2, sr = 0.05, so = 0.05)
plot(alpha, margpostdens, type = "l", xlab = bquote("Power parameter" ~ alpha),
ylab = "Marginal posterior density", las = 1)
Marginal posterior distribution of effect size
Description
These functions compute the marginal posterior of the effect
size \theta
. A power prior for \theta
is
constructed by updating an initial normal prior \theta \sim
\mathrm{N}(\code{m}, \code{v})
with likelihood of the
original data raised to the power of \alpha
. The power
parameter \alpha
can either be fixed to some value between 0
and 1 or it can have a beta prior distribution \alpha \sim
\mbox{Beta}(\code{x}, \code{y})
.
Usage
postPPtheta(
theta,
tr,
sr,
to,
so,
x = 1,
y = 1,
alpha = NA,
m = 0,
v = Inf,
hypergeo = FALSE,
...
)
postPPthetaHPD(
level,
tr,
sr,
to,
so,
x = 1,
y = 1,
alpha = NA,
m = 0,
v = Inf,
thetaRange = tr + c(-1, 1) * stats::qnorm(p = (1 + level)/2) * sr * 3,
quantileRange = c((1 - level) * 0.2, (1 - level) * 0.8),
...
)
Arguments
theta |
Effect size. Can be a vector. |
tr |
Effect estimate of the replication study. |
sr |
Standard error of the replication effect estimate. |
to |
Effect estimate of the original study. |
so |
Standard error of the replication effect estimate. |
x |
Number of successes parameter for beta prior of power parameter
|
y |
Number of failures parameter for beta prior of power parameter
|
alpha |
Power parameter. Can be set to a number between 0 and 1.
Defaults to |
m |
Mean parameter of initial normal prior for |
v |
Variance parameter of initial normal prior for |
hypergeo |
Logical indicating whether for uniform priors, the marginal
posterior should be computed with the hypergeometric function. Defaults
to |
... |
Additional arguments passed to |
level |
Credibility level of the highest posterior density interval.
Defaults to |
thetaRange |
The numerical search range for the effect size. Defaults to
the |
quantileRange |
The numerical search range for the lower posterior
quantile of the HPD interval. Defaults to the range between |
Value
postPPtheta
returns the marginal posterior density of the
effect size.
postPPthetaHPD
returns the highest marginal posterior density
interval of the effect size (this may take a while).
Author(s)
Samuel Pawel
See Also
Examples
theta <- seq(0, 0.6, 0.001)
margpostdens <- postPPtheta(theta = theta, tr = 0.1, to = 0.2, sr = 0.05, so = 0.05)
plot(theta, margpostdens, type = "l", xlab = bquote("Effect size" ~ theta),
ylab = "Marginal posterior density", las = 1)