rnegbinRw: MCMC Algorithm for Negative Binomial Regression In bayesm: Bayesian Inference for Marketing/Micro-Econometrics

Description

`rnegbinRw` implements a Random Walk Metropolis Algorithm for the Negative Binomial (NBD) regression model where β|α and α|β are drawn with two different random walks.

Usage

 `1` ```rnegbinRw(Data, Prior, Mcmc) ```

Arguments

 `Data ` list(y, X) `Prior` list(betabar, A, a, b) `Mcmc ` list(R, keep, nprint, s_beta, s_alpha, beta0, alpha)

Details

Model and Priors

y ~ NBD(mean=λ, over-dispersion=alpha)
λ = exp(x'β)

β ~ N(betabar, A^{-1})
alpha ~ Gamma(a, b) (unless `Mcmc\$alpha` specified)
Note: prior mean of alpha = a/b, variance = a/(b^2)

Argument Details

`Data = list(y, X)`

 `y: ` n x 1 vector of counts (0,1,2,…) `X: ` n x k design matrix

`Prior = list(betabar, A, a, b)` [optional]

 `betabar: ` k x 1 prior mean (def: 0) `A: ` k x k PDS prior precision matrix (def: 0.01*I) `a: ` Gamma prior parameter (not used if `Mcmc\$alpha` specified) (def: 0.5) `b: ` Gamma prior parameter (not used if `Mcmc\$alpha` specified) (def: 0.1)

`Mcmc = list(R, keep, nprint, s_beta, s_alpha, beta0, alpha)` [only `R` required]

 `R: ` number of MCMC draws `keep: ` MCMC thinning parameter -- keep every `keep`th draw (def: 1) `nprint: ` print the estimated time remaining for every `nprint`'th draw (def: 100, set to 0 for no print) `s_beta: ` scaling for beta | alpha RW inc cov matrix (def: 2.93/`sqrt(k)`) `s_alpha: ` scaling for alpha | beta RW inc cov matrix (def: 2.93) `alpha: ` over-dispersion parameter (def: alpha ~ Gamma(a,b))

Value

A list containing:

 `betadraw ` R/keep x k matrix of beta draws `alphadraw ` R/keep x 1 vector of alpha draws `llike ` R/keep x 1 vector of log-likelihood values evaluated at each draw `acceptrbeta ` acceptance rate of the beta draws `acceptralpha ` acceptance rate of the alpha draws

Note

The NBD regression encompasses Poisson regression in the sense that as alpha goes to infinity the NBD distribution tends toward the Poisson. For "small" values of alpha, the dependent variable can be extremely variable so that a large number of observations may be required to obtain precise inferences.

Author(s)

Sridhar Narayanan (Stanford GSB) and Peter Rossi (Anderson School, UCLA), [email protected].

References

For further discussion, see Bayesian Statistics and Marketing by Rossi, Allenby, McCulloch.
http://www.perossi.org/home/bsm-1

`rhierNegbinRw`

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``` ```if(nchar(Sys.getenv("LONG_TEST")) != 0) {R=1000} else {R=10} set.seed(66) simnegbin = function(X, beta, alpha) { # Simulate from the Negative Binomial Regression lambda = exp(X%*%beta) y = NULL for (j in 1:length(lambda)) { y = c(y, rnbinom(1, mu=lambda[j], size=alpha)) } return(y) } nobs = 500 nvar = 2 # Number of X variables alpha = 5 Vbeta = diag(nvar)*0.01 # Construct the regdata (containing X) simnegbindata = NULL beta = c(0.6, 0.2) X = cbind(rep(1,nobs), rnorm(nobs,mean=2,sd=0.5)) simnegbindata = list(y=simnegbin(X,beta,alpha), X=X, beta=beta) Data1 = simnegbindata Mcmc1 = list(R=R) out = rnegbinRw(Data=Data1, Mcmc=list(R=R)) cat("Summary of alpha/beta draw", fill=TRUE) summary(out\$alphadraw, tvalues=alpha) summary(out\$betadraw, tvalues=beta) ## plotting examples if(0){plot(out\$betadraw)} ```

Example output

```Using default s_alpha = 2.93
Using default s_beta = 2.93/sqrt(nvar)

Starting Random Walk Metropolis Sampler for Negative Binomial Regression
500  obs;  2  covariates (including intercept);
Prior Parameters:
betabar
[1] 0 0
A
[,1] [,2]
[1,] 0.01 0.00
[2,] 0.00 0.01
a
[1] 0.5
b
[1] 0.1

MCMC Parms:
R=  10  keep=  1  nprint=  100
s_alpha =  2.38
s_beta =  1.682914

Initializing RW Increment Covariance Matrix...
beta_mle =  0.7069472 0.1525201
alpha_mle =  6.272214
MCMC Iteration (est time to end - min)
Total Time Elapsed: 0.00
Summary of alpha/beta draw
fewer than 100 draws submitted
fewer than 100 draws submitted
```

bayesm documentation built on Dec. 21, 2018, 9:04 a.m.