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>. |
Authors: | Samuel Pawel [aut, cre] |
Maintainer: | Samuel Pawel <[email protected]> |
License: | GPL-3 |
Version: | 0.42.4 |
Built: | 2024-11-06 04:11:38 UTC |
Source: | https://github.com/samch93/pprep |
This function computes the Bayes factor contrasting
to
for the replication data assuming a normal likelihood.
The power parameter
indicates how much the normal
likelihood of the original data is raised to and then incorporated in the
prior for the effect size
(e.g., for
the original data are completely discounted). Under
, the power parameter can either be fixed to 0, or it can
have a beta distribution
. For the fixed power parameter
case, the specification of an unit-information prior
for the effect size
is required as the prior is otherwise not proper.
bfPPalpha(tr, sr, to, so, y = 2, uv = NA, ...)
bfPPalpha(tr, sr, to, so, y = 2, uv = NA, ...)
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 original 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 |
Bayes factor (BF > 1 indicates evidence for , whereas BF
< 1 indicates evidence for
)
Samuel Pawel
## 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)
## 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)
This function computes the Bayes factor contrasting
to
for the replication data assuming a normal likelihood. The
prior of the effect size
under
is the
posterior of the effect size obtained from combining a normal likelihood
of the original data raised to the power of
with a
flat initial prior with a. Under
, the power parameter can
either be fixed to some value between 0 and 1, or it can have a beta
distribution
.
bfPPtheta(tr, sr, to, so, x = 1, y = 1, alpha = NA, ...)
bfPPtheta(tr, sr, to, so, x = 1, y = 1, alpha = NA, ...)
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 original 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 |
Bayes factor (BF > 1 indicates evidence for , whereas BF
< 1 indicates evidence for
)
Samuel Pawel
## 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)
## 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)
This function computes the marginal likelihood of the
replication effect estimate tr
under the power prior model
with and
using numerical integration.
margLik(tr, to, sr, so, x = 1, y = 1, m = 0, v = Inf, ...)
margLik(tr, to, sr, so, x = 1, y = 1, m = 0, v = Inf, ...)
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 original 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 |
Marginal likelihood
Samuel Pawel
This convenience function computes and, if desired, visualizes
the joint posterior density of effect size and power
parameter
, as well as the marginal posterior
densities of effect size
and power parameter
individually. See the functions
postPP
,
postPPalpha
, and postPPtheta
for more details
on their computation.
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, ... )
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, ... )
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 original 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 |
Plots joint and marginal posterior densities, invisibly returns a list with the data for the plots.
Samuel Pawel
postPP
, postPPalpha
, postPPtheta
plotPP(tr = 0.2, sr = 0.05, to = 0.15, so = 0.05)
plotPP(tr = 0.2, sr = 0.05, to = 0.15, so = 0.05)
This function computes the posterior density of effect size
and power parameter
assuming a
normal likelihood for original and replication effect estimate. A power
prior for
is constructed by updating an initial
normal prior
with the likelihood of the original data raised to the power of
. A marginal beta prior
is assumed.
postPP(theta, alpha, tr, sr, to, so, x = 1, y = 1, m = 0, v = Inf, ...)
postPP(theta, alpha, tr, sr, to, so, x = 1, y = 1, m = 0, v = Inf, ...)
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 original 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 |
Posterior density
Samuel Pawel
postPPalpha
, postPPtheta
, plotPP
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"))
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"))
These functions compute the marginal posterior of the power
parameter . A power prior for
is
constructed by updating an initial normal prior
with the likelihood of
the original data raised to the power of
. A marginal
beta prior
is assumed.
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, ...)
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, ...)
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 original 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 |
postPPalpha
returns the marginal posterior density of the power
parameter.
postPPalphaHPD
returns the highest marginal posterior density
interval of the power parameter.
Samuel Pawel
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)
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)
These functions compute the marginal posterior of the effect
size . A power prior for
is
constructed by updating an initial normal prior
with likelihood of the
original data raised to the power of
. The power
parameter
can either be fixed to some value between 0
and 1 or it can have a beta prior distribution
.
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), ... )
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), ... )
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 original 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 |
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).
Samuel Pawel
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)
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)