From f867f2cceac13b85b7b8859a7be8006a3dcb659a Mon Sep 17 00:00:00 2001 From: Achim Zeileis Date: Wed, 15 May 2024 13:38:18 +0200 Subject: [PATCH] The method for objects can now also handle specifications from with fixed (reported by Christian Kleiber). --- NEWS.md | 2 ++ R/prodist.R | 7 +++++++ 2 files changed, 9 insertions(+) diff --git a/NEWS.md b/NEWS.md index f6f05d50..18ad9e17 100755 --- a/NEWS.md +++ b/NEWS.md @@ -22,6 +22,8 @@ for vectors of distributions (#101). - Fixed errors in notation of cumulative distribution function in the documentation of `HurdlePoisson()` and `HurdleNegativeBinomial()` (by @dkwhu in #94 and #96). +- The `prodist()` method for `glm` objects can now also handle `family` specifications from + `MASS::negative.binomial(theta)` with fixed `theta` (reported by Christian Kleiber). - Further small improvements in methods and manual pages. diff --git a/R/prodist.R b/R/prodist.R index 068a87bc..0c0440a9 100755 --- a/R/prodist.R +++ b/R/prodist.R @@ -200,12 +200,19 @@ prodist.glm <- function(object, ..., dispersion = NULL) { size <- if("newdata" %in% names(list(...))) 1L else object$prior.weights } + ## special case: MASS::negative.binomial() + if(startsWith(object$family$family, "Negative Binomial")) { + object$family$family <- "negative.binomial" + phi <- environment(object$family$variance)$.Theta + } + ## set up distributions object (if possible) switch(object$family$family, "gaussian" = Normal(mu = mu, sigma = sqrt(phi)), "poisson" = Poisson(lambda = mu), "binomial" = Binomial(size = size, p = mu), "Gamma" = distributions3::Gamma(shape = 1/phi, rate = 1/(phi * mu)), + "negative.binomial" = NegativeBinomial(mu = mu, size = phi), "inverse.gaussian" = stop("inverse Gaussian distributions3 object not implemented yet"), ## FIXME: could use SuppDists for this "quasi" = stop("quasi family is not associated with a full probability distribution"), "quasibinomial" = stop("quasi-Poisson family is not associated with a full probability distribution"),