Make normally distributed parameters noncentered in Stan programs.
Project description
decentralise
Make (some) Stan programs noncentered automatically.
Inspired by reading this paper.
Installation
Requires python 3.6+.
Install with pip
:
pip install decentralise
Example
This package provides a command line tool: decentralise
, which is used as follows:
decentralise <inputfile> <outputdestination>
It will take any normally distributed parameters that have variances that are themselves parameters, and reparameterise them to make them noncentered. For example, the canonical eight schools code is:
data {
int<lower=0> J; // number of schools
vector[J] y; // estimated treatment effects
vector<lower=0>[J] sigma; // s.e. of effect estimates
}
parameters {
real mu;
real<lower=0> tau;
vector[J] theta;
}
model {
theta ~ normal(mu, tau);
y ~ normal(theta, sigma);
}
Once decentralise
is applied, this program becomes
data {
int<lower=0> J; // number of schools
vector[J] y; // estimated treatment effects
vector<lower=0>[J] sigma; // s.e. of effect estimates
}
parameters {
real mu;
real<lower=0> tau;
vector[J] theta_std;
}
transformed parameters {
vector[J] theta = mu + theta_std * tau;
}
model {
theta_std ~ normal(0, 1);
y ~ normal(theta, sigma);
}
I wrote this tool for fun, and have not thoroughly tested it. For example, it will fail for any parameters whose sampling statements are not vectorised. e.g.:
x ~ normal(mu, tau);
will work, but
for i in (1:n) {
x[i] ~ normal(mu, tau);
}
will not. There are probably a ton of other cases where it will break that I have not anticipated, as well!
Project details
Release history Release notifications  RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Hashes for decentralise0.0.1py2.py3noneany.whl
Algorithm  Hash digest  

SHA256  fcf3f3bd6d2099d1159eb4691324fdfdcc94ad7ed2da0705ea085666229a86e2 

MD5  082f2bd8bcd5a61f330e4ed944f62e6b 

BLAKE2256  dc8149be6aba7250c93124ba449218974c439e58a69384e249edf942c7790b3f 