How to truncate Negative Binomial (log parametrization)

78 views
Skip to first unread message

Philip Wong

unread,
Jul 26, 2016, 10:52:19 AM7/26/16
to Stan users mailing list

Hi all, first time poster here.

I have a question about the truncation of a negative binomial variable.
Below you can find my model which is part of a hurdle model therefore I only want to model strictly positive counts, for which I need a truncation at 1.
Please take a look at the statement in bold.

data {
  int<lower=1> I; //number of individuals
  int<lower=1> N; //number of observations for all individuals over time
  int<lower=1> L; //number of parameters for mu
  matrix[I,L] X; //predictor variables for mu parameter
  int<lower=1,upper=12> y[N]; //counts
  int mu_idx[N]; //index indicating what parameter should be used for each observation
}

parameters {
  real beta_zero;
  vector[L] beta;
  real<lower=0> phi;
} 

model {
  vector[I] mu_param;
  real mu[N];

  beta_zero ~ normal(1,2);
  beta ~ normal(0,3);
  phi ~ normal(2,0.5);

  mu_param <- beta_zero + X * beta;
  mu <- to_array_1d(mu_param[mu_idx]);

  y ~ neg_binomial_2_log(mu,phi);
  for (n in 1:N){
  increment_log_prob(log1m_exp(neg_binomial_2_log_log(0,mu[n],phi))); //should be a truncation at 1
  }
}

The model works fine, I'm just wondering whether I should use 0 or 1 in the statement in bold if I want to truncate my distribution at 1?
Also if you have any other tips on which I can improve my model it is greatly appreciated.

Thanks in advance!

Philip

Bob Carpenter

unread,
Aug 8, 2016, 10:13:32 PM8/8/16
to stan-...@googlegroups.com
I'd recommend upgrading to 2.11 and using our new syntax!
I'd declare mu to be the type you want rather than trying
to convert a vector to array.

This

> log1m_exp(neg_binomial_2_log_log(0,mu[n],phi)))

is just the log of 1 minus the neg binomial evaluated
at 0, which gives you truncation below at 1 inclusive.

The bigger point is that negative binomial goes above
12, but your data doesn't. Could it have? If not, negative
binomial is probably the wrong model here.

- Bob
> --
> You received this message because you are subscribed to the Google Groups "Stan users mailing list" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to stan-users+...@googlegroups.com.
> To post to this group, send email to stan-...@googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.

Reply all
Reply to author
Forward
0 new messages