[ADMB Users] Beta-binomial random number generation

Tom Porteus tporteus at gwct.org.uk
Mon Nov 4 02:01:09 PST 2013

Hi ADMB users,

I'm using ADMB 11.1 on Windows 7 with Visual C++ 2010 and I'm trying to generate some beta-binomial random numbers but have come across a problem.  I've written a 'rbetabinom' function in ADMB using a combination of the rbeta function from the qfclib library and fill_randbi.  However, I've found that for some random seed values, rbeta returns a value >1.0, so there must be an error somewhere in that as it should be in the [0,1].  Digging into qfc_sim.cpp, I see that rbeta uses the rgamma function from that library in what I think is a suitable way (although perhaps only when the shape parameters are integers?), meaning the problem might be with that rgamma function, but I can't find what that problem is.  Has anyone come across this problem with rbeta before, and if not, what am I doing wrong?

I've attached (if the listserv doesn't remove them) my .tpl and .dat files.  I've not been able to fully test the properties of my rbetabinom function as it bombs out when a beta variate >1.0 is produced, if you change the first line in the .dat file from 20 to 30 you will see what I mean.  I can't generate more than about 20 beta variates before this happens so the numerical mean and variance are unlikely to be reliable, meaning I don't really know if I've made an error in my function code.  If anyone out there already has a neater solution to generating beta-binomial numbers, I'd be grateful if you could share it.


Tom Porteus, MSc.
Ecologist, Game & Wildlife Conservation Trust
PhD Candidate (Zoology), University of British Columbia
Burgate Manor, Fordingbridge, Hampshire, UK, SP6 1EF
Web: www.gwct.org.uk<http://www.gwct.org.uk/>


This communication from the Game & Wildlife Conservation Trust contains information which is confidential and may also be privileged. It is for the exclusive use of the addressee. If you are not the addressee please note that any distribution, copying or use of this communication or the information in it is prohibited. If you have received this communication in error, please telephone us immediately to arrange for its return.
The Game & Wildlife Conservation Trust is a charitable company limited by guarantee registered in England and Wales under number 05579632, registered charity number 1112023 (England and Wales) and SC038868 (Scotland). VAT Reg 665 2959 92. Registered Office: Burgate Manor, Fordingbridge, Hampshire SP6 1EF Tel: +44(0)1425 652381. Email: info at gwct.org.uk Web: www.gwct.org.uk Registered Office: Burgate Manor, Fordingbridge, Hampshire SP6 1EF
Game & Wildlife Conservation Trading is a company limited by guarantee (registered no 1503620, VAT Reg No 323 7013 94.) which carries out trading and advisory activities and some fundraising events for the Game & Wildlife Conservation Trust. Registered in England and Wales. Registered Office: Burgate Manor, Fordingbridge, Hampshire SP6 1EF
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.admb-project.org/pipermail/users/attachments/20131104/f8ce07b4/attachment.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: rbetabinom.dat
Type: application/octet-stream
Size: 71 bytes
Desc: rbetabinom.dat
URL: <http://lists.admb-project.org/pipermail/users/attachments/20131104/f8ce07b4/attachment.obj>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: rbetabinom.tpl
Type: application/octet-stream
Size: 2027 bytes
Desc: rbetabinom.tpl
URL: <http://lists.admb-project.org/pipermail/users/attachments/20131104/f8ce07b4/attachment-0001.obj>

More information about the Users mailing list