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

</div>