Multivariate chkptstanr

The chkptstanr R package allows users to start/stop brms models with the function ‘chkpt_brms’. the function specifies that the model can handle multivariate formulas e.g. mvbrmsformulas - see: R: Checkpoint Sampling: brms

I can’t seem to get a multivariate model working though, receiving the error ‘formula must be of class formula or brmsformula’. See a reproducible example below. Any ideas what’s wrong?

library(chkptstanr)
library(brms)

path ← create_folder(folder_name = “chkpt_folder_m1”)

data_simple ← read.table(
https://paul-buerkner.github.io/data/data_simple.txt”,
header = TRUE
)
head(data_simple)

model_simple ← bf(
mvbind(phen, cofactor) ~ 1 + (1|phylo),
family = gaussian()
)

fit_m1 ← chkpt_brms(
formula = model_simple,
data = data_simple,
path = “chkpt_folder_m1”,
iter_warmup = 1000,
iter_sampling = 1000,
iter_per_chkpt = 250,
)

R V4.2.3
chkptstanr V0.1.1
cmdtandr V0.7.1

The CRAN version of chkptstanr is completely non-functional and and hasn’t been updated in 2 years. I have recently taken up the development from the original creator, and this issue, together with others is fixed here:

If you install the current v0.2.0-alpha release via:

remotes::install_github("venpopov/chkptstanr@v0.2.0")

you should be able to use it with mvbrmsformulas

This is a very recent update, and so be careful when using it. More details on all the latest changes here

4 Likes

That worked a treat - thank you!

2 Likes

If you notice any issues feel free to post here or open an issue on the github repo

hi

probably just a simple mistake

I’m in Linux Mint 21.2 Victoria

I installed as remotes::install_github(“venpopov/chkptstanr@v0.2.0”)

updated all packages during the installation as suggested

cmdstanr version 0.8.1
CmdStan version: 2.35.0

I ran the test as below

library(cmdstanr)
options(mc.cores=2, brms.normalize=TRUE,brms.backend=“cmdstanr”)
library(lme4)
library(chkptstanr)
library(posterior)
library(bayesplot)
library(ggplot2)

fit1 ← chkpt_brms(count ~ zAge + zBase * Trt + (1|patient),
data = epilepsy,
family = poisson(),
iter_adaptation=1000,
iter_warmup=200,
save_warmup=FALSE,
iter_per_chkpt = 200,
path = ‘checkpoints/epilepsy’)

The programme appeared to run and the *.csv outputs are in the path as specified

But fit1 was not created and error messages shown:

Compiling Stan program…
Initial Warmup (Typical Set)
Chkpt: 1 / 6; Iteration: 200 / 1200 (warmup)
Chkpt: 2 / 6; Iteration: 400 / 1200 (sample)
Chkpt: 3 / 6; Iteration: 600 / 1200 (sample)
Chkpt: 4 / 6; Iteration: 800 / 1200 (sample)
Chkpt: 5 / 6; Iteration: 1000 / 1200 (sample)
Chkpt: 6 / 6; Iteration: 1200 / 1200 (sample)
Checkpointing complete
Error in if (max(save_warmup) == 0L) { :
missing value where TRUE/FALSE needed
In addition: Warning messages:
1: In parse_stancsv_comments(comments) : NAs introduced by coercion
2: In parse_stancsv_comments(comments) : NAs introduced by coercion
3: In parse_stancsv_comments(comments) : NAs introduced by coercion
4: In parse_stancsv_comments(comments) : NAs introduced by coercion

Sampling aborted. You can examine the results or continue sampling by rerunning the same code.
Error in if (max(save_warmup) == 0L) { :
missing value where TRUE/FALSE needed
In addition: Warning messages:
1: In parse_stancsv_comments(comments) : NAs introduced by coercion
2: In parse_stancsv_comments(comments) : NAs introduced by coercion
3: In parse_stancsv_comments(comments) : NAs introduced by coercion
4: In parse_stancsv_comments(comments) : NAs introduced by coercion

how can I fix this?

thanks

Greg

the problem was CmdStan 2.35.0
all ok in CmdStan 2.34.1

thanks

Greg