compiler and runiregGibbs (bayesm)

[This article was first published on [the] joint posterior distribution, and kindly contributed to R-bloggers]. (You can report issue about the content on this page here)
Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.

So everyone’s excited about the new R 2.13 release because of the compiler package.
Apparently it is easy to get a 3x speed increase by simply compiling a function.
Doing a lot of the MCMC stuff, I am particularly excited about speed in R. I just compiled a 2000-line file with code from my latest project, but none of the functions would run faster. Apparently I need to break down things a little more and use more subfunctions.

Well, so I tried a much easier example. I took runiregGibbs from the well known bayesm packages (which is a function completely written in R) and compiled it. There’s a visible change, but it’s quite small:

library(compiler)
library(bayesm)
#compile runiregGibbs function
runiregGibbsc=cmpfun(runiregGibbs)
set.seed(66); n=1000; R=10000
X=cbind(rep(1,n),runif(n)); beta=c(1,2); sigsq=.25
y=X%*%beta+rnorm(n,sd=sqrt(sigsq))
Data1=list(y=y,X=X); Mcmc1=list(R=R)
#run code
t.original = system.time(runiregGibbs(Data=Data1,Mcmc=Mcmc1))
t.compiled = system.time(runiregGibbsc(Data=Data1,Mcmc=Mcmc1))
#result
> t.original
User System verstrichen
2.20 0.11 2.30
> t.compiled
User System verstrichen
1.90 0.20 2.11
view raw gistfile1.r hosted with ❤ by GitHub

To leave a comment for the author, please follow the link and comment on their blog: [the] joint posterior distribution.

R-bloggers.com offers daily e-mail updates about R news and tutorials about learning R and many other topics. Click here if you're looking to post or find an R/data-science job.
Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.

Never miss an update!
Subscribe to R-bloggers to receive
e-mails with the latest R posts.
(You will not see this message again.)

Click here to close (This popup will not appear again)