You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
48 lines
1.3 KiB
Plaintext
48 lines
1.3 KiB
Plaintext
//
|
|
// This Stan program defines a simple model, with a
|
|
// vector of values 'y' modeled as normally distributed
|
|
// with mean 'mu' and standard deviation 'sigma'.
|
|
//
|
|
// Learn more about model development with Stan at:
|
|
//
|
|
// http://mc-stan.org/users/interfaces/rstan.html
|
|
// https://github.com/stan-dev/rstan/wiki/RStan-Getting-Started
|
|
//
|
|
// The input data is a vector 'y' of length 'N'.
|
|
data {
|
|
int<lower=1> D; //Number of parameters
|
|
int<lower=1> N; // Number of observations
|
|
int<lower=1> L; //Number of categories
|
|
int<lower=1, upper=L> ll[N];
|
|
row_vector[D] x[N];
|
|
real mu_m;
|
|
real mu_sd;
|
|
real sigma_shape;
|
|
real sigma_rate;
|
|
}
|
|
generated quantities {
|
|
//preallocate
|
|
real mu_prior[D];
|
|
real sigma_prior[D];
|
|
vector[D] beta_prior[L];
|
|
real p_prior[N]; // what I have priors about
|
|
//sample parameters
|
|
for (d in 1:D) {
|
|
mu_prior[d] = normal_rng(0,1);
|
|
sigma_prior[d] = gamma_rng(2,1);
|
|
}
|
|
for (l in 1:L) {
|
|
for (d in 1:D) {
|
|
beta_prior[l,d] = normal_rng(mu_prior[d],sigma_prior[d]);
|
|
}
|
|
}
|
|
//generate probabilities
|
|
{
|
|
vector[D] b_prior[N];//local var
|
|
for (n in 1:N){
|
|
b_prior[n] = beta_prior[ll[n]];
|
|
p_prior[n] = inv_logit( x[n] * b_prior[n] );
|
|
}
|
|
}
|
|
}
|