[ADMB Users] conditional statement using parameter to be estimated

dave fournier davef at otter-rsch.com
Sat May 24 08:33:14 PDT 2014


The way to do this is to use a differentiable logistic as Ben suggested. 
In addition you should use phases and gradually
increase the steepness.  Finally as a technical matter you should use 
exp(z) in place of exp(-z) to avoid overflow when
necessary.  See the attached changepoint.tpl

To run this with multiple phase you would use the command line option 
-maxph 3

Note use of value() function which will be needed in random effects model.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: changepoint.dat
Type: application/x-ns-proxy-autoconfig
Size: 277 bytes
Desc: not available
URL: <http://lists.admb-project.org/pipermail/users/attachments/20140524/a0299d23/attachment.dat>
-------------- next part --------------
DATA_SECTION
  init_int nobs
  init_vector y(1,nobs)
  vector predm(1,nobs)
PARAMETER_SECTION
  init_number m1
  init_number m2
  init_number cp
  objective_function_value f
PROCEDURE_SECTION

  double s=1;
  switch (current_phase())
  {
  case 1:
    s=1.0;
    break;
  case 2:
    s=10.0;
    break;
  case 3:
    s=100.0;
    break;
  default:
    s=1000.0;
    break;
  }

  for (int i=1;i<=nobs;i++)
  {
    dvariable p=f1(i,cp,s);
    dvariable m=p*m1+(1.0-p)*m2;
    predm(i)=value(m);
    f+=square(y(i)-m);
  }
  
REPORT_SECTION

  report << predm << endl;

GLOBALS_SECTION

  #include <admodel.h>

  dvariable f1(int i,const prevariable& cp,double s)
  {
    dvariable z=s*(cp-double(i));
    if (value(z)<20.)
    {
      return 1.0/(1+exp(z));
    }
    else
    {
      return exp(-z)/(1.0+exp(-z));
    }
  }



More information about the Users mailing list