
Explore probabilistic programming with Stan, a fast open-source language for Bayesian analysis and statistical inference. Learn to build predictive models from regression to logistic regression using Stan’s flexible framework.
Install R and RStudio to start your Bayesian regression journey; this optional setup guides Windows, Mac, and Linux users through downloading, installing, and running their first script.
Explore parametric bayesian inference with Stan by comparing non-bayesian least squares to posterior sampling, modeling height as a normal distribution with mean weight-derived linear function and estimating via posterior means.
Install rstan in RStudio by running the installation line, restarting the R session, loading the library, and preparing your environment for probabilistic programming with Stan.
Compare non-bayesian and bayesian fits using a dataset of 15 women, modeling height as a function of weight with a linear regression, and visualize the fitted relationship.
Define the data for Stan by building a list with predictors X, response Y, and the number of observations N, preparing inputs for Bayesian linear regression in Stan.
Create the STAN file by saving a text file and defining three crucial blocks—data, parameters, and model—for your probabilistic program.
Define the STAN data block by setting the number of observations and declaring Y as the response and X as the predictors, ensuring vector lengths match.
Define the parameters block in Stan for a Bayesian model where height equals alpha times weight plus beta, with sigma as the standard deviation, and enforce sigma to be positive.
Learn how to fill the Stan model block with priors and a likelihood for a linear model, and translate height, a normal distribution with mean and sigma, into Stan syntax.
Run the Stan model by loading the RStan interface, defining data, parameters, and model blocks, and fitting with chosen iterations and warm-ups using four chains to monitor convergence.
Explore probabilistic modeling with Stan by using a transformed data block to form a quadratic mean: intercept plus weight and weight squared, noting dispersion and divergence considerations.
Increase iterations and reduce the step size to achieve convergence in the Stan model with a quadratic parameter. Use trace plots and R-hat diagnostics to verify convergence.
Explore how to define and use generated quantities in Stan to produce replicated data from model fits, assess convergence with R-hat, and diagnose performance across chains.
Learn to replicate data with stan's generated quantities and visualize posterior predictive checks to compare quadratic versus linear models, noting convergence improves with longer iterations and smaller step size.
Learn to perform convergence diagnostics for a Stan model by using extract function from the RStan package to obtain the posterior and plot trace plots for alpha, intercepts, and sigma.
Explore model divergence in bayesian Stan models by examining posterior distributions, convergence diagnostics, and how iterations and tuning affect nonconvergence and recovery of parameters.
Explore convergence diagnosis of Stan models using trace plots across multiple chains, warm-up considerations, and key parameters like alpha and sigma to assess mixing and convergence.
Learn to use shinystan for interactive convergence diagnostics in Bayesian analysis, installing the shinystan package, launching the interactive diagnostics, and interpreting posterior estimates from trace plots and summaries.
Develop intuition for posterior predictive checks by updating priors with evidence, forming posterior predictive distributions, and using these updates to anticipate future observations.
Explore posterior predictive checks in Stan models, using generated quantities and PPC overlay to compare true values with simulated replicates and assess model fit.
Compare bayesian and non-bayesian fits of a linear model in Stan, examine alpha, beta, and sigma, and plot weight versus height to visualize posterior uncertainty.
Visualize uncertainty in a Bayesian model by plotting posterior draws of alpha and beta for height versus weight, illustrating the credible interval and model uncertainty.
Develop a logistic regression model using the Pima Indians diabetes data, inspecting nine variables across 768 observations and checking for missing values in Stan.
Learn probabilistic programming with Stan to build a logistic regression model for diabetes prediction, select features like pregnancy, glucose, and BMI, and interpret intercepts and coefficients.
Create a Stan-ready data list from a 768-observation diabetes dataset, selecting three predictors—pregnancies, glucose, and BMI—and a binary outcome, to feed the Stan model.
Define a data block in Stan by saving a Stan file and specifying data types: integer, real, and vector, with lengths equal to the number of observations and the outcome.
Define the parameters block in Stan to set the intercept and slopes for pregnancy, glucose, and BMI as real numbers. Use Bernoulli distribution for binary outcomes.
Define the model block in Stan for a logistic regression with data on pregnancy, glucose, and BMI, specify the likelihood with a Bernoulli outcome, and discuss priors and convergence checks.
Learn how to execute the Stan model on a diabetes data example, define data and parameters, run iterations with warmups, and assess convergence across four chains via posterior sampling.
Learn to verify model convergence in probabilistic programming by using shinystan diagnostics and trace plots across four chains with warmups to obtain reliable posterior estimates.
Extract posterior estimates from a converged Stan model to obtain the intercept and coefficients for pregnancy, glucose, and body mass index, and interpret the credible intervals for reliable predictions.
Learn to build a predictive Stan model for diabetes with data, model, and generated quantities blocks; produce predicted probabilities of diabetes from pregnancies, glucose, and BMI using Bernoulli logistic regression.
Learn how to generate predictions from a Stan model by converting to a matrix, applying quantize to obtain probabilities, and interpreting posterior convergence.
Explore the classic eight schools data with hierarchical models in Stan, comparing non-hierarchical and hierarchical estimates of treatment effects and their standard errors.
Construct a non-hierarchical bayesian model in Stan to analyze fiscal deficits, defining data, parameters, and model blocks, modeling treatment as a normal distribution with known standard errors.
Explore how non-hierarchical models compare to hierarchical approaches in Stan, using the eight schools example to examine convergence and posterior distributions.
Explore hierarchical modeling in Stan through the classical eight schools example, introducing hyper parameters and hyper models to capture group-level variation in bayesian data analysis.
Run a hierarchical multi-level model in Stan, using the eight schools example, defining data and hyperparameters, adjusting iterations for convergence, and inspecting results.
In this course , the probabilistic programming for statistical inference , STAN , within Bayesian framework has been taught with many examples and mini-project styles .
During my graduate studies in applied mathematics , I did not have the resources which teach me how to write the code and how to tune it , it took me such a long journey to teach myself , this then motivated me to create these tutorials for those who want to explore the richness of the Bayesian inference .
This course , in details , explore the following models in STAN :
- Multi_variate Regression Models
- Convergence and Model Tuning
- Logistic Regression Analysis
- Quadratic Predictive Models
- Hierarchical Models
I hope this tutorial helps you to think more Bayesian and act more Bayesian.