[ADMB Users] simulating and fitting negative binomial in ADMB

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


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,


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

  vector dat(1,ndat)
  number mu_sim
  number tau_sim

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

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

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

  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