This repository contains a docker image for cmdstanr version 0.4.0. It also contains R version 4.1.0
The image is hosted on dockerhub here. Therefore, with docker already installed,you can pull the image to your local machine using the following command:
docker pull nathanielhaines/cmdstanr
Once the image is installed, you can open a bash terminal using the following command:
docker run -it nathanielhaines/cmdstanr
From the terminal, you can run the following example code to see cmdstanr
in action:
Rscript cmdstanr-example.R
This will run the following R code:
# Load cmdstanr
library(cmdstanr)
# Get the compiled stan file for this example
file <- file.path(cmdstan_path(), "examples", "bernoulli", "bernoulli.stan")
mod <- cmdstan_model(file)
# Create some fake data and fit the model
data_list <- list(N = 10, y = c(0,1,0,0,0,0,0,0,0,1))
fit <- mod$sample(
data = data_list,
seed = 123,
chains = 4,
parallel_chains = 4,
refresh = 500
)
# Summarize the results
fit$summary()