Created
January 18, 2016 20:54
-
-
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
@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