Skip to content

Matlab interface to Stan, a package for Bayesian inference

License

Notifications You must be signed in to change notification settings

mboedigh/MatlabStan

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Stan Logo A Matlab interface to [Stan](http://mc-stan.org/), 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)

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

Contributions

MatlabStan Copyright (c) 2015 Brian Lau [email protected], BSD-3

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

Please feel free to fork and contribute!

About

Matlab interface to Stan, a package for Bayesian inference

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • MATLAB 100.0%