Home

Awesome

MatlabStan

<a href="http://mc-stan.org"> <img src="https://raw.githubusercontent.com/stan-dev/logos/master/logo.png?raw=true" width=100 alt="Stan Logo"/> </a>

A Matlab interface to Stan, a package for Bayesian inference.

For more information on Stan and its modeling language, see the Stan User's Guide and Reference Manual at http://mc-stan.org/.

Installation

Details can be found in the Getting started page of the wiki.

Example

The following is the classic 'eight schools' example from Section 5.5 of Gelman et al (2003). The output can be compared to that obtained using the Rstan and Pystan interfaces.

schools_code = {
   'data {'
   '    int<lower=0> J;         // number of schools '
   '    real y[J];              // estimated treatment effects'
   '    real<lower=0> sigma[J]; // s.e. of effect estimates '
   '}'
   'parameters {'
   '    real mu; '
   '    real<lower=0> tau;'
   '    real eta[J];'
   '}'
   'transformed parameters {'
   '    real theta[J];'
   '    for (j in 1:J)'
   '    theta[j] = mu + tau * eta[j];'
   '}'
   'model {'
   '    eta ~ normal(0, 1);'
   '    y ~ normal(theta, sigma);'
   '}'
};
  
schools_dat = struct('J',8,...
                     'y',[28 8 -3 7 -1 1 18 12],...
                     'sigma',[15 10 16 11 9 11 10 18]);

fit = stan('model_code',schools_code,'data',schools_dat);

print(fit);

eta = fit.extract('permuted',true).eta;
mean(eta)

A collection of Matlab-specific examples is available in the wiki.

Need help?

You may be able to find a solution in the wiki. Otherwise, open an issue.

Contributions

MatlabStan Copyright (c) 2017 Brian Lau brian.lau@upmc.fr, BSD-3

PSIS package Copyright (c) 2015 Aki Vehtari, GPL-3

Please feel free to fork and contribute!