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.
1 Answer 1
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...
vglm(stay ~ age + hmo + died, family = posnegbinomial, data = dat)(no parens after binomial)dput(head(dat,10))ordata.frame(.)or using a public dataset like one of the many included in theVGAMpackage. 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!VGAMand can reproduce the problem, and removing the parens does not resolve it for me. This sounds like a bug report is needed.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!VGAMmight have worked (was it1.1-7?). For a faster temporary workaround, you might considerremotes::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.