Merge pull request #2783 from jrnold/add-stan-extension

Add stan extension
This commit is contained in:
Arfon Smith
2016-01-02 21:32:14 -05:00
7 changed files with 85 additions and 0 deletions

3
.gitmodules vendored
View File

@@ -701,3 +701,6 @@
[submodule "vendor/grammars/language-renpy"]
path = vendor/grammars/language-renpy
url = https://github.com/williamd1k0/language-renpy.git
[submodule "vendor/grammars/atom-language-stan"]
path = vendor/grammars/atom-language-stan
url = git@github.com:jrnold/atom-language-stan.git

View File

@@ -187,6 +187,8 @@ vendor/grammars/atom-fsharp/:
- source.fsharp.fsx
vendor/grammars/atom-language-purescript/:
- source.purescript
vendor/grammars/atom-language-stan/:
- source.stan
vendor/grammars/atom-salt:
- source.python.salt
- source.yaml.salt

View File

@@ -3355,6 +3355,14 @@ Squirrel:
tm_scope: source.c++
ace_mode: c_cpp
Stan:
type: programming
color: "#b2011d"
extensions:
- .stan
ace_mode: text
tm_scope: source.stan
Standard ML:
type: programming
color: "#dc566d"

View File

@@ -0,0 +1,14 @@
data {
int<lower=0> N;
vector[N] incumbency_88;
vector[N] vote_86;
vector[N] vote_88;
}
parameters {
vector[3] beta;
real<lower=0> sigma;
}
model {
vote_88 ~ normal(beta[1] + beta[2] * vote_86
+ beta[3] * incumbency_88,sigma);
}

31
samples/Stan/dogs.stan Normal file
View File

@@ -0,0 +1,31 @@
data {
int<lower=0> n_dogs;
int<lower=0> n_trials;
int<lower=0,upper=1> y[n_dogs,n_trials];
}
parameters {
vector[3] beta;
}
transformed parameters {
matrix[n_dogs,n_trials] n_avoid;
matrix[n_dogs,n_trials] n_shock;
matrix[n_dogs,n_trials] p;
for (j in 1:n_dogs) {
n_avoid[j,1] <- 0;
n_shock[j,1] <- 0;
for (t in 2:n_trials) {
n_avoid[j,t] <- n_avoid[j,t-1] + 1 - y[j,t-1];
n_shock[j,t] <- n_shock[j,t-1] + y[j,t-1];
}
for (t in 1:n_trials)
p[j,t] <- beta[1] + beta[2] * n_avoid[j,t] + beta[3] * n_shock[j,t];
}
}
model {
beta ~ normal(0, 100);
for (i in 1:n_dogs) {
for (j in 1:n_trials)
y[i,j] ~ bernoulli_logit(p[i,j]);
}
}

26
samples/Stan/schools.stan Normal file
View File

@@ -0,0 +1,26 @@
data {
int<lower=0> N;
vector[N] y;
vector[N] sigma_y;
}
parameters {
vector[N] eta;
real mu_theta;
real<lower=0,upper=100> sigma_eta;
real xi;
}
transformed parameters {
real<lower=0> sigma_theta;
vector[N] theta;
theta <- mu_theta + xi * eta;
sigma_theta <- fabs(xi) / sigma_eta;
}
model {
mu_theta ~ normal(0, 100);
sigma_eta ~ inv_gamma(1, 1); //prior distribution can be changed to uniform
eta ~ normal(0, sigma_eta);
xi ~ normal(0, 5);
y ~ normal(theta,sigma_y);
}