Hi! I’m a beginner at Stan and Rstudio, and I’d like to run cmdstan in Rstudio. I’ ve successfully run the example model in this page, by using:
file <- file.path(cmdstan_path(), "examples", "bernoulli", "bernoulli.stan")
mod <- cmdstan_model(file)
However, when I turn to my dataset following Claassen(2019) tutorial page, I couldn’t even fetch the model:
# compile model
stan.mod = cmdstan_model('stan.mod6.7.stan')
Before using the model, I’ve successfully downloaded cmdstan by:
install.packages("cmdstanr", repos = c('https://stan-dev.r-universe.dev', getOption("repos")))
install_cmdstan(cores = 2, overwrite = TRUE)
library(cmdstanr)
And I’ve also tried the following, which didn’t help, either:
# install.packages("remotes")
remotes::install_github("stan-dev/cmdstanr")
It seems I didn’t find the exact folder where the “.stan” is saved, or probably it may take some extra steps to download “stan.mod6.7.stan” ?
I’d appreciate a lot if someone has similar experience could provide any valuable instructions!!!
Hi Anchu, you need to download the model file that the tutorial is using. In the ‘Setting things up in R’ section of the tutorial that you linked, there is a link for downloading the stan model
Thanks for your kind reply! But could you please further clarify where should I download the stan model? For your information, it seems I’ve tried my best to follow the tutorial instructions including :
## Installing the R package
# we recommend running this in a fresh R session or restarting your current session
install.packages("cmdstanr", repos = c('https://stan-dev.r-universe.dev', getOption("repos")))
# install.packages("remotes")
remotes::install_github("stan-dev/cmdstanr")
and
## Installing CmdStan
install_cmdstan(cores = 2, overwrite = TRUE)
# using another version of code instead
install_cmdstan(
dir = NULL,
cores = getOption("mc.cores", 2),
quiet = FALSE,
overwrite = TRUE,
timeout = 1200,
version = NULL,
release_url = NULL,
release_file = NULL,
cpp_options = list(),
check_toolchain = TRUE,
wsl = FALSE
)
# both worked from checking
cmdstan_path()
#[1] "/Users/laurawang/.cmdstan/cmdstan-2.36.0"
cmdstan_version()
#"2.36.0"
While I could exactly find the example model from the following directory:
file <- file.path(cmdstan_path(), "examples", "bernoulli", "bernoulli.stan")
mod <- cmdstan_model(file)
the model “stan.mod6.7.stan” which should be used in my analysis couldn’t be found…
I’m still puzzled about where to download the model and did I miss some essential steps? Or should I change any code above to precisely download “stan.mod6.7.stan” alone? Thank’s for your generous help again!!!
Not in the cmdstanr tutorial, in the modelling tutorial that you’re following. You can see the link in this section (in the last sentence):
Yes I exactly follow this link for R, so that I could load the example file. But I failed to find “stan.mod6.7.stan” everywhere even in the same directory where I found the example model. I’m so sorry for bothering you again and again…
You need to save the Stan file that the tutorial is providing.
Right-click on the link to the stan code and select save:
Done! Thanks a lot for your patient help. Have a good day !