Skip to content

Commit

Permalink
use prob as default for negative binomial
Browse files Browse the repository at this point in the history
  • Loading branch information
edknock committed Oct 18, 2024
1 parent 255bb05 commit c4d310a
Showing 1 changed file with 16 additions and 15 deletions.
31 changes: 16 additions & 15 deletions R/dsl-distributions.R
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,21 @@ distr_hypergeometric <- distribution(
mean = quote(k * n1 / (n1 + n2))),
cpp = list(density = "hypergeometric", sample = "hypergeometric"))

distr_negative_binomial_prob <- distribution(
name = "NegativeBinomial",
variant = "prob",
density = function(x, size, prob) {
dnbinom(x, size, prob = prob, log = TRUE)
},
domain = c(0, Inf),
sample = function(rng, size, prob) rng$negative_binomial_prob(1, size, prob),
expr = list(
density = quote(lgamma(x + size) - lgamma(size) - lgamma(x + 1) +
x * log(1 - prob) + size * log(prob)),
mean = quote(size * (1 - prob) / prob)),
cpp = list(density = "negative_binomial_prob",
sample = "negative_binomial_prob"))

distr_negative_binomial_mu <- distribution(
name = "NegativeBinomial",
variant = "mu",
Expand All @@ -140,20 +155,6 @@ distr_negative_binomial_mu <- distribution(
mean = quote(mu)),
cpp = list(density = "negative_binomial_mu", sample = "negative_binomial_mu"))

distr_negative_binomial_prob <- distribution(
name = "NegativeBinomial",
variant = "prob",
density = function(x, size, prob) {
dnbinom(x, size, prob = prob, log = TRUE)
},
domain = c(0, Inf),
sample = function(rng, size, prob) rng$negative_binomial_prob(1, size, prob),
expr = list(
density = quote(lgamma(x + size) - lgamma(size) - lgamma(x + 1) +
x * log(1 - prob) + size * log(prob)),
mean = quote(size * (1 - prob) / prob)),
cpp = list(density = "negative_binomial_prob", sample = "negative_binomial_prob"))

distr_normal <- distribution(
name = "Normal",
density = function(x, mean, sd) dnorm(x, mean, sd, log = TRUE),
Expand Down Expand Up @@ -195,8 +196,8 @@ dsl_distributions <- local({
distr_gamma_rate,
distr_gamma_scale,
distr_hypergeometric,
distr_negative_binomial_mu,
distr_negative_binomial_prob,
distr_negative_binomial_mu,
distr_normal,
distr_poisson,
distr_uniform)
Expand Down

0 comments on commit c4d310a

Please sign in to comment.