## 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

curve(dbetabinom(x,size=15,shape1=3,shape2=7),ylim=c(0,.12),xlim=c(0,10))(2) instead I use the following R function in package “VGAM”

dbetabinom.ab(x,size,shape1,shape2,log=FALSE,.dontuse.prob=NULL)more precisely I did

curve(dbetabinom.ab(x,size=15,shape1=3,shape2=7),ylim=c(0,.12),xlim=c(0,10))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*.)

February 18, 2013 at 3:42 pm

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

curve(dbetabinom(x,size=15,shape1=3,shape2=7),

ylim=c(0,.12),xlim=c(0,10),n=11,type=”h”)

February 19, 2013 at 6:51 am

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

February 19, 2013 at 2:00 pm

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.

February 20, 2013 at 4:26 am

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.

February 18, 2013 at 10:17 am

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

and

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.

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