dbetabinom versions

I got this email from a student:

(1) I used the following R function in package “emdbook

dbetabinom(x,prob,size,theta, shape1,shape2,log=FALSE)

more precisely I did


(2) instead I use the following R function in package “VGAM


more precisely I did


and I get two different curves! Sad!

to which I replied only the following

> dbetabinom.ab(1:10,size=15,shape1=3,shape2=7)
[1] 0.08893281 0.12450593 0.14198045 0.14198045 0.12861758
[6] 0.10718132 0.08268273 0.05905909 0.03886795 0.02332077
> dbetabinom(1:10,size=15,shape1=3,shape2=7)
[1] 0.08893281 0.12450593 0.14198045 0.14198045 0.12861758
[6] 0.10718132 0.08268273 0.05905909 0.03886795 0.02332077

as the beta-binomial density is only defined for integers! (emdbook is the R package associated with Benjamin Bolker’s Ecological Models and Data in R.)

8 Responses to “dbetabinom versions”

  1. Just found a need for dbetabinom(), and your example was far more useful than the (traditionally obscure) manual page. Thanks!

  2. A couple of points:

    * The reason dbetabinom acts strangely is that I use `lchoose()` (log(C(n,k)) internally, which does the rounding — but `lbeta()`, which is also used, does *not* round … I will fix `dbetabinom()` to behave like `dbinom()`. (Arguably `dbetabinom.ab()` should issue a warning for non-integer x too, for consistency with R’s other distribution functions …)
    * I would suggest to the student that if they want to use `curve()`, they try


    • Thanks! I still do not think ‘curve()’ is appropriate in this case…

      • did you look at what I actually did there with curve()? I use n=11 to make sure the function only gets evaluated at integer values, and type=”h” to draw vertical indicator lines rather than connecting the densities (which I agree would be inappropriate). Admittedly it might be better to just evaluate the function at the integers “by hand” and use plot(…,type=”h”), but one would end up with the same plot.

      • sorry for being cryptic: I meant that finite support pdfs should not be drawn using a continuous curve tool like curve(), and agree that plot() would be better.

  3. dbetabinom (package emdbook) does behave strangely. When you call it at a non-integer value, it does not return 0. Instead, you get a warning stating that the value was rounded to the nearest integer.
    BUT: calling




    return different values. In the formula for the density, the value of x is sometimes rounded to the nearest integer, sometimes not. So the output value is completely meaningless.

    dbetabinom.ab (package VGAM) 

    seems to behave more reasonably, returning 0 for non integer values of x.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s