2. I checked the inits behavior and it seems my guess was wrong:
blavaan can't get inits from a fitted blavaan model because while it
doesn't crash when I try, the PSRFs don't improve noticeably and it
spits out a lot of warnings, 50+ warnings of the form:
...
3: In if (inits != "jags") { ... :
the condition has length > 1 and only the first element will be used
Calls: system.time ... tryCatchList -> tryCatchOne ->
doTryCatch -> lav2jags
4: In if (inits == "prior") { ... :
the condition has length > 1 and only the first element will be used
Calls: system.time ... tryCatchList -> tryCatchOne ->
doTryCatch -> lav2jags -> set_inits
5: In if (inits == "prior") { ... :
the condition has length > 1 and only the first element will be used
Calls: system.time ... tryCatchList -> tryCatchOne ->
doTryCatch -> lav2jags -> set_inits
...
50: In if (inits == "prior") { ... :
the condition has length > 1 and only the first element will be used
Calls: system.time ... tryCatchList -> tryCatchOne ->
doTryCatch -> lav2jags -> set_inits
...
6. The interaction stuff hasn't changed and still leaves me perplexed
whether blavaan is genuinely estimating main+interaction effects or
has some sort of parsing issue.
On Mon, Jun 27, 2016 at 11:01 PM, Ed Merkle <
ecme...@gmail.com> wrote:
> 1. General-purpose samplers like JAGS or BUGS will always be somewhat slow,
> sacrificing speed for flexibility. However, run times on the order of hours
> do seem extreme. I wonder whether you are running into memory issues
> associated with having lots of missing data (the missing data are generally
> sampled as extra parameters, and this is handled behind the scenes).
I have been benchmarking this over the past week; the missingness
varies heavily by time while the MCMC should scale with the data size,
so I've been comparing timings by adding in years/_n_ to look for
non-linear changes in runtime. There looks to be *some* but not a huge
amount, and there's not more than a 50% slowdown.
Since I have Mnemosyne data back to ~2009 (2009-05-31), sleep back to
2010 (2010-12-26) MP back to ~2012 (2012-02-16), but the Kongin only
goes back to 2014 and the Netatmo only back to May 2016, there is
enormous missingness and some variables are estimated much more
precisely than others, and may not be worth causing the slowdown in
the MCMC.
So let's drop everything after the current day and before 2016 and see
how much that speeds up 100k samples (it may even make it possible to
turn back on posterior predictive checks, which would allow model
comparison through `BF()`).
Then we can gradually extend data coverage back to see how computation
time scales with years.
Just this year:
nightShort <- night[night$Date>=as.Date("2016-01-01") &
night$Date<Sys.Date(),]
nrow(night); nrow(nightShort); nrow(nightShort) / nrow(night) *
15.6 ## ~7% of the data by _n_/rows, so should take ~1.04h if
computation time scales linearly with the rows
# [1] 2678
# [1] 179
# [1] 1.060194175
system.time(s5 <- bsem(model3, test="none", n.chains=6,
jagcontrol=list(method="rjparallel"), sample=100000, fixed.x=FALSE,
data=scale(nightShort[-1]))); summary(s5)
1841 seconds or ~0.51 hours, half than expected from just _n_=179.
Adding another year of data, 2015:
nightShort2015 <- night[night$Date>=as.Date("2015-01-01") &
night$Date<Sys.Date(),]
nrow(night); nrow(nightShort2015); nrow(nightShort2015) /
nrow(night); (nrow(nightShort2015) / nrow(night)) * 15.6
# [1] 2678
# [1] 545
# [1] 0.
2035100822
# [1] 3.174757282 ## so expected to run over 3.17h if runtime is
merely proportional to rows, but will probably run less since
missingness still isn't high back in 2015...
system.time(s6 <- bsem(model3, test="none", n.chains=6,
jagcontrol=list(method="rjparallel"), sample=100000, fixed.x=FALSE,
data=scale(nightShort2015[-1]))); summary(s6)
10305 seconds or 2.86h rather than 3.17h - still better but starting
to converge on predicted.
nightShort2014 <- night[night$Date>=as.Date("2014-01-01") &
night$Date<Sys.Date(),]
nrow(night); nrow(nightShort2014); nrow(nightShort2014) /
nrow(night); (nrow(nightShort2014) / nrow(night)) * 15.6
# [1] 2678
# [1] 911
# [1] 0.3401792382
# [1] 5.306796117
system.time(s7 <- bsem(model3, test="none", n.chains=6,
jagcontrol=list(method="rjparallel"), sample=100000, fixed.x=FALSE,
data=scale(nightShort2014[-1]))); summary(s7)
24489 seconds or 6.8h, more than 5.3h - now more than predicted
nightShort2013 <- night[night$Date>=as.Date("2013-01-01") &
night$Date<Sys.Date(),]
nrow(night); nrow(nightShort2013); nrow(nightShort2013) /
nrow(night); (nrow(nightShort2013) / nrow(night)) * 15.6
# [1] 2678
# [1] 1279
# [1] 0.4775952203
# [1] 7.450485437
system.time(s8 <- bsem(model3, test="none", n.chains=6,
jagcontrol=list(method="rjparallel"), sample=100000, fixed.x=FALSE,
data=scale(nightShort2013[-1]))); summary(s8)
26218 seconds or 7.28h - less than predicted.
nightShort2012 <- night[night$Date>=as.Date("2012-01-01") &
night$Date<Sys.Date(),]
nrow(night); nrow(nightShort2012); nrow(nightShort2012) /
nrow(night); (nrow(nightShort2012) / nrow(night)) * 15.6
# [1] 2678
# [1] 1645
# [1] 0.
6142643764
# [1] 9.582524272
system.time(s9 <- bsem(model3, test="none", n.chains=6,
jagcontrol=list(method="rjparallel"), sample=100000, fixed.x=FALSE,
data=scale(nightShort2012[-1]))); summary(s9)
32321s or 8.97h - less than predicted.
nightShort2011 <- night[night$Date>=as.Date("2011-01-01") &
night$Date<Sys.Date(),]
nrow(night); nrow(nightShort2011); nrow(nightShort2011) /
nrow(night); (nrow(nightShort2011) / nrow(night)) * 15.6
# [1] 2678
# [1] 1989
# [1] 0.
7427184466
# [1] 11.58640777
system.time(s10 <- bsem(model3, test="none", n.chains=6,
jagcontrol=list(method="rjparallel"), sample=100000, fixed.x=FALSE,
data=scale(nightShort2011[-1])))
41317s or 11.47h, around predicted.
Presumably going back to 2010 and 2009 would yield similar results
(convergence) but that would take another two days so I'm going to end
benchmarking there.
> 2. The "sample" argument is per chain. So sample=100 with 8 chains gives you
> 800 total samples.
OK. But that doesn't explain the major slowdown I observe with
parallelism on the example model; see my other email.
> 3. In general, I think you will not have much luck with arithmetic in a
> blavaan model call. Behavior should be the same as lavaan here.
It would be nice if the blavaan formula syntax could be made as
flexible as the standard R formula syntax which allows logs, roots,
powers, and the other common transformations. I suppose it's not too
important though.
> 4. Regarding the BF() function, you may get the error if you set
> test="none". I should make this error more informative.
Yes, that seems to be it. I wasn't expecting model comparison to rely
on posterior predictive checks, though.
Actually, how does that work? I've seen PPCs expounded by Gelman as a
way to reject models but it's not one of the Bayesian model comparison
techniques I've read about before like the product-space method; I'd
always seen PPCs described as *not* giving a Bayesian comparison from
which a BF could be extracted, hence the name 'Bayesian p-value'.
--
gwern
http://www.gwern.net