rhierMnlRwMixture {rpud} | R Documentation |
rhierMnlRwMixture
is a MCMC algorithm for a hierarchical multinomial logit with a mixture of normals
heterogeneity distribution. This is a hybrid Gibbs Sampler with a RW Metropolis step for the MNL
coefficients for each panel unit.
rhierMnlRwMixture(Data, Prior, Mcmc, output)
Data |
list(p,lgtdata,Z) ( Z is optional) |
Prior |
list(a,deltabar,Ad,mubar,Amu,nu,V,ncomp) (all but ncomp are optional) |
Mcmc |
list(s,w,R,keep,chains) (R required) |
output |
binary output format. |
Model:
y_i ~ MNL(X_i,beta_i). i=1,..., length(lgtdata). theta_i is nvar x 1.
beta_i= ZDelta[i,] + u_i.
Note: here ZDelta refers to Z%*%D, ZDelta[i,] is ith row of this product.
Delta is an nz x nvar array.
u_i ~ N(mu_{ind},Sigma_{ind}). ind ~ multinomial(pvec).
Priors:
pvec ~ dirichlet (a)
delta= vec(Delta) ~ N(deltabar,A_d^{-1})
mu_j ~ N(mubar,Sigma_j (x) Amu^{-1})
Sigma_j ~ IW(nu,V)
Lists contain:
p
p is number of choice alternatives
lgtdata
list of lists with each cross-section unit MNL data
lgtdata[[i]]$y
n_i vector of multinomial outcomes (1,...,m)
lgtdata[[i]]$X
n_i*p by nvar design matrix for ith unit
a
vector of length ncomp of Dirichlet prior parms (def: rep(5,ncomp))
deltabar
nz*nvar vector of prior means (def: 0)
Ad
prior prec matrix for vec(D) (def: .01I)
mubar
nvar x 1 prior mean vector for normal comp mean (def: 0)
Amu
prior precision for normal comp mean (def: .01I)
nu
d.f. parm for IW prior on norm comp Sigma (def: nvar+3)
V
pds location parm for IW prior on norm comp Sigma (def: nuI)
ncomp
number of components used in normal mixture
s
scaling parm for RW Metropolis (def: 2.93/sqrt(nvar))
w
fractional likelihood weighting parm (def: .1)
R
number of MCMC draws
keep
MCMC thinning parm: keep every keepth draw (def: 1)
chains
number of MCMC simulation chains for CODA
diagnostics
output
supported binary output format:
default
, bayesm
, or coda
.
For default
format: a list containing
llkdraw |
R/keep array of log likelikelhood of draws |
betadraw |
R/keep x nvar x nlgt array of draws of betas |
Deltadraw |
R/keep x nvar x nz array of Delta draws, first row is initial value |
probdraw |
R/keep x ncomp array of draws of probs of mixture components |
mudraw |
R/keep x nvar x ncomp array of draws of mean parameter of beta coefficients |
rootdraw |
R/keep x nvar x nvar x ncomp array of error variances of beta coefficients |
For bayesm
format: a list containing
Deltadraw |
R/keep x nz*nvar matrix of draws of Delta, first row is initial value |
betadraw |
nlgt x nvar x R/keep array of draws of betas |
nmix |
list of 3 components, probdraw, NULL, compdraw |
loglike |
log-likelihood for each kept draw (length R/keep) |
For CODA
output format:
A list of CODA compatible simulation chains in default format.
More on probdraw
component of nmix list in bayesm
output format:
R/keep x ncomp matrix of draws of probs of mixture components (pvec)
More on compdraw
component of return value list:
compdraw[[i]] the ith draw of components for mixtures
compdraw[[i]][[j]] ith draw of the jth normal mixture comp
compdraw[[i]][[j]][[1]] ith draw of jth normal mixture comp mean vector
compdraw[[i]][[j]][[2]] ith draw of jth normal mixture cov parm (rooti)
Note: Z should not include an intercept and is centered for ease of interpretation.
Be careful in assessing prior parameter, Amu. .01 is too small for many applications. See
Rossi et al, chapter 5 for full discussion.
Note: as of version 2.0-2 of bayesm
, the fractional weight parameter has been changed
to a weight between 0 and 1. w is the fractional weight on the normalized pooled likelihood.
This differs from what is in Rossi et al chapter 5, i.e.
like_i^(1-w) x like_pooled^((n_i/N)*w)
Large R values may be required (>20,000).
Chi Yau (based on R doc of rhierMnlRwMixture
in bayesm
by Peter Rossi)
chi.yau@r-tutor.com
Rossi, Allenby and McCulloch:
Bayesian Statistics and Marketing Ch 5
http://www.perossi.org/home/bsm-1
## Not run: library(rpud) data.path <- file.path(path.package(package="rpud"), "runit/data") # load p, Delta, Z, and simlgtdata load(file.path(data.path, "rhierMnl-n2x6x5-rd.txt.gz")) ## set parms for priors and Z R <- 5000 keep <- 5 seed <- 66 Prior <- list(ncomp=4) Mcmc <- list(R=R, keep=keep) Data <- list(p=p, lgtdata=simlgtdata, Z=Z) set.seed(seed) system.time( out <- rpud::rhierMnlRwMixture( Data=Data, Prior=Prior, Mcmc=Mcmc, output="bayesm" )) library(bayesm) cat("Summary of Delta draws", fill=TRUE) summary(out$Deltadraw, tvalues=as.vector(Delta)) cat("Summary of Normal Mixture Distribution", fill=TRUE) summary(out$nmix) if(0) { ## plotting examples plot(out$betadraw) plot(out$nmix) } ## End(Not run)