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