Become an expert in R — Interactive courses, Cheat Sheets, certificates and more!
Get Started for Free

MCMCnegbin

Markov Chain Monte Carlo for Negative Binomial Regression


Description

This function generates a sample from the posterior distribution of a Negative Binomial regression model via auxiliary mixture sampling. The user supplies data and priors, and a sample from the posterior distribution is returned as an mcmc object, which can be subsequently analyzed with functions provided in the coda package.

Usage

MCMCnegbin(
  formula,
  data = parent.frame(),
  b0 = 0,
  B0 = 1,
  e = 2,
  f = 2,
  g = 10,
  burnin = 1000,
  mcmc = 1000,
  thin = 1,
  verbose = 0,
  seed = NA,
  beta.start = NA,
  rho.start = NA,
  rho.step = 0.1,
  nu.start = NA,
  marginal.likelihood = c("none", "Chib95"),
  ...
)

Arguments

formula

Model formula.

data

Data frame.

b0

The prior mean of β. This can either be a scalar or a column vector with dimension equal to the number of betas. If this takes a scalar value, then that value will serve as the prior mean for all of the betas.

B0

The prior precision of β. This can either be a scalar or a square matrix with dimensions equal to the number of betas. If this takes a scalar value, then that value times an identity matrix serves as the prior precision of β. Default value of 0 is equivalent to an improper uniform prior for beta.

e

The hyperprior for the distribution ρ. See details.

f

The hyperprior for the distribution ρ. See details.

g

The hyperprior for the distribution ρ. See details.

burnin

The number of burn-in iterations for the sampler.

mcmc

The number of Metropolis iterations for the sampler.

thin

The thinning interval used in the simulation. The number of mcmc iterations must be divisible by this value.

verbose

A switch which determines whether or not the progress of the sampler is printed to the screen. If verbose is greater than 0 the iteration number, the current beta vector, and the Metropolis acceptance rate are printed to the screen every verboseth iteration.

seed

The seed for the random number generator. If NA, the Mersenne Twister generator is used with default seed 12345; if an integer is passed it is used to seed the Mersenne twister. The user can also pass a list of length two to use the L'Ecuyer random number generator, which is suitable for parallel computation. The first element of the list is the L'Ecuyer seed, which is a vector of length six or NA (if NA a default seed of rep(12345,6) is used). The second element of list is a positive substream number. See the MCMCpack specification for more details.

beta.start

The starting value for the β vector. This can either be a scalar or a column vector with dimension equal to the number of betas. If this takes a scalar value, then that value will serve as the starting value for all of the betas. The default value of NA will use the maximum likelihood estimate of β as the starting value.

rho.start

The starting value for the ρ variable. The default value is 1.

rho.step

Tuning parameter for the slice sampling approach to sampling rho. Determines the size of the step-out used to find the correct slice to draw from. Lower values are more accurate, but will take longer (up to a fixed searching limit). Default is 0.1.

nu.start

The starting values for the random effect, ν. The default value is a vector of ones.

marginal.likelihood

How should the marginal likelihood be calculated? Options are: none in which case the marginal likelihood will not be calculated or Laplace in which case the Laplace approximation (see Kass and Raftery, 1995) is used.

...

further arguments to be passed.

Details

MCMCnegbin simulates from the posterior distribution of a Negative Binomial regression model using a combination of auxiliary mixture sampling and slice sampling. The simulation proper is done in compiled C++ code to maximize efficiency. Please consult the coda documentation for a comprehensive list of functions that can be used to analyze the posterior sample.

The model takes the following form:

y_i \sim \mathcal{P}oisson(ν_iμ_i)

Where the inverse link function:

μ_i = \exp(x_i'β)

We assume a multivariate Normal prior on β:

β \sim \mathcal{N}(b_0,B_0^{-1})

The unit-level random effect that handles overdispersion is assumed to be distributed Gamma:

ν_i \sim \mathcal{G}amma(ρ, ρ)

The overdispersion parameter has a prior with the following form:

f(ρ|e,f,g) \propto ρ^{e-1}(ρ + g)^{-(e+f)}

The model is simulated via blocked Gibbs, with the the β being simulated via the auxiliary mixture sampling method of Fuerhwirth-Schanetter et al. (2009). The ρ is updated via slice sampling. The ν_i are updated their (conjugate) full conditional, which is also Gamma.

Value

An mcmc object that contains the posterior sample. This object can be summarized by functions provided by the coda package.

References

Andrew D. Martin, Kevin M. Quinn, and Jong Hee Park. 2011. “MCMCpack: Markov Chain Monte Carlo in R.”, Journal of Statistical Software. 42(9): 1-21. https://www.jstatsoft.org/v42/i09/.

Daniel Pemstein, Kevin M. Quinn, and Andrew D. Martin. 2007. Scythe Statistical Library 1.0. http://scythe.lsa.umich.edu.

Martyn Plummer, Nicky Best, Kate Cowles, and Karen Vines. 2006. “Output Analysis and Diagnostics for MCMC (CODA)”, R News. 6(1): 7-11. https://CRAN.R-project.org/doc/Rnews/Rnews_2006-1.pdf.

Sylvia Fruehwirth-Schnatter, Rudolf Fruehwirth, Leonhard Held, and Havard Rue. 2009. “Improved auxiliary mixture sampling for hierarchical models of non-Gaussian data”, Statistics and Computing 19(4): 479-492. <doi:10.1007/s11222-008-9109-4>

See Also

Examples

## Not run: 
   n <- 150
   mcmcs <- 5000
   burnin <- 5000
   thin <- 5
   x1 <- runif(n, 0, 2)
   rho.true <- 1.5
   nu.true <- rgamma(n, rho.true, rho.true)
   mu <- nu.true * exp(1 + x1 * 1)
   y <- rpois(n, mu)
   posterior <- MCMCnegbin(y ~ x1)
   plot(posterior)
   summary(posterior)
   
## End(Not run)

MCMCpack

Markov Chain Monte Carlo (MCMC) Package

v1.5-0
GPL-3
Authors
Andrew D. Martin [aut], Kevin M. Quinn [aut], Jong Hee Park [aut,cre], Ghislain Vieilledent [ctb], Michael Malecki[ctb], Matthew Blackwell [ctb], Keith Poole [ctb], Craig Reed [ctb], Ben Goodrich [ctb], Ross Ihaka [cph], The R Development Core Team [cph], The R Foundation [cph], Pierre L'Ecuyer [cph], Makoto Matsumoto [cph], Takuji Nishimura [cph]
Initial release
2021-01-19

We don't support your browser anymore

Please choose more modern alternatives, such as Google Chrome or Mozilla Firefox.