Package 'ppRep'

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

Help Index


Bayes factor for testing power parameter

Description

This function computes the Bayes factor contrasting H1 ⁣:α=1H_1\colon \alpha = 1 to H0 ⁣:α<1H_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 α=0\alpha = 0 the original data are completely discounted). Under H0H_0, the power parameter can either be fixed to 0, or it can have a beta distribution αH0Beta(1,y)\alpha | H_0 \sim \mbox{Beta}(1, \code{y}). For the fixed power parameter case, the specification of an unit-information prior θN(0,uv)\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 original effect estimate.

y

Number of failures parameter for beta prior of power parameter under H0H_0. Has to be larger than 1 so that density is monotonically decreasing. Defaults to 2 (a linearly decreasing prior with zero density at 1). Is only taken into account when uv = NA.

uv

Variance of the unit-information prior for the effect size that is used for testing the simple hypothesis H0 ⁣:α=0H_0 \colon \alpha = 0. Defaults to NA.

...

Additional arguments passed to stats::integrate.

Value

Bayes factor (BF > 1 indicates evidence for H0H_0, whereas BF < 1 indicates evidence for H1H_1)

Author(s)

Samuel Pawel

See Also

bfPPtheta

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 H0 ⁣:θ=0H_0\colon \theta = 0 to H1 ⁣:θf(θto,so,α)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 H1H_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 H1H_1, the power parameter can either be fixed to some value between 0 and 1, or it can have a beta distribution αH1Beta(x,y)\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 original effect estimate.

x

Number of successes parameter for beta prior of power parameter under H1H_1. Defaults to 1. Is only taken into account when alpha = NA.

y

Number of failures parameter for beta prior of power parameter under H1H_1. Defaults to 1. Is only taken into account when alpha = NA.

alpha

Power parameter under H1H_1. Can be set to a number between 0 and 1. Defaults to NA.

...

Additional arguments passed to stats::integrate.

Value

Bayes factor (BF > 1 indicates evidence for H0H_0, whereas BF < 1 indicates evidence for H1H_1)

Author(s)

Samuel Pawel

See Also

bfPPalpha

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(trto,so,sr,x,y)=01N(tr;θ,sr2)×N(θ;μ,ϕ)×Beta(α;x,y) dθ dα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 ϕ=1/(1/v+α/so2)\phi = 1/(1/\code{v} + \alpha/\code{so}^2) and μ=ϕ{(α×to)/so2+m/v}\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 original effect estimate.

x

Number of successes parameter of beta prior for α\alpha. Defaults to 1.

y

Number of failures parameter of beta prior for α\alpha. Defaults to 1.

m

Mean parameter of initial normal prior for θ\theta. Defaults to 0.

v

Variance parameter of initial normal prior for θ\theta. Defaults to Inf (uniform prior).

...

Additional arguments passed to stats::integrate.

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 original effect estimate.

x

Number of successes parameter of beta prior for α\alpha. Defaults to 1.

y

Number of failures parameter of beta prior for α\alpha. Defaults to 1.

m

Mean parameter of initial normal prior for θ\theta. Defaults to 0.

v

Variance parameter of initial normal prior for θ\theta. Defaults to Inf (uniform prior).

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 100.

plot

Logical indicating whether data should be plotted. If FALSE only the data used for plotting are returned.

CI

Logical indicating whether 95% highest posterior credible intervals should be plotted. Defaults to FALSE.

...

Additional arguments passed to stats::integrate for computation of posterior densities and highest posterior density credible intervals.

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)

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 θN(m,v)\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 αBeta(x,y)\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.

alpha

Power parameter. Has to be of length one or the same length as theta.

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 α\alpha. Defaults to 1.

y

Number of failures parameter of beta prior for α\alpha. Defaults to 1.

m

Mean parameter of initial normal prior for θ\theta. Defaults to 0.

v

Variance parameter of initial normal prior for θ\theta. Defaults to Inf (uniform prior).

...

Additional arguments passed to stats::integrate.

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 θN(m,v)\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 αBeta(x,y)\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 original effect estimate.

x

Number of successes parameter of beta prior α\alpha. Defaults to 1.

y

Number of failures parameter of beta prior α\alpha. Defaults to 1.

m

Mean parameter of initial normal prior for θ\theta. Defaults to 0.

v

Variance parameter of initial normal prior for θ\theta. Defaults to Inf (uniform prior).

...

Additional arguments passed to stats::integrate.

level

Credibility level of the highest posterior density interval. Defaults to 0.95.

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

postPP, postPPtheta, plotPP

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 θN(m,v)\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 αBeta(x,y)\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 original effect estimate.

x

Number of successes parameter for beta prior of power parameter α\alpha. Defaults to 1. Is only taken into account when alpha = NA.

y

Number of failures parameter for beta prior of power parameter α\alpha. Defaults to 1. Is only taken into account when alpha = NA.

alpha

Power parameter. Can be set to a number between 0 and 1. Defaults to NA (a beta prior on the power parameter).

m

Mean parameter of initial normal prior for θ\theta. Defaults to 0.

v

Variance parameter of initial normal prior for θ\theta. Defaults to Inf (uniform prior).

hypergeo

Logical indicating whether for uniform priors, the marginal posterior should be computed with the hypergeometric function. Defaults to FALSE (using numerical integration instead).

...

Additional arguments passed to stats::integrate or hypergeo::genhypergeo (depending on the hypergeo argument).

level

Credibility level of the highest posterior density interval. Defaults to 0.95.

thetaRange

The numerical search range for the effect size. Defaults to the level*100% confidence inteval range inflated by a factor of three. We recommend changing this argument only if there are numerical problems in calculating the HPD interval.

quantileRange

The numerical search range for the lower posterior quantile of the HPD interval. Defaults to the range between (1 - level)*0.2 and (1 - level)*0.8. We recommend changing this argument only if there are numerical problems in calculating the HPD interval.

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

postPP, postPPalpha, plotPP

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)