Skip to content

Commit

Permalink
Agregar modelos
Browse files Browse the repository at this point in the history
  • Loading branch information
felipegonzalez committed Apr 10, 2024
1 parent d023a87 commit 4054d06
Show file tree
Hide file tree
Showing 3 changed files with 94 additions and 0 deletions.
30 changes: 30 additions & 0 deletions notas/src/heart-agregado.stan
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
data {
int<lower=0> N;
array[N] int e;
array[N] int y;
}

parameters {
real <lower=0> lambda;
}

transformed parameters {
vector[N] media_hospital;
// lambda es por cada 1000 expuestos:
for (i in 1:N){
media_hospital[i] = lambda * e[i] / 1000;
}
}

model {
// partes no determinísticas
y ~ poisson(media_hospital);
lambda ~ exponential(1);
}

generated quantities {
array[N] int y_sim;
for (i in 1:N){
y_sim[i] = poisson_rng(media_hospital[i]);
}
}
30 changes: 30 additions & 0 deletions notas/src/heart-individual.stan
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
data {
int<lower=0> N;
array[N] int e;
array[N] int y;
}

parameters {
vector<lower=0>[N] lambda;
}

transformed parameters {
vector[N] media_hospital;
// lambda es por cada 1000 expuestos:
for (i in 1:N){
media_hospital[i] = lambda[i] * e[i] / 1000;
}
}

model {
// partes no determinísticas
y ~ poisson(media_hospital);
lambda ~ exponential(1);
}

generated quantities {
array[N] int y_sim;
for (i in 1:N){
y_sim[i] = poisson_rng(media_hospital[i]);
}
}
34 changes: 34 additions & 0 deletions notas/src/heart-jerarquico.stan
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
data {
int<lower=0> N;
array[N] int e;
array[N] int y;
}

parameters {
vector<lower=0>[N] lambda;
real<lower=0> alpha;
real<lower=0> mu;
}

transformed parameters {
vector[N] media_hospital;
// lambda es por cada 1000 expuestos:
for (i in 1:N){
media_hospital[i] = lambda[i] * e[i] /1000;
}
}

model {
// partes no determinísticas
y ~ poisson(media_hospital);
lambda ~ gamma(alpha, alpha / mu);
mu ~ exponential(1);
alpha ~ exponential(1);
}

generated quantities {
array[N] int y_sim;
for (i in 1:N){
y_sim[i] = poisson_rng(media_hospital[i]);
}
}

0 comments on commit 4054d06

Please sign in to comment.