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