rethinking (version 2.13)

dgampois: Gamma-Poisson probability density

Description

Functions for computing density and producing random samples from a gamma-Poisson (negative-binomial) probability distribution.

Usage

dgampois( x , mu , scale , log=FALSE )
rgampois( n , mu , scale )

Arguments

x

Integer values to compute probabilies of

mu

Mean of gamma distribution

scale

Scale parameter of gamma distribution

log

If TRUE, returns log-probability instead of probability

n

Number of random observations to sample

Details

These functions provide density and random number calculations for gamma-Poisson observations. These functions use dnbinom and rnbinom internally, but convert the parameters from the mu and scale form. The size parameter of the negative-binomial is defined by mu/scale, and the prob parameter of the negative-binomial is the same as 1/(1+scale).

Examples

Run this code
# NOT RUN {
data(Hurricanes)

# map model fit
# note exp(log_scale) to constrain scale to positive reals
m <- map(
    alist(
        deaths ~ dgampois( mu , exp(log_scale) ),
        log(mu) <- a + b*femininity,
        a ~ dnorm(0,100),
        b ~ dnorm(0,1),
        log_scale ~ dnorm(1,10)
    ),
    data=Hurricanes )

# map2stan model fit
# constraint on scale is passed via contraints list
m.stan <- map2stan(
    alist(
        deaths ~ dgampois( mu , scale ),
        log(mu) <- a + b*femininity,
        a ~ dnorm(0,100),
        b ~ dnorm(0,1),
        scale ~ dcauchy(0,2)
    ),
    data=Hurricanes,
    constraints=list(scale="lower=0"),
    start=list(scale=2) )
# }

Run the code above in your browser using DataLab