View source: R/poisson_test_b.R
| poisson_test_b | R Documentation |
Make inference on one or two populations using Poisson distributed count data
poisson_test_b(
x,
offset,
r,
ROPE,
prior = "jeffreys",
prior_shape_rate,
CI_level = 0.95,
plot = TRUE,
seed = 1,
mc_error = 0.002
)
x |
Number of events. A vector of length one or two. |
offset |
Time, area, etc. measured in the Poisson process. NOTE: Do not take the log! |
r |
optional. If provided and inference is being made for
a single population, |
ROPE |
ROPE for rate 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" (Gamma(1/2,0)) or "flat" (Gamma(0.001,0.001)). This is ignored if prior_shape_rate is provided. |
prior_shape_rate |
Vector of length two, giving the shape and rate parameters for the gamma distribution that will act as the prior on the population rates. |
CI_level |
The posterior probability to be contained in the credible intervals. |
plot |
logical. Should a plot be shown? |
seed |
Always set your seed! (Unused for a single population rate) |
mc_error |
The number of posterior draws will ensure that with 99%
probability the bounds of the credible intervals of |
The likelihood is
y \sim Poi(\lambda t),
where \lambda is the rate, and t is the time or area observed
and is given by the argument offset.
The prior is given by
\lambda \sim \Gamma(a,b),
where a and b are given by the argument prior_shape_rate.
If prior_shape_rate is missing and prior = "jeffreys",
then a Jeffrey's prior will be used, i.e., \Gamma(0.5,0) (improper),
while if prior = "flat", \Gamma(0.001,0.001) will be used.
(returned invisible) A list with the following:
x, offset: data and offset(s)
posterior_mean, posterior_mean_pop1, posterior_mean_pop2:
posterior means of the Poisson rates
CI, CI_pop1, CI_pop2: Credible interval bounds for the rates
CI_lambda1_over_lambda2: Credible interval bounds for the rate
ratio (rate of population 1 over the rate of population 2)
Pr_less_than_r: (1 sample analysis only) If r was
supplied, the posterior probability that the rate is less than r.
Pr_rate_ratio_lt_one: (2 sample analysis only) Posterior
probability that the rate ratio is less than 1
Pr_rateratio_in_ROPE: (2 sample analysis only) Posterior
probability that the rate ratio is in the ROPE (based on
Pr_rate_ratio_lt_one)
rate_plot: Posterior and prior plots for the rates
posterior_parameters: Posterior parameters for rates for the
gamma posterior distribution
# One sample
poisson_test_b(x = 12)
## You can compute the posterior probability that the rate is less than r
poisson_test_b(x = 12,
r = 8)
# Two samples
poisson_test_b(x = c(12,20))
# Offsets can be included:
poisson_test_b(x = c(12,20),
offset = c(10,9))
# Different priors can be used
poisson_test_b(x = c(12,20),
prior = "flat")
poisson_test_b(x = c(12,20),
prior_shape_rate = c(20,1.5))
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.