Skip to contents

Base class for the binomial models whose posterior is available in closed form.

Both the separate-analysis and the pooled-analysis models place a uniform prior on the control rate and, conditionally on it, a uniform prior on the treatment effect over (-control_rate, 1 - control_rate). That interval has width 1 whatever the control rate, so the joint prior density is constant and the pair (control_rate, treatment_rate) is uniform on the unit square, i.e. independent Beta(1, 1) priors on the two arm response rates. The binomial likelihood factorises over arms, so the posterior is a product of two independent Beta distributions:

$$p_c \mid D \sim Beta(s_c + 1, n_c - s_c + 1), \quad p_t \mid D \sim Beta(s_t + 1, n_t - s_t + 1)$$

and the treatment effect is their difference. Moments are available analytically; the distribution function of the difference is obtained by one-dimensional quadrature over the control rate - see beta_difference_expectation() - and inverted numerically for quantiles, so no Monte Carlo error enters the operating characteristics.

Super class

Model -> BinomialConjugate

Public fields

control_shape1

First shape parameter of the control rate posterior.

control_shape2

Second shape parameter of the control rate posterior.

treatment_shape1

First shape parameter of the treatment rate posterior.

treatment_shape2

Second shape parameter of the treatment rate posterior.

n_quadrature_nodes

Gauss-Legendre nodes per smooth piece of the integral over the control rate.

interval_memo

Credible intervals of the current posterior, by level.

Methods

Inherited methods


BinomialConjugate$new()

Initialize the BinomialConjugate object

Usage

BinomialConjugate$new(prior, mcmc_config = NULL)

Arguments

prior

The prior object

mcmc_config

Unused, kept so that the model factory can build every binomial model with the same call.


BinomialConjugate$summary_rows()

Rows of the model summary, with the shape parameters of the Beta posteriors on the two response rates

Usage

BinomialConjugate$summary_rows()

Returns

A data frame with columns Attribute and Value.


BinomialConjugate$prepare_data()

Assemble the event counts the posterior conditions on. Subclasses must implement the 'prepare_data' method.

Usage

BinomialConjugate$prepare_data(target_data)

Arguments

target_data

The target data for inference


BinomialConjugate$posterior_moments()

Compute the posterior moments in closed form

Usage

BinomialConjugate$posterior_moments(target_data)

Arguments

target_data

Target study data


BinomialConjugate$posterior_cdf()

Posterior CDF of the treatment effect

Usage

BinomialConjugate$posterior_cdf(target_treatment_effect)

Arguments

target_treatment_effect

Point at which to evaluate the posterior CDF


BinomialConjugate$posterior_pdf()

Posterior PDF of the treatment effect

Usage

BinomialConjugate$posterior_pdf(target_treatment_effect)

Arguments

target_treatment_effect

Point at which to evaluate the posterior PDF


BinomialConjugate$posterior_quantile()

Quantiles of the posterior treatment effect

Usage

BinomialConjugate$posterior_quantile(probability)

Arguments

probability

Probabilities at which to evaluate the quantile function


BinomialConjugate$posterior_median()

Posterior median

Usage

BinomialConjugate$posterior_median(...)

Arguments

...

Additional argument

Returns

The posterior median


BinomialConjugate$credible_interval()

Credible interval on the treatment effect

Usage

BinomialConjugate$credible_interval(level = 0.95)

Arguments

level

Level of the credible interval


BinomialConjugate$posterior_ess()

Effective sample sizes of the current posterior

The posterior variance is available in closed form and the credible interval comes from the same quadrature the rest of the class uses, so both effective sample sizes are evaluated directly. The inherited route would instead fit a mixture to a finite sample drawn from the posterior, which costs a mixture fit per replicate and leaves Monte Carlo error in a quantity that has no need of it.

Usage

BinomialConjugate$posterior_ess(target_data, ...)

Arguments

target_data

Target study data

...

Unused, kept so that the simulation can call every model the same way.

Returns

A list with the moment and precision effective sample sizes.


BinomialConjugate$sample_posterior()

Draw independent samples from the posterior

Usage

BinomialConjugate$sample_posterior(n_samples)

Arguments

n_samples

Number of samples to draw


BinomialConjugate$sample_prior()

Draw samples from the prior

Usage

BinomialConjugate$sample_prior(n_samples)

Arguments

n_samples

Number of samples from the prior


BinomialConjugate$prior_given_control_rate()

The prior of the treatment effect given the target control rate

The marginal prior averages over a uniform control rate and spans (-1, 1); a trial whose control rate is known can only have an effect in (-control_rate, 1 - control_rate), and given the control rate the effect is uniform there.

Usage

BinomialConjugate$prior_given_control_rate(control_rate)

Arguments

control_rate

The target control rate.

Returns

A list of three functions of the treatment effect: cdf, pdf, and sample, which takes the number of draws.


BinomialConjugate$prior_pdf()

Prior PDF

Usage

BinomialConjugate$prior_pdf(target_treatment_effect)

Arguments

target_treatment_effect

Point at which to evaluate the prior PDF


BinomialConjugate$prior_cdf()

Prior CDF

Usage

BinomialConjugate$prior_cdf(target_treatment_effect)

Arguments

target_treatment_effect

Point at which to evaluate the prior CDF


BinomialConjugate$clone()

The objects of this class are cloneable with this method.

Usage

BinomialConjugate$clone(deep = FALSE)

Arguments

deep

Whether to make a deep clone.