Skip to content

Instantly share code, notes, and snippets.

@rasmusab
Created January 18, 2016 20:54
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 4 You must be signed in to fork a gist
  • Save rasmusab/744410db9cf85ecb85e1 to your computer and use it in GitHub Desktop.
Save rasmusab/744410db9cf85ecb85e1 to your computer and use it in GitHub Desktop.
A short script you can use to test if rstan is installed and working correctly.
# Prior to the tutorial make sure that the script below runs without error on your R installation.
# What you need is a working installation of Stan: http://mc-stan.org/ .
# For installation instructions, see here:
# https://github.com/stan-dev/rstan/wiki/RStan-Getting-Started
# After installation you should be able to run this script which should output
# some summary statistics and some pretty plots, :)
# Generating some fake data
set.seed(123)
y <- rbinom(30, size = 1, prob = 0.2016)
# Fitting a simple binomial model using Stan
library(rstan)
model_string <- "
data {
int n;
int y[n];
}
parameters {
real<lower=0, upper=1> theta;
}
model {
y ~ bernoulli(theta);
}"
stan_samples <- stan(model_code = model_string, data = list(y = y, n = length(y)) )
stan_samples
traceplot(stan_samples)
plot(stan_samples)
@barracuda156
Copy link

@rasmusab I am getting this error:

Loading required package: StanHeaders
Loading required package: ggplot2
rstan (Version 2.21.2, GitRev: 2e1f913d3ca3)
For execution on a local, multicore CPU with excess RAM we recommend calling
options(mc.cores = parallel::detectCores()).
To avoid recompilation of unchanged Stan programs, we recommend calling
rstan_options(auto_write = TRUE)
Warning message:
In file(con, "r") :
cannot open file '/var/db/timezone/zoneinfo/+VERSION': No such file or directory
Error in dyn.load(libLFile) :
unable to load shared object '/var/folders/rD/rDeCM6SDHv8daLCecrRmrU+++TI/-Tmp-//RtmpaiK5vN/file3dce3fe08cef.so':
dlopen(/var/folders/rD/rDeCM6SDHv8daLCecrRmrU+++TI/-Tmp-//RtmpaiK5vN/file3dce3fe08cef.so, 6): Library not loaded: @rpath/libtbb.dylib
Referenced from: /var/folders/rD/rDeCM6SDHv8daLCecrRmrU+++TI/-Tmp-//RtmpaiK5vN/file3dce3fe08cef.so
Reason: image not found
Calls: stan ... cxxfunctionplus -> -> cxxfunction -> dyn.load
Error in sink(type = "output") : invalid connection
Calls: stan -> stan_model -> cxxfunctionplus -> sink
Execution halted

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment