[ADMB Users] conditional statement using parameter to be estimated

John Sibert sibert at hawaii.edu
Fri May 23 17:31:55 PDT 2014


Hi Tiffany,

Yes it is possible to do what you seem to be trying to do with ADMB, but 
perhaps not in the way you have envisaged.

You have two problems in the code as it is written:

1. The compiler (and Aaron) have identified an incompatibility in the 
"<" operator which appears to be comparing an integer object with a 
differentiable object. One solution is to write the code for the 
required operator. A simpler (for your point of view) solution would be 
cast the left side of comparison to an object for which the required 
operator is available, that is, write something like
if( (double)(yrKey(n))<cp){
Even simpler yet, redefine the yrKey variable to be a floating point 
opject (eg vector).

2. Logical comparisons on model parameters, as Ben pointed out, usually 
lead to errors computing the likelihood gradients. Using a logistic 
"switch" is one solution, but the parameter you are interested in my be 
difficult to estimate. My colleagues and I faced this problem when 
attempting to detect a difference in behavior of a tag a attached to a 
fish and a freely drifting tag. Anders Nielsen developed a change point 
estimation algorithm described in our paper
"Inter-annual variation in large-scale movement of Atlantic bluefin tuna 
(Thunnus thynnus) determined from pop-up satellite archival tags. Can. 
J. Fish. Aquat. Sci. 63: 2154-2166". (I will send you the pdfs off list; 
the supplementary material is particularly relevant.)  I'm guessing that 
this approach might be very similar to what you are trying to do, 
although it is difficult to be sure without knowing more about your 
problem. As a last resort, you can finesse the non-differentiability 
issue by using MCMC to search for the mode of the posterior distributions.

Cheers,
John

John Sibert
Emeritus Researcher, SOEST
University of Hawaii at Manoa
Honolulu HI (GMT-10)
808-294-3842 (mobile)

Visit the ADMB project http://admb-project.org/

On 05/23/2014 11:29 AM, Tiffany Vidal wrote:
> Hello,
>
> I'm just starting to use ADMB, and am interested in running a 
> something like a changepoint model. I am running into problems trying 
> to use a parameter, to be estimated, in a conditional statement. When 
> estimating the negative log likelihood I have code that looks like this:
>
>  if(useNB==1){
>     for(int n=1;n<=nobs;n++){
>
> *if(yrKey(n)<cp)*{
>         
> mu_hat(n)=f0+*rS1*(siteKey(n))+(f1+rSs(siteKey(n)))*Cyear(n)+rY(yrKey(n)); 
>
>         }
>      else {
>           
> mu_hat(n)=f0+*rS2*(siteKey(n))+(f1+rSs(siteKey(n)))*Cyear(n)+rY(yrKey(n)); 
>
>       }
>       NB_mu(n)=mfexp(mu_hat(n));
>
>                nll += 
> -log_negbinomial_density((catch(n)),(NB_mu(n)),(1+((NB_mu(n))/s)));
>     }
>   }
>
>
> where cp is my changepoint parameter (intended to estimate a single 
> year in the series), bounded between 0 and max(year index), with an 
> initial value of 30 (max year index = 50). The point of this is to 
> allow the random site parameter to be estimated separately for the 
> period before the changepoint and after it.
>
> The error that I receive is as follows:
> error: no match for 'operator<' in 
> '((df1b2_parameters*)this)->df1b2_parameters::<anonymous>.df1b2_pre_parameters::<anonymous>.model_parameters::<anonymous>.model_data::yrKey.ivector::operator()(n) 
> < ((df1b2_parameters*)this)->df1b2_parameters::cp'
>
> Is this possible to do in this program? Thank you in advance for any 
> thoughts on how to execute this.
>
> Kindly,
> Tiffany
>
>
> _______________________________________________
> Users mailing list
> Users at admb-project.org
> http://lists.admb-project.org/mailman/listinfo/users



More information about the Users mailing list