rhierBinLogit             package:bayesm             R Documentation

_M_C_M_C _A_l_g_o_r_i_t_h_m _f_o_r _H_i_e_r_a_r_c_h_i_c_a_l _B_i_n_a_r_y _L_o_g_i_t

_D_e_s_c_r_i_p_t_i_o_n:

     'rhierBinLogit' implements an MCMC algorithm for hierarchical
     binary logits with a normal heterogeneity distribution.  This is a
     hybrid sampler with a RW Metropolis step for unit-level logit
     parameters.

     'rhierBinLogit' is designed for use on choice-based conjoint data
     with partial profiles. The Design matrix is based on differences
     of characteristics between two alternatives. See Appendix A of
     _Bayesian Statistics and Marketing_ for details.

_U_s_a_g_e:

     rhierBinLogit(Data, Prior, Mcmc)

_A_r_g_u_m_e_n_t_s:

    Data: list(lgtdata,Z) (note: Z is optional) 

   Prior: list(Deltabar,ADelta,nu,V) (note: all are optional)

    Mcmc: list(sbeta,R,keep) (note: all but R are optional)

_D_e_t_a_i_l_s:

     Model: 
      y_{hi} = 1 with pr=exp(x_{hi}'beta_h)/(1+exp(x_{hi}'beta_h). 
     beta_h is nvar x 1.
      h=1,...,length(lgtdata) units or "respondents" for survey data.

     beta_h= ZDelta[h,] + u_h. 
      Note: here ZDelta refers to Z%*%Delta, ZDelta[h,] is hth row of
     this product.
      Delta is an nz x nvar array. 

     u_h ~ N(0,V_{beta}).  

     Priors: 
      delta= vec(Delta) ~ N(vec(Deltabar),V_{beta} (x) ADelta^{-1})
      V_{beta} ~ IW(nu,V)

     Lists contain:

   '_l_g_t_d_a_t_a' list of lists with each cross-section unit MNL data

   '_l_g_t_d_a_t_a[[_h]]$_y' n_h vector of binary outcomes (0,1)

   '_l_g_t_d_a_t_a[[_h]]$_X' n_h by nvar design matrix for hth unit

   '_D_e_l_t_a_b_a_r' nz x nvar matrix of prior means (def: 0)

   '_A_D_e_l_t_a' prior prec matrix  (def: .01I)

   '_n_u' 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)

   '_s_b_e_t_a' scaling parm for RW Metropolis (def: .2)

   '_R' number of MCMC draws

   '_k_e_e_p' MCMC thinning parm: keep every keepth draw (def: 1)

_V_a_l_u_e:

     a list containing: 

Deltadraw: R/keep  x nz*nvar matrix of draws of Delta

betadraw: nlgt x nvar x R/keep array of draws of betas

Vbetadraw: R/keep x nvar*nvar matrix of draws of Vbeta

   llike: R/keep vector of log-like values

  reject: R/keep vector of reject rates over nlgt units

_N_o_t_e:

     Some experimentation with the Metropolis scaling paramter (sbeta)
     may be required.

_A_u_t_h_o_r(_s):

     Peter Rossi, Graduate School of Business, University of Chicago,
     Peter.Rossi@ChicagoGsb.edu.

_R_e_f_e_r_e_n_c_e_s:

     For further discussion, see _Bayesian Statistics and Marketing_ by
     Rossi, Allenby and McCulloch, Chapter 5. 
      <URL:
     http://gsbwww.uchicago.edu/fac/peter.rossi/research/bsm.html>

_S_e_e _A_l_s_o:

     'rhierMnlRwMixture'

_E_x_a_m_p_l_e_s:

     ##  
     if(nchar(Sys.getenv("LONG_TEST")) != 0) {R=10000} else {R=10}

     set.seed(66)
     nvar=5                           ## number of coefficients
     nlgt=1000                        ## number of cross-sectional units
     nobs=10                          ## number of observations per unit
     nz=2                             ## number of regressors in mixing distribution

     ## set hyper-parameters
     ##     B=ZDelta + U  

     Z=matrix(c(rep(1,nlgt),runif(nlgt,min=-1,max=1)),nrow=nlgt,ncol=nz)
     Delta=matrix(c(-2,-1,0,1,2,-1,1,-.5,.5,0),nrow=nz,ncol=nvar)
     iota=matrix(1,nrow=nvar,ncol=1)
     Vbeta=diag(nvar)+.5*iota%*%t(iota)

     ## simulate data
     lgtdata=NULL

     for (i in 1:nlgt) 
     { beta=t(Delta)%*%Z[i,]+as.vector(t(chol(Vbeta))%*%rnorm(nvar))
       X=matrix(runif(nobs*nvar),nrow=nobs,ncol=nvar)
       prob=exp(X%*%beta)/(1+exp(X%*%beta)) 
       unif=runif(nobs,0,1)
       y=ifelse(unif<prob,1,0)
       lgtdata[[i]]=list(y=y,X=X,beta=beta)
     }

     Data=list(Dat=lgtdata,Demo=Z)
     out=rhierBinLogit(Data=list(lgtdata=lgtdata,Z=Z),Mcmc=list(R=R))

     cat(" Deltadraws ",fill=TRUE)
     mat=apply(out$Deltadraw,2,quantile,probs=c(.01,.05,.5,.95,.99))
     mat=rbind(as.vector(Delta),mat); rownames(mat)[1]="delta"; print(mat)
     cat(" Vbetadraws ",fill=TRUE)
     mat=apply(out$Vbetadraw,2,quantile,probs=c(.01,.05,.5,.95,.99))
     mat=rbind(as.vector(Vbeta),mat); rownames(mat)[1]="Vbeta"; print(mat)

     if(0){
     td=as.vector(Delta)
     par(mfrow=c(2,2))
     matplot(out$Deltadraw[,(1:nvar)],type="l")
     abline(h=td[1:nvar],col=(1:nvar))
     matplot(out$Deltadraw[,((nvar+1):(2*nvar))],type="l")
     abline(h=td[(nvar+1):(2*nvar)],col=(1:nvar))
     matplot(out$Vbetadraw[,c(1,7,13,19,25)],type="l")
     abline(h=1.5)
     matplot(out$Vbetadraw[,-c(1,7,13,19,25)],type="l")
     abline(h=.5)
     }

