[ADMB Users] simulating and fitting negative binomial in ADMB

Mark Payne mpa at aqua.dtu.dk
Tue Mar 8 04:38:01 PST 2011


Hi,

I have been having a lot of problems trying to fit a negative binomial distribution in ADMB. In the end, I sat down and wrote the simplest possible simulation code, where I use ADMB's build in negative bionomial random number generator to generate a set of negative bionomially distributed numbers, and then tried to fit the negative binomial distribution. In both cases I am using the built in negative binomial functions. However, I am simply not able to reconstruct the parameters that I have used to generate the simulated data in the first place - the ADMB minimizer stalls. Playing with phases doesn't help either.

The question is why isn't this working? Am I don't something really dumb? Have I misunderstood how this is supposed to work?

Code copied below.

Best wishes,

Mark


GLOBALS_SECTION
  #include <ctime>  //Allow random number seeding
  int ndat = 1000;
  int const MU_PHASE =1;
  int const TAU_PHASE=1;

DATA_SECTION
  vector dat(1,ndat)
  number mu_sim
  number tau_sim

PARAMETER_SECTION
  init_number log_mu(MU_PHASE)
  sdreport_number mu
  init_bounded_number tau(1,5,TAU_PHASE)     //Accounts for overdispersion
  objective_function_value nll

PRELIMINARY_CALCS_SECTION
  random_number_generator rand_gen(time(0));
  mu_sim=10;
  tau_sim =2;
  for(int i=1;i<=ndat;i++) {
    dat(i) = randnegbinomial(mu_sim,tau_sim,rand_gen);
  }
  
PROCEDURE_SECTION
  nll =0;
  mu = exp(log_mu);

  for(int i=1;i<=ndat;i++) {
    nll += -log_negbinomial_density(dat(i),mu,tau) ;
  }

REPORT_SECTION
  cout << "Results" << endl;
  cout << "Mu est   : " << mu <<  "\t sim : " << mu_sim <<endl;
  cout << "Tau est  : " << tau << "\t sim : " << tau_sim << endl;
  report << dat << endl;




More information about the Users mailing list