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

How to extract tidy draws from brms models (tidybayes) for interaction terms

I ran this model using the brms package: fit<-brm(scoreAMI2~ year2011 + year2012+ year2013+ year2014+ (1|sysid)+ (1|hrr)+ (1|sysid:hrr), data=standata, prior=priors,warmup = 1000, iter = 2000, chains = 4, control = list(adapt_delta = 0.95)) I am…
micaaron
  • 41
  • 1
4
votes
1 answer

recompiling to avoid crashing R session

How to avoid recompiling? My stan() is recompiling to avoid crashing R session. To validate my model, I want to replicate various models for many data from known distributions. However rstan::stan() always recompile my stan file, so it took a very…
Camford Oxbridge
  • 834
  • 8
  • 21
4
votes
1 answer

In rstan, are initial parameter values that are specified via a list applied on the constrained support or the unconstrained support?

The help file for rstan::stan has the following to say about the init argument: init="random" (default): Let Stan generate random initial values for all parameters. The seed of the random number generator used by Stan can be specified via…
Cameron Bieganek
  • 7,208
  • 1
  • 23
  • 40
4
votes
0 answers

Translating WinBUGS models to rstan

I have WinBUGS models below which I need to use in R. However because I am not familiar with WinBUGS and for consistency with other parts of the analysis, I would appreciate any help to convert them to rstan. Here are the models and data (full…
Krantz
  • 1,424
  • 1
  • 12
  • 31
4
votes
1 answer

Optimizing Gaussian Process in Stan/rstan

I have recently encountered Gaussian process models and happen to think that they may be the solution to a problem I have been working on in my lab. I have an open and related question on Cross Validated, but I wanted to separate out my…
Matt Barstead
  • 235
  • 1
  • 8
4
votes
1 answer

How to report with APA style a Bayesian Linear (Mixed) Models using rstanarm?

I'm currently struggling with how to report, following APA-6 recommendations, the output of rstanarm::stan_lmer(). First, I'll fit a mixed model within the frequentist approach, then will try to do the same using the bayesian framework. Here's the…
Dominique Makowski
  • 1,511
  • 1
  • 13
  • 30
4
votes
2 answers

Using JAGS or STAN when an observed node is the max of latent nodes

I have the following latent variable model: Person j has two latent variables, Xj1 and Xj2. The only thing we get to observe is their maximum, Yj = max(Xj1, Xj2). The latent variables are bivariate normal; they each have mean mu, variance sigma2,…
Dagremu
  • 325
  • 1
  • 7
4
votes
1 answer

Probit regression with data augmentation in stan

I am attempting to do a probit model with data augmentation using stan. This is where we have outcomes y either 0/1 that tell us the sign of the latent variable ystar. This is what I have so far, but I'm not sure how to add information in the model…
Alex
  • 1,997
  • 1
  • 15
  • 32
4
votes
1 answer

Embedding Stan in C++ application

I wanted to know whether it is possible to incorporate Stan in another C++ application. Since Stan is also written in C++, there should be a way. Currently, I am using RInside to achieve this but then you have all this data transferring which is…
beginneR
  • 3,207
  • 5
  • 30
  • 52
4
votes
1 answer

How to monitor local variables in STAN?

I'm currently trying to port some JAGS models to STAN. I get some strange errors "stan::prob::exponential_log(N4stan5agrad3varE): Random variable is nan:0, but must not be nan!" and to debug those I would like to know the the values of some local…
4
votes
0 answers

Supplying seed to Stan doesn't guarantee the same chains

I was trying to compare the run time of two very much equivalent but slightly different models. But the chains will always take very different time based on the random numbers sampled. So I tried to fix this supplying the same seed parameter to…
Tomas
  • 57,621
  • 49
  • 238
  • 373
3
votes
0 answers

Finding the amount of memory allocated for the environment output by cmdstanr sampling

Assigning the output of a call to the sample() method of a compiled model from the cmdstanr package produces an "environment" in my global environment rather than a model object. Is there some way to see how much memory this environment is…
socialscientist
  • 3,759
  • 5
  • 23
  • 58
3
votes
2 answers

Slurm Job is Running out of Memory [RAM?] but memory limit not reached

I run simulations on a hpc-cluster which are quite memory demanding. I'm fitting cmdstan models with 3000 iterations for different conditions(200 unique combinations). To do this, I'm using the simDesign package in R. The simulations run perfectly…
3
votes
0 answers

brms hurdle_lognormal model: is this a correct way to convert posterior values into y-variable units and hurdle values into probabilities?

I have a zero-inflated y-variable. Could you please confirm that my solutions for converting brms hurdle lognormal posterior values into meaningful estimates as y-variable units (lognormal part) or zero probabilities (hurdle part). Model model =…
st4co4
  • 445
  • 3
  • 10
3
votes
1 answer

Warning message: 'c:/Rtools/mingw_/bin/g++' not found

When I try to use RStan (which needs RTools to run) in R, I get the following warning message: Warning message: In system(paste(CXX, ARGS), ignore.stdout = TRUE, ignore.stderr = TRUE) : 'c:/Rtools/mingw_/bin/g++' not found But, when I check in…
Anthony
  • 377
  • 2
  • 6
  • 13
1 2
3
28 29