poisgamp: Poisson sampling with a gamma prior

Description Usage Arguments Value See Also Examples

View source: R/poisgamp.R

Description

Evaluates and plots the posterior density for mu, the mean rate of occurance in a Poisson process and a gamma prior on mu

Usage

1
poisgamp(y, shape, rate = 1, scale = 1/rate, alpha = 0.05, ...)

Arguments

y

a random sample from a Poisson distribution.

shape

the shape parameter of the gamma prior.

rate

the rate parameter of the gamma prior. Note that the scale is 1 / rate

scale

the scale parameter of the gamma prior

alpha

the width of the credible interval is controlled by the parameter alpha.

...

additional arguments that are passed to Bolstad.control

Value

An object of class 'Bolstad' is returned. This is a list with the following components:

prior

the prior density assigned to mu

likelihood

the scaled likelihood function for mu given y

posterior

the posterior probability of mu given y

shape

the shape parameter for the gamma posterior

rate

the rate parameter for the gamma posterior

See Also

poisdp poisgcp

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
## simplest call with an observation of 4 and a gamma(1, 1), i.e. an exponential prior on the
## mu
poisgamp(4, 1, 1)

##  Same as the previous example but a gamma(10, ) prior
poisgamp(4, 10, 1)

##  Same as the previous example but an improper gamma(1, ) prior
poisgamp(4, 1, 0)

## A random sample of 50 observations from a Poisson distribution with
## parameter mu = 3 and  gamma(6,3) prior
set.seed(123)
y = rpois(50,3)
poisgamp(y,6,3)

## In this example we have a random sample from a Poisson distribution
## with an unknown mean. We will use a gamma(6,3) prior to obtain the
## posterior gamma distribution, and use the R function qgamma to get a
## 95% credible interval for mu
y = c(3,4,4,3,3,4,2,3,1,7)
results = poisgamp(y,6,3)
ci = qgamma(c(0.025,0.975),results$shape, results$rate)
cat(paste("95% credible interval for mu: [",round(ci[1],3), ",", round(ci[2],3)),"]\n")

## In this example we have a random sample from a Poisson distribution
## with an unknown mean. We will use a gamma(6,3) prior to obtain the
## posterior gamma distribution, and use the R function qgamma to get a
## 95% credible interval for mu
y = c(3,4,4,3,3,4,2,3,1,7)
results = poisgamp(y, 6, 3)
ci = quantile(results, c(0.025, 0.975))
cat(paste("95% credible interval for mu: [",round(ci[1],3), ",", round(ci[2],3)),"]\n")

Bolstad documentation built on Jan. 8, 2021, 2:03 a.m.