I have been trying to replicate some analyses I did in another software package using -bayesmh- and my own likelihood evaluator. My first attempt went well; I wrote a likelihood evaluator for a two part Poisson (hurdle) model:
This worked fine. However, I would also like to introduce random effects for each part of the model, so I modified the evaluator
and tried various version of this:
However, each time, after running silently for several hours, I get no output other than an error message:
So - my questions are:
1. How to avoid the error? I tried removing the comma in the parameters option, restating the priors, etc, but always get the error.
2. Almost as helpful - is there a way to ask -bayesmh- to somehow parse the options and return any errors right away? Waiting several hours for a syntax error is very inefficient.
3. Have I in fact set up the random effects correctly? I cannot find any information on combining REs with -llevaluator-, so I'm just doing what seems intuitive.
thanks,
Jeph
Code:
program myhurdle
version 14.0
args lnf xb xc
tempname sig
tempvar lnfj pi linpzero linpnozero munozero logpnozero
qui gen double `linpzero'=`xb'
qui gen double `pi'=1/(1+exp(-`linpzero'))
qui gen double `linpnozero'=`xc'
qui gen double `munozero'=exp(`linpnozero')
qui gen double `logpnozero'=log(`pi')-log(1-exp(-`munozero'))-`munozero' ///
- lngamma($MH_y2+1)+$MH_y2*log(`munozero')
qui gen double `lnfj'=log(1-`pi') if $MH_touse
qui replace `lnfj' = `logpnozero' if $MH_y1>0 & $MH_touse
summarize `lnfj', meanonly
if r(N) < $MH_n {
scalar `lnf'=.
exit
}
scalar `lnf'=r(sum)
end
gen days1=days>0
bayesmh (days1 x1) (days x1), llevaluator(myhurdle) prior({days1:} {days:} , flat) saving(sim, replace) dots
Code:
program myhurdleRE
version 14.0
args lnf xb xc m1 m2
tempname sig
tempvar lnfj pi linpzero linpnozero munozero logpnozero
qui gen double `linpzero'=`xb'+`m1'
qui gen double `pi'=1/(1+exp(-`linpzero'))
qui gen double `linpnozero'=`xc'+`m2'
qui gen double `munozero'=exp(`linpnozero')
qui gen double `logpnozero'=log(`pi')-log(1-exp(-`munozero'))-`munozero' ///
- lngamma($MH_y2+1)+$MH_y2*log(`munozero')
qui gen double `lnfj'=log(1-`pi') if $MH_touse
qui replace `lnfj' = `logpnozero' if $MH_y1>0 & $MH_touse
summarize `lnfj', meanonly
if r(N) < $MH_n {
scalar `lnf'=.
exit
}
scalar `lnf'=r(sum)
end
Code:
bayesmh (days1 x1 i.id) (days x1 i.id), noconstant llevaluator(myhurdleRE, parameters({m1}, {m2})) ///
prior({days1:i.id} , normal({m1},{S1})) ///
prior({m1}, normal(`B0',10000)) prior({S1},igamma(0.001,0.001)) ///
prior({days:i.id} , normal({m2},{S2})) ///
prior({m2}, normal(`C0',10000)) prior({S2},igamma(0.001,0.001)) ///
block({days1:i.id},split) block({days:i.id},split) block({S1},gibbs) block({S2},gibbs) ///
saving(simRE, replace) dots mcmcsize(1000)
Code:
option m2 for parameter m1 is not allowed r(198);
1. How to avoid the error? I tried removing the comma in the parameters option, restating the priors, etc, but always get the error.
2. Almost as helpful - is there a way to ask -bayesmh- to somehow parse the options and return any errors right away? Waiting several hours for a syntax error is very inefficient.
3. Have I in fact set up the random effects correctly? I cannot find any information on combining REs with -llevaluator-, so I'm just doing what seems intuitive.
thanks,
Jeph

Comment