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
6
votes
0 answers

Stan_glmer object assignment error

After waiting a week for three MC chains to run, the object was not saved, giving the error "Error: is.atomic(x) is not TRUE". I have run this code or variants thereof many times, so it is probably not my syntax, but possibly something about the…
6
votes
2 answers

Nested Model in STAN?

Say I want to model a random effect at two levels, i.e. I have two levels of nesting: individuals within a parent group and parent groups within a grandparent group. I know how to write a basic model for a single random effect (below) from examples…
goldisfine
  • 4,742
  • 11
  • 59
  • 83
6
votes
4 answers

How to run a robit model in Stan?

I would like to run a robust logistic regression (robit) in Stan. The model is suggested in Gelman & Hill's "Data Analysis Using Regression and Multilevel Methods" (2006, pp. 124), but I'm not sure how to implement it. I checked Stan's Github…
danilofreire
  • 503
  • 1
  • 5
  • 18
6
votes
3 answers

Defining new functions and distributions in the BUGS/JAGS/STAN language

I am very new statistical analysis world and have taken a recent interest in the BUGS/JAGS/STAN modelling language. Something which really surprises me is that I haven't seen any examples of new functions or distributions being defined to avoid code…
jacky
5
votes
1 answer

How to input matrix data into brms formula?

I am trying to input matrix data into the brm() function to run a signal regression. brm is from the brms package, which provides an interface to fit Bayesian models using Stan. Signal regression is when you model one covariate using another within…
Xia Zhu
  • 53
  • 4
5
votes
2 answers

Sampling from prior without running a separate model

I want to graph the histograms of parameter estimates from a stan model against the priors for those parameters. I have tried doing this by running a model in stan, graphing it with ggplot2, then overlaying an approximation of the prior distribution…
llewmills
  • 2,959
  • 3
  • 31
  • 58
5
votes
2 answers

Changing y axis text on mcmc_areas() plot from bayesplot R package

I am having some trouble altering the y-axis values in graphs produced by the mcmc_areas function. My goal is to change the text and update the y-axis values to include greek, subscripted letters. I can do this pretty easily in other graphs that can…
Matt Barstead
  • 235
  • 1
  • 8
5
votes
2 answers

linear model diagnostics for Bayesian models using rstan

I'm looking for an efficient method to identify data points that have an outsize effect on the parameters of a linear model. This is straight-forward with ordinary linear models, but I'm not sure how to do it with Bayesian linear models. Here's one…
Ben
  • 41,615
  • 18
  • 132
  • 227
5
votes
1 answer

MC-Stan on Spark?

I hope to use MC-Stan on Spark, but it seems there is no related page searched by Google. I wonder if this approach is even possible on Spark, therefore I would appreciate if someone let me know. Moreover, I also wonder what is the widely-used…
Kim
  • 1,768
  • 2
  • 14
  • 24
5
votes
3 answers

Mixed Pareto and Normal Stan model not working

I'm trying to learn Stan via rstan (since I'm familiar with R). I've tried running a simple mixed Pareto and Normal model. It compiles fine (as far as I can tell), but it fails to sample, giving me the error: "Initialization between (-2, 2) failed…
ASGR
  • 86
  • 3
5
votes
2 answers

How to obtain the full marginal distribution of a parameter in stan

when starting a standard example from the stan webpage like the following: schools_code <- ' data { int J; // number of schools real y[J]; // estimated treatment effects real sigma[J]; // s.e. of effect estimates } …
Seb
  • 5,417
  • 7
  • 31
  • 50
4
votes
1 answer

Cannot get install of brms or rstan to compile

I have been trying to get brms/rstan to work on my system with limited luck. I have R 4.2 and am using R studio. I originally started doing this in R, because I couldn't get any Bayes packages to work in Python and I (it seems incorrectly) thought…
Beth
  • 41
  • 2
4
votes
2 answers

Need to fix Stan code for the generalized pareto distribution to take in real arguments rather than vectors

I am using the functions defined here: Extreme value analysis and user defined probability functions in Stan for modeling the data with a generalized pareto distribution, but my problem is that my model is in a for-loop and expects three real valued…
John Smith
  • 133
  • 8
4
votes
1 answer

brms: how do I set prior on categorical variable?

I am building a binomial regression model using 2 categorical variables. This is from an example in the book, Statistical rethinking. In the book, while using the rethinking package, we can set priors on each categorical variable as shown…
Srivatsa Srinath
  • 177
  • 2
  • 10
4
votes
1 answer

Matrix with simplex columns in stan

Is there a way to construct a matrix with simplex columns in Stan? The model I want to construct is similar to the following, where I model counts as dirichlet-multinomial: data { int g; int c; int counts[g, c]; } parameters { …
alan ocallaghan
  • 3,116
  • 17
  • 37
1
2
3
28 29