Skip to content

Commit

Permalink
Agregar más diagnósticos y continuar el ejemplo de variables latentes
Browse files Browse the repository at this point in the history
  • Loading branch information
felipegonzalez committed Apr 3, 2024
1 parent 587c623 commit 8c71af7
Show file tree
Hide file tree
Showing 7 changed files with 635 additions and 1 deletion.
520 changes: 519 additions & 1 deletion notas/08-mcmc.qmd

Large diffs are not rendered by default.

12 changes: 12 additions & 0 deletions notas/referencias/book.bib
Original file line number Diff line number Diff line change
Expand Up @@ -462,3 +462,15 @@ @book{PearlWhy
title = {The Book of Why},
year = 2018
}
@book{handbookmc,
added-at = {2015-03-24T17:28:34.000+0100},
author = {Brooks, Steve and Gelman, Andrew and Jones, Galin and Meng, Xiao-Li},
biburl = {https://www.bibsonomy.org/bibtex/22b8d02bec832fa945b62ecf7808614bf/becker},
interhash = {0b127e40d41a970274484b65a7e0744f},
intrahash = {2b8d02bec832fa945b62ecf7808614bf},
keywords = {carlo chain diss handbook inthesis markov mcmc monte},
publisher = {CRC press},
timestamp = {2017-08-04T09:03:42.000+0200},
title = {Handbook of Markov Chain Monte Carlo},
year = 2011
}
16 changes: 16 additions & 0 deletions notas/src/embudo-neal-reparam.stan
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
parameters {
real y;
vector[9] z;
}

transformed parameters {
vector[9] x;

x = exp(y/2) * z;

}

model {
y ~ normal(0, 3);
z ~ std_normal();
}
8 changes: 8 additions & 0 deletions notas/src/embudo-neal.stan
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
parameters {
real y;
vector[9] x;
}
model {
y ~ normal(0, 3);
x ~ normal(0, exp(y/2));
}
1 change: 1 addition & 0 deletions notas/src/vinos-1.stan
Original file line number Diff line number Diff line change
Expand Up @@ -26,3 +26,4 @@ model {
Q ~ std_normal();
sigma ~ exponential(1);
}

37 changes: 37 additions & 0 deletions notas/src/vinos-2.stan
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
data {
int<lower=0> N; //número de calificaciones
int<lower=0> n_vinos; //número de vinos
int<lower=0> n_jueces; //número de jueces
int<lower=0> n_origen; //número de jueces
vector[N] S;
array[N] int juez;
array[N] int vino;
array[N] int origen;
}

parameters {
vector[n_vinos] Q;
vector[n_origen] O;
real <lower=0> sigma;
}

transformed parameters {
vector[N] media_score;
// determinístico dado parámetros
for (i in 1:N){
media_score[i] = Q[vino[i]] + O[origen[i]];
}
}

model {
// partes no determinísticas
S ~ normal(media_score, sigma);
Q ~ std_normal();
O ~ std_normal();
sigma ~ exponential(1);
}

generated quantities {
real dif_origen;
dif_origen = O[1] - O[2];
}
42 changes: 42 additions & 0 deletions notas/src/vinos-3.stan
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
data {
int<lower=0> N; //número de calificaciones
int<lower=0> n_vinos; //número de vinos
int<lower=0> n_jueces; //número de jueces
int<lower=0> n_origen; //número de jueces
vector[N] S;
array[N] int juez;
array[N] int vino;
array[N] int origen;
}

parameters {
vector[n_vinos] Q;
vector[n_origen] O;
vector[n_jueces] H;
vector<lower=0>[n_jueces] D;

real <lower=0> sigma;
}

transformed parameters {
vector[N] media_score;
// determinístico dado parámetros
for (i in 1:N){
media_score[i] = (Q[vino[i]] + O[origen[i]] - H[juez[i]]) * D[juez[i]];
}
}

model {
// partes no determinísticas
S ~ normal(media_score, sigma);
Q ~ std_normal();
O ~ std_normal();
H ~ std_normal();
D ~ std_normal();
sigma ~ exponential(1);
}

generated quantities {
real dif_origen;
dif_origen = O[1] - O[2];
}

0 comments on commit 8c71af7

Please sign in to comment.