Thanks, Hans, for your thoughtful response.<div><br></div><div>I have tried a number of ways to increase the information about tau, including those you describe.  Success has been mixed--but this does bring up a related issue that has caused me great difficulty, and has backed me into the corner in which I find myself.  When estimating random effects and variance components (I typically follow the manual's advice and estimate both of these in a second phase), I frequently encounter loglikelihood=NaN in this second phase.  It seems to be occurring when values for the random effects that are too large (in absolute value) are tested.  The definition of "too large", of course, depends on the parameter estimates and the resulting distribution based on the structure (typically, normally-distributed) that I have assumed/simulated.  Frequently, my vector of random effects contains values in the hundreds or even thousands, when I have assumed (and simulated) a normal distribution centered around 0, and my estimated variance is ~5 (I simulated it to be about 2.5).</div>

<div><br></div><div>Is anyone aware of a way to exert some control over this search, so I can prevent NaN's from occurring, even if at the cost of a less-than-full search of the random effects' distribution?</div>
<div><br></div><div><br></div><div><br clear="all">
<br>-----------------------------<br>Chris Gast<br><a href="mailto:cmgast@gmail.com" target="_blank">cmgast@gmail.com</a><br>
<br><br><div class="gmail_quote">On Sat, May 1, 2010 at 10:40 PM, H. Skaug <span dir="ltr"><<a href="mailto:hskaug@gmail.com" target="_blank">hskaug@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">

Chris,<br>
<br>
What you are indirectly doing when using<br>
<div><br>
 totL += (.5)*(-(nyears-1)*log(tau)-.5*norm2(e/tau));<br>
<br>
</div>is to place a penalty on tau, favoring large values of tau. (Somewhat<br>
like a Bayesian prior on tau.) The penalty you have added is<br>
<br>
totL += (.5)*(nyears-1)*log(tau);<br>
<br>
<br>
But, your MLE of tau is 0. Since this is happending repeatedly<br>
on simulated datasets where you used tau>0 to generate the<br>
data, the conclusion is that tau is weakly identified under your<br>
model (given parameters and amount of data). This is maybe not<br>
good news for you, but you should appreciate ADMB telling you this.<br>
To investigate my claim you can increase the information about<br>
tau in the simulations, by increasing value of tau and the amount of data.<br>
<br>
<br>
Hans<br>
<div><div></div><div><br>
<br>
<br>
<br>
On Sat, May 1, 2010 at 9:44 PM, Chris Gast <<a href="mailto:cmgast@gmail.com" target="_blank">cmgast@gmail.com</a>> wrote:<br>
> Hello,<br>
> I'm still relatively new to ADMB--that information might be helpful in<br>
> diagnosing the problem I seem to be encountering.<br>
> The setup is this:  I have a relatively simple product-multinomial model<br>
> that I can fit well (with simulated data) when all effects are considered<br>
> fixed.  The data are age-specific harvest numbers of a fictional animal.  I<br>
> am simulating stochasticity in both survival ( logistic transformation of<br>
> \beta+e_i, e_i~N(0,tau^2)), and in my vulnerability parameter.  I have a<br>
> single vulnerability coefficient c, such that the probability of harvest is<br>
> 1-exp(-(c+e_i)*f_i), for hunter-effort level f_i in year i.  I am currently<br>
> working with 12 simulated years of data and three age classes.  For the<br>
> discussion below, I am limiting myself to fitting the single random effect<br>
> for survival (rather than both random effects for survival and<br>
> vulnerability).  (I am also simulating 4 years of binomial telemetry data to<br>
> provide information on the probability of harvest.)<br>
> The problem is this:  ADMB seems to have some trouble estimating the single<br>
> variance component.  My resulting report either spits out my initial value<br>
> (I'm using true simulated values as initial estimates), or ADMB forces the<br>
> parameter estimates as close to zero as I will allow it (of course, it's<br>
> constrained to be positive).  I have tried many avenues of attack from the<br>
> manual and in other examples, and none of them seem to alleviate the<br>
> problem.  Having run out of options, I tried replacing the "prior"<br>
> distribution portion of the log-likelihood with<br>
> totL += (.5)*(-(nyears-1)*log(tau)-.5*norm2(e/tau));<br>
> instead of the usual<br>
> totL += (-(nyears-1)*log(tau)-.5*norm2(e/tau));<br>
> and the variance component estimates are actually OK--they are at least on<br>
> the correct order of magnitude, and not precisely equal to my initial<br>
> parameter estimate.  I don't really understand why this down-weighting is<br>
> successful (or if it is truly successful or I have just gotten lucky<br>
> somehow).  I would also really like to avoid this seemingly ad hoc<br>
> procedure, since I think ADMB is powerful enough to fit this model without<br>
> resorting to such things--it seems to fit more complex models relatively<br>
> easily.<br>
> For the record, I have tried the transformation procedure of using a<br>
> standard N(0,1) density for the random effect, and then scaling up to match<br>
> the true N(0,tau^2) distribution, and in this case, this "trick" seems to<br>
> hasten ADMBs result of loglikelihood=nan, from which it does not recover.  I<br>
> have also tried playing with boundary values on constrained parameters, and<br>
> met with no success.<br>
> I have pasted a stripped-down version of my .tpl file (the working version,<br>
> with the down-weighting intact), with accompanying .dat and .pin files, in<br>
> the hope that someone would be kind enough to examine them.  I am aware that<br>
> there are probably some inefficiencies here, but I'm not yet concerned about<br>
> optimizing the program for run-time.  Of course, I'm only posting one<br>
> simulated dataset---this phenomenon occurs for hundreds of simulations in a<br>
> row.<br>
> Thanks very much,<br>
> Chris Gast<br>
><br>
><br>
> /********************* start tpl file ******************************/<br>
> DATA_SECTION<br>
>   init_int nyears;<br>
>   init_int nages;<br>
>   init_int m;<br>
>   init_vector effdat(0,nyears-1);<br>
>   init_int telnyears;<br>
>   init_vector numtagged(0,telnyears-1);<br>
>   init_vector numrecovered(0,telnyears-1);<br>
>   init_imatrix dat(0,nyears-1,0,nages-1);<br>
>   imatrix fcohort(0,nyears-1,0,nages-1);<br>
>   imatrix pcohort(0,nages-2,0,nages-1);<br>
>   imatrix fdat(0,nyears+nages-2,0,nages-1);<br>
>   int i;<br>
>   int j;<br>
> PARAMETER_SECTION<br>
>   init_vector logparms(0,m-1,1);<br>
>   init_bounded_number beta(-2,1.7,1);<br>
>   init_bounded_number logcmu(-6,1,1);<br>
>   init_bounded_number logtau(-10,1.5,2);<br>
>   random_effects_vector e(0,nyears-2,2);<br>
>   number tau;<br>
>   vector parms(0,m-1);<br>
>   number prob;<br>
>   number prevq;<br>
>   number prod;<br>
>   number datL;<br>
>   number telL;<br>
>   number auxL;<br>
>   number extraL;<br>
>   number s;<br>
>   number c;<br>
>   number sprod;<br>
>   objective_function_value totL;<br>
> PROCEDURE_SECTION<br>
>   const double pi=3.14159265358979323846264338327950288;<br>
>   double datsum;<br>
>   int colrank;<br>
>   datL=0.0; auxL=0.0; telL=0.0; tau=mfexp(logtau);<br>
>   parms=mfexp(logparms);<br>
>   c=mfexp(logcmu);<br>
>   cout << "tau=" << tau << ", c=" << c << "\n";<br>
>   for(i=0;i<(nyears+nages-1);i++){<br>
>     datsum=0;<br>
>     datL+=gammln(parms[i]+1);<br>
>     prevq=1;<br>
>     prod=0;<br>
>     colrank=0;<br>
>     sprod=1;<br>
>     for(j=0;j<nages;j++){<br>
>       if(fdat[i][j]!=-1){<br>
>         if(i<nages) prob=1-exp(-c*effdat[colrank]);<br>
>         else if(i>=nages) prob=1-exp(-c*effdat[i-nages+1+j]);<br>
>         if(colrank==0) s=1;<br>
>         else if(i<nages)<br>
>  s=exp(beta+e[colrank-1])/(1+exp(beta+e[colrank-1]));<br>
>         else if(i>=nages)<br>
> s=exp(beta+e[i-nages+1+j-1])/(1+exp(beta+e[i-nages+1+j-1]));<br>
>         sprod*=s;<br>
>         datsum+=fdat[i][j];<br>
>         datL-=gammln(fdat[i][j]+1);<br>
>         if(colrank>0) prod+=prevq*sprod*prob;<br>
>         else prod=prob;<br>
>         //cout << "prod=" << prod << ", prob=" << prob << ", s=" << s << ",<br>
> sprod=" << sprod << ", prevq=" << prevq << "\n";<br>
>         datL+=fdat[i][j]*log(prevq*sprod*prob);<br>
>         colrank++;<br>
>         prevq*=(1-prob);<br>
>       }<br>
>     }<br>
>     datL+=(parms[i]-datsum)*log(1-prod) - gammln(parms[i]-datsum+1);<br>
>   }<br>
>   //now compute radio-telemetry likelihood<br>
>   for(i=0;i<telnyears;i++){<br>
>     telL+=gammln(numtagged[i]+1) - gammln(numrecovered[i]+1) -<br>
> gammln(numtagged[i]-numrecovered[i]+1) +<br>
> numrecovered[i]*log((1-exp(-c*effdat[nyears-1]))) +<br>
> (numtagged[i]-numrecovered[i])*log(exp(-c*effdat[nyears-1]));<br>
>   }<br>
>   for(i=0;i<(nyears-1);i++){<br>
>     cout << e[i] << "\t";<br>
>   }<br>
>   cout << "\n\ndatL=" << datL << ", telL=" << telL << ", extraL=" << extraL<br>
> << ", totL=" << -(datL+telL) <<  "\n";<br>
>   cout << "cest=" << c << ", betaest=" << beta << ", tauest=" << tau <<<br>
> "\n\n\n\n\n\n\n\n\n";<br>
>   totL=(datL+telL);<br>
>   totL += (.5)*(-(nyears-1)*log(tau)-.5*norm2(e/tau));<br>
>   /*totL += -.5*norm2(u);<br>
>   e=tau*u;*/<br>
>   totL *= -1;<br>
> REPORT_SECTION<br>
>   report << "s\n" << exp(beta)/(1+exp(beta)) << "\n";<br>
>   report << "tau\n" << tau << "\n";<br>
>   report << "cmu\n" << c << "\n";<br>
>   report << "parms\n" << parms << "\n";<br>
> PRELIMINARY_CALCS_SECTION<br>
>   for(i=0;i<nyears;i++){<br>
>     effdat[i]/=1000;<br>
>   }<br>
>   for(i=0;i<(nages-1);i++){<br>
>     for(j=0;j<nages;j++){<br>
>       pcohort[i][j]=-1;<br>
>     }<br>
>   }<br>
>   for(i=0;i<nyears;i++){<br>
>     for(j=0;j<nages;j++){<br>
>       fcohort[i][j]=-1;<br>
>     }<br>
>   }<br>
>   //get the partial cohorts first<br>
>   for(i=0;i<(nages-1);i++){<br>
>     for(j=0;j<nages;j++){<br>
>       if(j>i){<br>
>         pcohort[nages-j-1+i][j] = dat[i][j];<br>
>       }<br>
>     }<br>
>   }<br>
>   //now get the "full" cohorts<br>
>   for(i=0;i<nyears;i++){<br>
>     for(j=0;j<nages;j++){<br>
>       if(i<=(nyears-nages)) fcohort[i][j]=dat[i+j][j];<br>
>         else if((j+i)<nyears) fcohort[i][j]=dat[i+j][j];<br>
>       }<br>
>   }<br>
>   //now put all the cohort data together in a single matrix<br>
>   for(i=0;i<(nyears+nages-1);i++){<br>
>     for(j=0;j<nages;j++){<br>
>       if(i<(nages-1))  fdat[i][j]=pcohort[i][j];<br>
>       else             fdat[i][j]=fcohort[i-(nages-1)][j];<br>
>     }<br>
>   }<br>
><br>
> /********************* end tpl file ******************************/<br>
><br>
> /********************* start dat file ******************************/<br>
> #nyears<br>
> 12<br>
> #nages<br>
> 3<br>
> #parameters<br>
> 14<br>
> #effort<br>
> 379 233 829 1012 807 698 859 137 779 574 460 684<br>
> #telnyears<br>
> 4<br>
> #numtagged<br>
> 100 100 100 100<br>
> #numrecovered<br>
> 13 19 17 11<br>
> #harvest data<br>
> 28 13 9<br>
> 15 8 4<br>
> 49 24 13<br>
> 53 27 13<br>
> 42 24 12<br>
> 36 16 9<br>
> 33 18 8<br>
> 5 3 1<br>
> 29 13 8<br>
> 18 12 5<br>
> 16 7 4<br>
> 23 12 5<br>
><br>
> /********************* end dat file ******************************/<br>
> /********************* start pin file ******************************/<br>
> #logparms<br>
> 5.45959 5.86647 5.92426 5.85793 5.81114 5.69709 5.5835 5.60212 5.39816<br>
> 5.30827 5.34711 5.17615 5.32301 5.11799<br>
> #beta<br>
> 0.322773<br>
> #logtau<br>
> -1.20397<br>
> #logcmu<br>
> -1.60944<br>
> #e<br>
> 0 0 0 0 0 0 0 0 0 0 0<br>
><br>
> /********************* end pin file ******************************/<br>
><br>
><br>
><br>
><br>
><br>
><br>
><br>
><br>
><br>
><br>
><br>
><br>
><br>
><br>
><br>
><br>
> -----------------------------<br>
> Chris Gast<br>
> <a href="mailto:cmgast@gmail.com" target="_blank">cmgast@gmail.com</a><br>
><br>
</div></div><div><div></div><div>> _______________________________________________<br>
> Users mailing list<br>
> <a href="mailto:Users@admb-project.org" target="_blank">Users@admb-project.org</a><br>
> <a href="http://lists.admb-project.org/mailman/listinfo/users" target="_blank">http://lists.admb-project.org/mailman/listinfo/users</a><br>
><br>
><br>
</div></div></blockquote></div><br></div>