[ADMB Users] Integrating R and ADMB to generalize TPL files

Mollie Brooks mbrooks at ufl.edu
Tue Oct 30 10:22:07 PDT 2012


Hi Jeff,
I agree that R2admb is the easiest way to get data into ADMB and get results out of it. 
I have a couple of examples posted also.
http://www.admb-project.org/examples/r-stuff/gamma-distributed-myxomatosis-using-r2admb
http://www.admb-project.org/examples/glmm-generalized-linear-mixed-models/negative-binomial-fir-fecundity-1  

The example at the first link shows a comparison of using a completed tpl file versus letting R2admb write the DATA_SECTION and PARAMETER_SECTION. The benefit of writing those sections yourself is that you can use the same tpl file on datasets of different sizes. R2admb hard codes the dimension sizes into the tpl file.

I also highly recommend using R2admb for getting mcmc results out of the psv file. I recently saved a colleague from reinventing the wheel by showing him the code below that runs the bcb example (distributed in admb-trunk/examples/admb-re). I'll write this up more formally sometime soon. There are also many examples coming soon from an NCEAS working group.

cheers,
Mollie 

Mollie Brooks
Postdoctoral Researcher, Ponciano Lab
Biology Department, University of Florida
http://people.biology.ufl.edu/mbrooks

library(R2admb)
setup_admb()
library(coda)
compile_admb("bcb", verbose=TRUE, re=TRUE)
run_admb("bcb", verbose=TRUE, 
	mcmc=TRUE, 
	mcmc.opts=mcmc.control(mcmc2=1000, mcmcpars=c("Py")))

#m_admb=read_admb("bcb",  mcmc=TRUE, checkterm=FALSE) #this has a bug
m_admb=read_admb("bcb",  checkterm=FALSE)
mcraw=read_psv("bcb")
colnames(mcraw)=names(coef(m_admb))
mmc=as.mcmc(mcraw)
densityplot(mmc, asp="fill")
xyplot(mmc)


On 30 Oct 2012, at 12:37 PM, Jeff Laake wrote:

> I'm a newbie at ADMB but have been using R for over a decade. Coming from R my inclination was to integrate R and ADMB and I found the R2admb package that Ben Bolker wrote. That package makes it quite easy to use R in constructing TPL files and drive model development from R rather than editing TPL in an IDE or text editor. In particular, I'm using model.matrix in R to create design matrices that are input as DATA into ADMB. This means a basic TPL file can be used without modification to run any number of models directly from R.  I mentioned this to a colleague who said that his biggest complaint about ADMB was it's lack of tools such as model.matrix.  When I showed him my approach he suggested that I post a message to the user list as others may be interested as well. The following link https://github.com/downloads/jlaake/R2admb/Intro_to_r2admb.pdf  will take you to a pdf that shows a couple of examples. The first shows how to extend simple.tpl to fit any model and the second more useful example fits detection curves to line transect data. The code for these examples is at https://github.com/jlaake/R2admb/tree/master/Intro%20to%20R2admb
> 
> I'd appreciate getting any comments about its usefulness (or not) and my admb programming which I'm still learning, I believe that integration of admb into R (as in glmmADMB) will help make ADMB more mainstream in ecology and other fields.
> 
> regards --jeff laake
> _______________________________________________
> Users mailing list
> Users at admb-project.org
> http://lists.admb-project.org/mailman/listinfo/users

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.admb-project.org/pipermail/users/attachments/20121030/42c56114/attachment.html>


More information about the Users mailing list