Learn R Programming

mcmcsae (version 0.8.1)

f_poisson: Specify a Poisson sampling distribution

Description

This function can be used in the family argument of create_sampler or generate_data to specify a Poisson sampling distribution.

Usage

f_poisson(link = "log", control = poisson_control())

Value

A family object.

Arguments

link

the name of a link function. Currently the only allowed link function for the Poisson distribution is "log".

control

a list with computational options. These options can be specified using function poisson_control.

Examples

Run this code
if (FALSE) {
n <- 3000
m <- 25
dat <- data.frame(
  x = rnorm(n),
  g = factor(sample(1:m, n, replace=TRUE), levels=1:m)
)
v <- rnorm(m, sd=0.6)
dat$y <- rpois(n, lambda=exp(with(dat, 1 - 0.5*x + v[g])))

sampler <- create_sampler(
  y ~ reg(~ x, name="beta") +       # fixed effects
      gen(factor = ~ g, name="v"),  # random intercepts
  data=dat, family="poisson"
)
sim <- MCMCsim(sampler, store.all=TRUE)
compute_DIC(sim)
waic(sim)
summary(sim)

bayesplot::mcmc_recover_intervals(as.array(sim$beta), c(1, -0.5))
bayesplot::mcmc_recover_intervals(as.array(sim$v_sigma), 0.6)
yrep <- predict(sim, iters=sample(1:1000, 10))
bayesplot::pp_check(dat$y, as.matrix(yrep), bayesplot::ppc_dens_overlay)
}

Run the code above in your browser using DataLab