Skip to content

Instantly share code, notes, and snippets.

@kagaya
Created January 30, 2019 11:40
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kagaya/dea9bb9bb1dbe946497c814205801f86 to your computer and use it in GitHub Desktop.
Save kagaya/dea9bb9bb1dbe946497c814205801f86 to your computer and use it in GitHub Desktop.
functions {
vector my_student_t_rng(int N, real nu, real mu, real sigma){
vector[N] Y;
for (n in 1:N){
Y[n] = student_t_rng(nu, mu, sigma);
}
return(Y);
}
vector my_ZIP_rng(int N, real q, real lambda){
vector[N] Y;
int choice;
for (n in 1:N){
choice = bernoulli_rng(q);
if (choice == 0){
Y[n] = 0;
} else {
Y[n] = poisson_rng(lambda);
}
}
return(Y);
}
vector my_gamma_rng(int N, real shape, real scale){
vector[N] Y;
for (n in 1:N){
Y[n] = gamma_rng(shape, shape/scale);
}
return(Y);
}
vector my_normal_rng(int N, real mu, real sigma){
vector[N] Y;
for (n in 1:N){
Y[n] = normal_rng(mu, sigma);
}
return(Y);
}
vector my_poisson_rng(int N, real lambda){
vector[N] Y;
for (n in 1:N){
Y[n] = poisson_rng(lambda);
}
return(Y);
}
vector my_categorical_logit_rng(int N, vector mu){
vector[N] Y;
for (n in 1:N){
Y[n] = categorical_logit_rng(mu);
}
return(Y);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment