1
$\begingroup$

I'm working with a Negative binomial regression in STAN.

I would like to make predictions on a test set, but looking at the reference I can't find a negative_binomial random number generator.

Is there any way to do so without saving mean and overdispersion distributions and sampling from them in R ?

$\endgroup$

closed as off-topic by whuber Mar 28 '17 at 15:05

This question appears to be off-topic. The users who voted to close gave this specific reason:

  • "This question appears to be off-topic because EITHER it is not about statistics, machine learning, data analysis, data mining, or data visualization, OR it focuses on programming, debugging, or performing routine operations within a statistical computing platform. If the latter, you could try the support links we maintain." – whuber
If this question can be reworded to fit the rules in the help center, please edit the question.

  • 1
    $\begingroup$ I think you need to add the self-study tag. $\endgroup$ – Michael Chernick Mar 27 '17 at 22:31
  • 1
    $\begingroup$ Also since you are mainly looking for information on two software packages (STAN and R), the question is off topic for this site. $\endgroup$ – Michael Chernick Mar 27 '17 at 22:41
  • $\begingroup$ Ok, I'll move to stackoverflow and add the self study tag there, thank you for raising my awareness about this site :) $\endgroup$ – Tommaso Guerrini Mar 27 '17 at 22:42
1
$\begingroup$

From the Stan User's Guide (2.14.0), it appears you should be able to generate samples from a negative binomial using:

neg_binomial_rng(real alpha, real beta)

You can draw from this distribution on each step of your chain by including it in the normal manner in your generated quantities block, e.g.

generated quantities { vector[N] y_rep; for (n in 1:N) { y_rep[n] = neg_binomial_rng(alpha, beta); } }

Where alpha and beta are your parameter estimates at each step, and N is the total number of samples to generate - specified as input to the data block.

$\endgroup$
  • $\begingroup$ Why can't I find things on the Stan reference remains a mistery. Thank you!! $\endgroup$ – Tommaso Guerrini Mar 27 '17 at 22:46
  • 1
    $\begingroup$ @TommasoGuerrini No problem. FWIW, you can also specify using alternate parameterizations neg_binomial_2_rng(real mu, real phi) and neg_binomial_2_log_rng(real eta, real phi) which take precision and logged parameters, respectively. $\endgroup$ – khonegger Mar 27 '17 at 22:52
  • $\begingroup$ Yep, actually I used the one with the overdispersion and log, thank you again! $\endgroup$ – Tommaso Guerrini Mar 27 '17 at 22:57

Not the answer you're looking for? Browse other questions tagged or ask your own question.