Script Draft for Intro Stan Channel on YouTube

I just ran a 100K standard normal model on my 2012 Mac Pro notebook and it took:

> fit <- sampling(model, data = list(D = 100000), chains = 1)

SAMPLING FOR MODEL 'norm' NOW (CHAIN 1).
Chain 1: 
Chain 1: Gradient evaluation took 0.002456 seconds
Chain 1: 1000 transitions using 10 leapfrog steps per transition would take 24.56 seconds.
Chain 1: Adjust your expectations accordingly!
Chain 1: 
Chain 1: 
Chain 1: Iteration:    1 / 2000 [  0%]  (Warmup)
Chain 1: Iteration:  200 / 2000 [ 10%]  (Warmup)
Chain 1: Iteration:  400 / 2000 [ 20%]  (Warmup)
Chain 1: Iteration:  600 / 2000 [ 30%]  (Warmup)
Chain 1: Iteration:  800 / 2000 [ 40%]  (Warmup)
Chain 1: Iteration: 1000 / 2000 [ 50%]  (Warmup)
Chain 1: Iteration: 1001 / 2000 [ 50%]  (Sampling)
Chain 1: Iteration: 1200 / 2000 [ 60%]  (Sampling)
Chain 1: Iteration: 1400 / 2000 [ 70%]  (Sampling)
Chain 1: Iteration: 1600 / 2000 [ 80%]  (Sampling)
Chain 1: Iteration: 1800 / 2000 [ 90%]  (Sampling)
Chain 1: Iteration: 2000 / 2000 [100%]  (Sampling)
Chain 1: 
Chain 1:  Elapsed Time: 489.771 seconds (Warm-up)
Chain 1:                365.287 seconds (Sampling)
Chain 1:                855.058 seconds (Total)

That’s 14 minutes to complete sampling. So if you ran four chains one after the other, it’d be about an hour. It’d be faster with a faster CPU and faster memory. I can run four chains in parallel and get this all done in 15 minutes, even on my ancient notebook (assuming I don’t want to do anything else on it).

I’m still waiting for it to return because RStan does a lot of extraneous work creating a stanfit object compared to CmdStan just saving the draws!

Daniel Lee and I fit a hierarchical Bradley-Terry model for baseball batting matchups over all time (15K parameters, 10M observations) in about two days on a regular computer in our office many years ago. I don’t know how long 100K parameters and 100M observations would’ve taken but presumably longer than our patience would’ve lasted. It can be hard to speed this up with map_rect because the computation is so simple per data point and parameter.