Questions tagged [stan]

Stan is open source software for Markov chain Monte Carlo sampling, often used for multilevel Bayesian modeling.

Stan is an open-source package for obtaining Bayesian inference using the No-U-Turn sampler, a variant of Hamiltonian Monte Carlo. The Stan webpage describes the program as follows:

Stan® is a state-of-the-art platform for statistical modeling and high-performance statistical computation. Thousands of users rely on Stan for statistical modeling, data analysis, and prediction in the social, biological, and physical sciences, engineering, and business.

Users specify log density functions in Stan’s probabilistic programming language and get:

  • full Bayesian statistical inference with MCMC sampling (NUTS, HMC)
  • approximate Bayesian inference with variational inference (ADVI)
  • penalized maximum likelihood estimation with optimization (L-BFGS)

Stan’s math library provides differentiable probability functions & linear algebra (C++ autodiff). Additional R packages provide expression-based linear modeling, posterior visualization, and leave-one-out cross-validation.

Stan is developed by statistician Andrew Gelman and a team of developers, and is frequently used for sampling from multilevel generalized linear models. It translates a domain-specific language for model specification to C++ code, which employs automatic differentiation to obtain the gradient information needed by the No-U-Turn sampler.

Interfaces to the Stan library and algorithms are available for

In addition, RStanArm is a higher-level interface which provides an R formula interface for Bayesian regression modeling.

Further information can be found at:

The users are recommended that they read the followings:

424 questions
395
votes
1 answer

Representing Parametric Survival Model in 'Counting Process' form in JAGS

I'm trying to build a survival model in JAGS that allows for time-varying covariates. I'd like it to be a parametric model — for example, assuming survival follows the Weibull distribution (but I'd like to allow the hazard to vary, so exponential is…
jwdink
  • 4,824
  • 5
  • 18
  • 20
36
votes
2 answers

Stan. Using target += syntax

I'm starting to learn Stan. Could anyone explain when and how to use syntax such as... ? target += instead of just: y ~ normal(mu, sigma) For example in Stan manual you can find the following example. model { real ps[K]; // temp for log component…
skan
  • 7,423
  • 14
  • 59
  • 96
18
votes
2 answers

How to represent a categorical predictor rstan?

What is the proper way to format a categorical predictor to use in STAN? I cannot seem to input a categorical predictor as a normal factor variable, so what is the quickest way to transform a normal categorical variable such that Stan can accept…
goldisfine
  • 4,742
  • 11
  • 59
  • 83
16
votes
2 answers

how to control output from fbprophet?

I would like to be able to suppress some output coming from fbprophet while fitting a forecasting model. This output ("Initial log joint probability...", "Optimization terminated normally:", "Convergence detected:...", etc.) is apparently coming…
ryszard
  • 379
  • 1
  • 2
  • 12
12
votes
2 answers

Not able to install rstanarm on Ubuntu 18.04 LTS

I'm not able to install rstanarm on R 3.5.3 running on Ubuntu 18.04 LTS. I used the following commands: install.packages("rstanarm") and devtools::install_github("stan-dev/rstanarm", build_vignettes = FALSE) and both throws the following…
MYaseen208
  • 22,666
  • 37
  • 165
  • 309
12
votes
2 answers

Exceeded maximum number of DLLs in R

I am using RStan to sample from a large number of Gaussian Processes (GPs), i.e., using the function stan(). For every GP that I fit, another DLL gets loaded, as can be seen by running the R command getLoadedDLLs() The problem I'm running into is…
Doug Jackson
  • 131
  • 2
  • 7
11
votes
1 answer

Suppress running messages from RStan in Rmarkdown HTML output

The following are my r code. ```{r message=FALSE, warning=FALSE, cache=0,eval=TRUE, error=FALSE} stan_m1 <- rethinking::map2stan( alist( y ~ dbinom(n, p), logit(p) <- alpha + bP*P + bA*A + bV*V, alpha ~ dnorm(0, 10), bP ~ dnorm(0,…
score324
  • 687
  • 10
  • 18
10
votes
1 answer

How do I get standard errors of maximum-likelihood estimates in STAN?

I am using maximum-likelihood optimization in Stan, but unfortunately the optimizing() function doesn't report standard errors: > MLb4c <- optimizing(get_stanmodel(fitb4c), data = win.data, init = inits) STAN OPTIMIZATION COMMAND (LBFGS) init =…
Tomas
  • 57,621
  • 49
  • 238
  • 373
10
votes
5 answers

Will RStan run on a supercomputer?

Stan is a new Bayesian analysis software by Gelman et al. RStan is, I am guessing, a way to call Stan from within R. Will Stan / RStan run on a supercomputer with a Linux operating system, and if so can it take advantage of the super-computer's…
Mark Miller
  • 12,483
  • 23
  • 78
  • 132
9
votes
2 answers

How to use stan in rmarkdown

I would like to get the estimated coefficients of a model using rstan in an rnotebook I have the following stan chunk: ```{stan output.var="rats"} data { int N; int T; real x[T]; real y[N,T]; real xbar; } parameters { …
Alex
  • 2,603
  • 4
  • 40
  • 73
9
votes
1 answer

posterior predictive distribution from brms (logistic regression)

I'm new to both stan and brms, and having trouble extracting posterior predictive distributions. Let's say I have a simple logistic regression fit = brm(y ~ x, family="bernoulli", data=df.training) where y is binary and x continuous. For test data…
funklute
  • 581
  • 4
  • 21
8
votes
0 answers

How to use stans integrate_ode x inputs?

Recently stan has added the integrate_ode method. Unfortunately the only documentation I can find is the stan reference manual (p.191ff). I have a model that would require some driving signal. As I understand the parameter x_r and x_i are supposed…
bdecaf
  • 4,652
  • 23
  • 44
7
votes
3 answers

Library not loaded: @rpath/libtbb.dylib in Prophet / Python

I'm on a Mac X1, Monterey. I've installed prophet and run into this issue when trying to fit a model. RuntimeError: Error during optimization: console log output: dyld[90668]: Library not loaded: @rpath/libtbb.dylib Referenced from:…
cloud36
  • 1,026
  • 6
  • 21
  • 35
7
votes
1 answer

How to extract stan code from rstanarm object

Is there a possibility to extract the stan code used for the MCMC sampling in rstanarm? I would like to compare my own parametrisation of a model and prior choices to the one used in rstanarm.
snaut
  • 2,261
  • 18
  • 37
6
votes
2 answers

a nice pystan trace plot for a stan vector parameter

I am doing a multiple regression in Stan. I want a trace plot of the beta vector parameter for the regressors/design matrix. When I do the following: fit = model.sampling(data=data, iter=2000, chains=4) fig = fit.plot('beta') I get a pretty horrid…
Mark Graph
  • 4,969
  • 6
  • 25
  • 37
1
2 3
28 29