[ADMB Users] Random effects model with integration in the likelihood

Jeff Laake jefflaake at gmail.com
Fri Nov 9 14:59:44 PST 2012


Okay, now I understand what you mean by bullet-proof.  My idea solved the
problem of passing the argument but then it fails at call to adromb which
must not work with re code.  I still don't know what that entails but I'm
learning.  If there is a programming wish-list having a re version of
adromb would be useful but I have no idea what that entails.

I've been extremely impressed by the reliability of the admb optimization.
Kudos. It certainly beats any of the optimization functions I've used in R
for the examples I have done. But Dave, that doesn't mean that I'm not
going to use R.  Let's agree to disagree but I believe integrating R and
admb will make both more useful. The optimization code in R has always been
one of its weak areas but R is far more than optimization code.  Using admb
from R overcomes that weakness in R and it also makes admb more accessible
to folks that would never be able to construct a tpl file or program in c++.

regards --jeff

regards --jeff


On Fri, Nov 9, 2012 at 2:29 PM, Jeff Laake <jefflaake at gmail.com> wrote:

> 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.
>
> Thanks for your responses and suggestions.
>
> --jeff
>
>
> On Fri, Nov 9, 2012 at 11:11 AM, John Sibert <sibert at hawaii.edu> wrote:
>
>> Try getting rid of the GLOBALS_SECTION and declaring sigma as a number in
>> the PARAMETER_SECTION
>>
>>
>> DATA_SECTION
>>    init_int n;                        // number of distances
>>    init_number width;
>>    init_vector xs(1,n);               // distances
>> PARAMETER_SECTION
>>    init_number beta;                  // beta parameter for log-sigma;
>>    init_bounded_number sigeps(0.000001,5);
>>                                       // sigma for random effect;
>>    random_effects_vector u(1,n);      // random effect for scale
>>    objective_function_value f;        // negative log-likelihood
>>    number sigma;
>>
>>
>> PROCEDURE_SECTION
>>    int j;
>> // loop over each observation computing sum of log-likelihood values
>> // integral is sqrt(pi/2)*sigma; I dropped constant
>>    f=0;
>>    for (j=1;j<=n;j++)
>>    {
>>       ll_j(j,beta,sigeps,u(j));
>>    }
>>
>> SEPARABLE_FUNCTION void ll_j(const int j, const dvariable& beta,const
>> dvariable& sigeps,const dvariable& u)
>>    dvariable eps=u*sigeps;
>>    int k;
>>    dvariable mu;
>>    sigma=exp(beta+eps);
>>    mu=adromb(&model_parameters::**fct,0,width,8);
>>    f -= -0.5*square(u);
>>    f -= -log(mu) - 0.5*square(xs(j)/sigma);
>>
>> FUNCTION dvariable fct(const dvariable& x)
>> // x is integration variable
>> // ifct is index for function read from data
>>    dvariable tmp;
>>    tmp=mfexp(-.5*x*x/square(**sigma));
>>    return tm
>>
>> John Sibert
>> Emeritus Researcher, SOEST
>> University of Hawaii at Manoa
>>
>> Visit the ADMB project http://admb-project.org/
>>
>>
>> On 11/09/2012 07:00 AM, Jeff Laake wrote:
>>
>>> 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: https://github.com/downloads/**
>>> jlaake/ADMButils/distance_**random_effect.pdf<https://github.com/downloads/jlaake/ADMButils/distance_random_effect.pdf>
>>>
>>> DATA_SECTION
>>>    init_int n;                        // number of distances
>>>    init_number width;
>>>    init_vector xs(1,n);               // distances
>>> PARAMETER_SECTION
>>>    init_number beta;                  // beta parameter for log-sigma;
>>>    init_bounded_number sigeps(0.000001,5);
>>>                                       // sigma for random effect;
>>>    random_effects_vector u(1,n);      // random effect for scale
>>>    objective_function_value f;        // negative log-likelihood
>>> GLOBALS_SECTION
>>>   #include <admodel.h>
>>>   dvariable sigma;
>>>
>>> PROCEDURE_SECTION
>>>    int j;
>>> // loop over each observation computing sum of log-likelihood values
>>> // integral is sqrt(pi/2)*sigma; I dropped constant
>>>    f=0;
>>>    for (j=1;j<=n;j++)
>>>    {
>>>       ll_j(j,beta,sigeps,u(j));
>>>    }
>>>
>>> SEPARABLE_FUNCTION void ll_j(const int j, const dvariable& beta,const
>>> dvariable& sigeps,const dvariable& u)
>>>    dvariable eps=u*sigeps;
>>>    int k;
>>>    dvariable mu;
>>>    sigma=exp(beta+eps);
>>>    mu=adromb(&model_parameters::**fct,0,width,8);
>>>    f -= -0.5*square(u);
>>>    f -= -log(mu) - 0.5*square(xs(j)/sigma);
>>>
>>> FUNCTION dvariable fct(const dvariable& x)
>>> // x is integration variable
>>> // ifct is index for function read from data
>>>    dvariable tmp;
>>>    tmp=mfexp(-.5*x*x/square(**sigma));
>>>    return tmp;
>>>
>>>
>>>
>>>
>>> ______________________________**_________________
>>> Users mailing list
>>> Users at admb-project.org
>>> http://lists.admb-project.org/**mailman/listinfo/users<http://lists.admb-project.org/mailman/listinfo/users>
>>>
>>
>>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.admb-project.org/pipermail/users/attachments/20121109/7b979cbe/attachment.html>


More information about the Users mailing list