I had tried John's suggestion initially but the compiler fails at the assignment to sigma. That is how I did it with fixed effect parameters.   I was hoping that the GLOBAL approach would work.  The problem is getting parameters to the function being integrated. Apparently the mechanism that work with fixed effect parameters doesn't carry over to random effects. Thinking out loud here, what about computing the sigma in fct rather than trying to pass it? The random effect vector seems to be global and if I make the index global, maybe that will work. Unless someone knows that it won't I'll give that a try.<div>
<br></div><div>Thanks for your responses and suggestions. </div><div><br></div><div>--jeff</div><div class="gmail_extra"><br><br><div class="gmail_quote">On Fri, Nov 9, 2012 at 11:11 AM, John Sibert <span dir="ltr"><<a href="mailto:sibert@hawaii.edu" target="_blank">sibert@hawaii.edu</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Try getting rid of the GLOBALS_SECTION and declaring sigma as a number in the PARAMETER_SECTION<div class="im"><br>
<br>
DATA_SECTION<br>
   init_int n;                        // number of distances<br>
   init_number width;<br>
   init_vector xs(1,n);               // distances<br>
PARAMETER_SECTION<br>
   init_number beta;                  // beta parameter for log-sigma;<br>
   init_bounded_number sigeps(0.000001,5);<br>
                                      // sigma for random effect;<br>
   random_effects_vector u(1,n);      // random effect for scale<br>
   objective_function_value f;        // negative log-likelihood<br></div>
   number sigma;<div class="im"><br>
<br>
PROCEDURE_SECTION<br>
   int j;<br>
// loop over each observation computing sum of log-likelihood values<br>
// integral is sqrt(pi/2)*sigma; I dropped constant<br>
   f=0;<br>
   for (j=1;j<=n;j++)<br>
   {<br>
      ll_j(j,beta,sigeps,u(j));<br>
   }<br>
<br>
SEPARABLE_FUNCTION void ll_j(const int j, const dvariable& beta,const dvariable& sigeps,const dvariable& u)<br>
   dvariable eps=u*sigeps;<br>
   int k;<br>
   dvariable mu;<br>
   sigma=exp(beta+eps);<br>
   mu=adromb(&model_parameters::<u></u>fct,0,width,8);<br>
   f -= -0.5*square(u);<br>
   f -= -log(mu) - 0.5*square(xs(j)/sigma);<br>
<br>
FUNCTION dvariable fct(const dvariable& x)<br>
// x is integration variable<br>
// ifct is index for function read from data<br>
   dvariable tmp;<br>
   tmp=mfexp(-.5*x*x/square(<u></u>sigma));<br>
   return tm<br>
<br></div>
John Sibert<br>
Emeritus Researcher, SOEST<br>
University of Hawaii at Manoa<br>
<br>
Visit the ADMB project <a href="http://admb-project.org/" target="_blank">http://admb-project.org/</a><div><div class="h5"><br>
<br>
On 11/09/2012 07:00 AM, Jeff Laake wrote:<br>
</div></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div><div class="h5">
I'm attempting to incorporate a random effect into the scale of the detection function for distance sampling which could be very useful for fitting this type of data.  With Hans help I was successful when the integral for the detection function could be solved analytically. However, I'm having a problem incorporating adromb for numerical integration.  The issue is that the function being integrated depends on the parameter sigma which includes a random effect. adromb doesn't have an argument for parameters of the function being integrated (fct below). Without random effects, sigma was in the parameter section and was available globally but that doesn't seem to work with random effects.  Below is my attempt at a solution but it fails to compile when it hits the assignment for sigma. Any suggestions/help would be much appreciated. You can find a pdf describing what I'm trying to do at: <a href="https://github.com/downloads/jlaake/ADMButils/distance_random_effect.pdf" target="_blank">https://github.com/downloads/<u></u>jlaake/ADMButils/distance_<u></u>random_effect.pdf</a><br>

<br>
DATA_SECTION<br>
   init_int n;                        // number of distances<br>
   init_number width;<br>
   init_vector xs(1,n);               // distances<br>
PARAMETER_SECTION<br>
   init_number beta;                  // beta parameter for log-sigma;<br>
   init_bounded_number sigeps(0.000001,5);<br>
                                      // sigma for random effect;<br>
   random_effects_vector u(1,n);      // random effect for scale<br>
   objective_function_value f;        // negative log-likelihood<br>
GLOBALS_SECTION<br>
  #include <admodel.h><br>
  dvariable sigma;<br>
<br>
PROCEDURE_SECTION<br>
   int j;<br>
// loop over each observation computing sum of log-likelihood values<br>
// integral is sqrt(pi/2)*sigma; I dropped constant<br>
   f=0;<br>
   for (j=1;j<=n;j++)<br>
   {<br>
      ll_j(j,beta,sigeps,u(j));<br>
   }<br>
<br>
SEPARABLE_FUNCTION void ll_j(const int j, const dvariable& beta,const dvariable& sigeps,const dvariable& u)<br>
   dvariable eps=u*sigeps;<br>
   int k;<br>
   dvariable mu;<br>
   sigma=exp(beta+eps);<br>
   mu=adromb(&model_parameters::<u></u>fct,0,width,8);<br>
   f -= -0.5*square(u);<br>
   f -= -log(mu) - 0.5*square(xs(j)/sigma);<br>
<br>
FUNCTION dvariable fct(const dvariable& x)<br>
// x is integration variable<br>
// ifct is index for function read from data<br>
   dvariable tmp;<br>
   tmp=mfexp(-.5*x*x/square(<u></u>sigma));<br>
   return tmp;<br>
<br>
<br>
<br>
<br></div></div>
______________________________<u></u>_________________<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/<u></u>mailman/listinfo/users</a><br>
</blockquote>
<br>
</blockquote></div><br></div>