| prop_test_b | R Documentation |
prop_test_b either makes inference on a single population
proportion, or else compares two population proportions.
binom_test_b is the same as prop_test_b.
prop_test_b(
n_successes,
n_failures,
n_total,
p,
predict_for_n,
ROPE,
prior = "jeffreys",
prior_shapes,
CI_level = 0.95,
PI_level = 0.95,
plot = TRUE,
seed = 1,
mc_error = 0.002
)
n_successes |
integer/numeric vector of length 1 (for 1 population) or 2 (for 2 populations) providing the number of "successes" |
n_failures |
Similar to n_successes, but for failures. Only provide this OR n_total. |
n_total |
Similar to n_successes, but for total number of trials. Only provide this OR n_failures. |
p |
optional. If provided and inference is being made for
a single population, |
predict_for_n |
Number in a future trial. If missing, |
ROPE |
ROPE for odds ratio if inference is being made for two populations. Provide either a single value or a vector of length two. If the former, the ROPE will be taken as (1/ROPE,ROPE). If the latter, these will be the bounds of the ROPE. |
prior |
Either "jeffreys" (Beta(1/2,1/2)) or "uniform" (Beta(1,1)). This is ignored if prior_shapes is provided. |
prior_shapes |
Vector of length two, giving the shape parameters for the beta distribution that will act as the prior on the population proportions. |
CI_level, PI_level |
The posterior probability to be contained in the credible and prediction intervals respectively. |
plot |
logical. Should a plot be shown? |
seed |
Always set your seed! (Unused for a single population proportion.) |
mc_error |
The number of posterior draws will ensure that with 99%
probability the bounds of the credible intervals of |
The likelihood is given by
y \sim \text{Binom}(n,p),
and the prior on p is
p \sim Beta(a,b),
where a and b are given by the argument prior_shapes. If
prior_shapes is missing and prior = "jeffreys", then a
Jeffreys prior will be used (Beta(1/2,1/2)), and if
prior = "uniform", then a uniform prior will be used (Beta(1,1)).
(returned invisible) A list with the following:
successes, failures: Number of successes and failures
posterior_mean, posterior_mean_pop1, posterior_mean_pop2:
posterior means for the population proportion
CI, CI_pop1, CI_pop2: Credible interval for the
population proportion
Pr_oddsratio_in_ROPE: (2 sample analysis only) Posterior
probability that the odds ratio is in the ROPE
PI, PI_pop1, PI_pop2: Prediction interval for the
number of trials given in predict_for_n
Pr_less_than_p: (1 sample analysis only) If p was
supplied, the posterior probability that the population proportion is less
than p
prop_plot: Prior and posterior plot of population proportion(s)
posterior_parameters: Posterior beta shape parameters for the
population proportion(s)
# Single population
prop_test_b(14,
19)
# or another way of the same thing;
prop_test_b(14,
n_total = 14 + 19)
# A null value compared against can be added:
prop_test_b(14,
19,
p = 0.5)
# Two populations
prop_test_b(c(14,22),
c(19,45))
# or equivalently
prop_test_b(c(14,22),
n_total = c(14,22) + c(19,45))
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.