Saturday, March 16, 2013

Save compilation time with RStan


It seems RStan compiles the program every time the "stan_code = " option in "stan" command was invoked. The best way to avoid this is to do it once:

fit1 <- stan(model_code = "stan.model," chains = 1, data = data)

Then call it using the "fit" option:

fit2 <- stan(fit="fit1," data=data, iter = 10000)

Or do it in parallel way:

library(parallel)
sflist1 <- 
  mclapply(1:4, mc.cores = 8, 
           function(i) stan(fit = fit1, chains = 1, chain_id = i, refresh = -1))
fit3 <- sflist2stanfit(sflist1)

No comments:

Counter