1

I'm trying to fit a zero-truncated negative binomial model using the vglm() function from the VGAM package in R. However, I'm encountering the following error:

> dat <- read.dta("https://stats.idre.ucla.edu/stat/data/ztp.dta")
> library(VGAM)
> m1 <- vglm(stay ~ age + hmo + died, family = posnegbinomial(), data = dat)

Error in dposnegbin2(y, kmat, munb = munb, log = TRUE) : could not find function "dposnegbin2"

I’ve confirmed that the VGAM package is loaded, but the error suggests an internal function dposnegbin2() is not available.

Has anyone else encountered this issue? Is there a known fix? I'm also open to alternative ways to fit a positive or zero-truncated negative binomial model in R.

Jan
12k7 gold badges25 silver badges36 bronze badges
asked Jul 15, 2025 at 13:32
7
  • The docs show it used without the parens, try vglm(stay ~ age + hmo + died, family = posnegbinomial, data = dat) (no parens after binomial) Commented Jul 15, 2025 at 13:57
  • Welcome to SO, Ariel! If my first comment does not resolve it for you, it helps incredibly if your question is reproducible as a min-reprex. For that, please add sample data, either using dput(head(dat,10)) or data.frame(.) or using a public dataset like one of the many included in the VGAM package. For that, please edit your question and add the sample data in a code block (see how I suggested an edit to your question to put the code in a code block, also beneficial). Thanks, good luck, and please report back! Commented Jul 15, 2025 at 14:02
  • I just installed VGAM and can reproduce the problem, and removing the parens does not resolve it for me. This sounds like a bug report is needed. Commented Jul 15, 2025 at 14:07
  • Hi r2evans, Thank you so much for your reply and help! I have tried vglm(stay ~ age + hmo + died, family = posnegbinomial, data = dat); but it has the same response: Error in dposnegbin2(y, kmat, munb = munb, log = TRUE) : could not find function "dposnegbin2". I just edited the question as you suggested! Thank you! Commented Jul 15, 2025 at 14:11
  • I think @user20650 (?) reported that an older version of VGAM might have worked (was it 1.1-7?). For a faster temporary workaround, you might consider remotes::install_version(.) for less-up-to-date versions listed here. I haven't tried it, it's just grunt-work, esp since you likely have to restart R after installing each new version. Commented Jul 15, 2025 at 15:05

1 Answer 1

2

Sorry about this bug.

It is currently fixed at https://www.stat.auckland.ac.nz/~yee/VGAM/prerelease/ sorry Mac unavailable there.I hope to submit VGAM to CRAN later this year, if you really need it for the Mac.

Best, Thomas

ps. the following ought to work but doesn't because of another bug.

library(VGAM)
library(foreign)
dat <- read.dta("https://stats.idre.ucla.edu/stat/data/ztp.dta")
m1 <- vglm(stay ~ age + hmo + died, family = posnegbinomial,
 data = dat)
m2 <- vglm(stay ~ age + hmo + died,
 gaitdnbinomial(truncate = 0, zero = 2),
 data = dat)
coef(m1, matrix = TRUE)
coef(m2, matrix = TRUE)
max(abs(coef(m1) - coef(m2))) # Should be 0

I just fixed up this bug however my VPN does not work from home anymore so I cannot update the very latest prerelease onto the website just now. Maybe in a few days time...

MetehanGungor
5271 gold badge4 silver badges23 bronze badges
answered Jul 17, 2025 at 2:12
Sign up to request clarification or add additional context in comments.

2 Comments

As it’s currently written, your answer is unclear. Please edit to add additional details that will help others understand how this addresses the question asked. You can find more information on how to write good answers in the help center.
Just to say I have hit the same bug just now - I will try the pre-release and see if that works.

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.