Skip to content

Commit

Permalink
minor update + PIT ecdf
Browse files Browse the repository at this point in the history
  • Loading branch information
avehtari committed Oct 26, 2022
1 parent 73ca8ed commit 1454485
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 13 deletions.
3 changes: 1 addition & 2 deletions demos_ch6/demo6_2.R
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,6 @@ ggplot(data = Tyr) +
color = 'black', binwidth = 1) +
geom_vline(aes(xintercept = x), data = data.frame(x = Ty),
color = 'red') +
labs(x = TeX('Number of changes in \\mathit{y} and \\mathit{y}^{\\mathrm{rep}}'),
labs(x = TeX(r"(Number of changes in $\textit{y}$ and $\textit{y}^{ \textrm{rep}}$)"),
y = '', title = title1) +
scale_y_continuous(breaks=NULL)

2 changes: 1 addition & 1 deletion demos_ch6/demo6_2.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ ggplot(data = Tyr) +
color = 'black', binwidth = 1) +
geom_vline(aes(xintercept = x), data = data.frame(x = Ty),
color = 'red') +
labs(x = TeX('Number of changes in \\mathit{y} and \\mathit{y}^{\\mathrm{rep}}'),
labs(x = TeX(r"(Number of changes in $\textit{y}$ and $\textit{y}^{ \textrm{rep}}$)"),
y = '', title = title1) +
scale_y_continuous(breaks=NULL)
```
Expand Down
26 changes: 21 additions & 5 deletions demos_ch6/demo6_4.R
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@
#' ggplot2 is used for plotting, tidyr for manipulating data frames
#+ setup, message=FALSE, error=FALSE, warning=FALSE
library(ggplot2)
theme_set(theme_minimal())
library(bayesplot)
theme_set(bayesplot::theme_default(base_family = "sans"))
library(tidyr)
library(latex2exp)
library(rprojroot)
Expand All @@ -38,15 +39,23 @@ Ty <- data.frame(x = pt((y - my)/(sqrt(1+1/n)*s), n-1))

#* Plot histogram of PIT values. Ideally histogram should be close to uniform.
title1 <- 'Light speed example
distribution of marginal posterior tail-values'
distribution of predictive distribution tail-values'

ggplot(data = Ty) +
geom_histogram(aes(x = x), fill = 'steelblue',
color = 'black', binwidth = 0.05) +
coord_cartesian(xlim = c(0, 1)) +
labs(x = TeX('\\mathit{p}(\\mathit{y}^{\\mathrm{rep}}_{\\mathit{i}} < \\mathit{y_i} | \\mathit{y})'),
labs(x = TeX(r"($\textit{p}(\textit{y}^{\textrm{rep}}_{\textit{i}} < \textit{y_i} | \textit{y})$)"),
y = '', title = title1) +
scale_y_continuous(breaks=NULL)

#* Plot ECDF of PIT values. Ideally ECDF should be close to diagonal line
ggplot(data=data.frame(x=Ty), aes(x)) +
stat_ecdf(geom = "step", color=4) +
xlim(c(0,1))+
labs(x="Observed PIT values", y="ECDF")+
annotate(geom="segment",x=0,y=0,xend=1,yend=1)

#' Repeat the PIT checking after removing two "outliers"
y <- y[y>0]
#' Sufficient statistics
Expand All @@ -60,11 +69,18 @@ Ty <- data.frame(x = pt((y - my)/(sqrt(1+1/n)*s), n-1))

#' Plot histogram of PIT values. Ideally histogram should be close to uniform.
title1 <- 'Light speed example
distribution of marginal posterior tail-values'
distribution of predictive distribution tail-values'
ggplot(data = Ty) +
geom_histogram(aes(x = x), fill = 'steelblue',
color = 'black', binwidth = 0.05) +
coord_cartesian(xlim = c(0, 1)) +
labs(x = TeX('\\mathit{p}(\\mathit{y}^{\\mathrm{rep}}_{\\mathit{i}} < \\mathit{y_i} | \\mathit{y})'),
labs(x = TeX(r"($\textit{p}(\textit{y}^{\textrm{rep}}_{\textit{i}} < \textit{y_i} | \textit{y})$)"),
y = '', title = title1) +
scale_y_continuous(breaks=NULL)

#* Plot ECDF of PIT values. Ideally ECDF should be close to diagonal line
ggplot(data=data.frame(x=Ty), aes(x)) +
stat_ecdf(geom = "step", color=4) +
xlim(c(0,1))+
labs(x="Observed PIT values", y="ECDF")+
annotate(geom="segment",x=0,y=0,xend=1,yend=1)
26 changes: 21 additions & 5 deletions demos_ch6/demo6_4.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@ ggplot2 is used for plotting, tidyr for manipulating data frames

```{r setup, message=FALSE, error=FALSE, warning=FALSE}
library(ggplot2)
theme_set(theme_minimal())
library(bayesplot)
theme_set(bayesplot::theme_default(base_family = "sans"))
library(tidyr)
library(latex2exp)
library(rprojroot)
Expand Down Expand Up @@ -47,14 +48,22 @@ Ty <- data.frame(x = pt((y - my)/(sqrt(1+1/n)*s), n-1))
#* Plot histogram of PIT values. Ideally histogram should be close to uniform.
title1 <- 'Light speed example
distribution of marginal posterior tail-values'
distribution of predictive distribution tail-values'
ggplot(data = Ty) +
geom_histogram(aes(x = x), fill = 'steelblue',
color = 'black', binwidth = 0.05) +
coord_cartesian(xlim = c(0, 1)) +
labs(x = TeX('\\mathit{p}(\\mathit{y}^{\\mathrm{rep}}_{\\mathit{i}} < \\mathit{y_i} | \\mathit{y})'),
labs(x = TeX(r"($\textit{p}(\textit{y}^{\textrm{rep}}_{\textit{i}} < \textit{y_i} | \textit{y})$)"),
y = '', title = title1) +
scale_y_continuous(breaks=NULL)
#* Plot ECDF of PIT values. Ideally ECDF should be close to diagonal line
ggplot(data=data.frame(x=Ty), aes(x)) +
stat_ecdf(geom = "step", color=4) +
xlim(c(0,1))+
labs(x="Observed PIT values", y="ECDF")+
annotate(geom="segment",x=0,y=0,xend=1,yend=1)
```

Repeat the PIT checking after removing two "outliers"
Expand Down Expand Up @@ -82,13 +91,20 @@ Plot histogram of PIT values. Ideally histogram should be close to uniform.

```{r }
title1 <- 'Light speed example
distribution of marginal posterior tail-values'
distribution of predictive distribution tail-values'
ggplot(data = Ty) +
geom_histogram(aes(x = x), fill = 'steelblue',
color = 'black', binwidth = 0.05) +
coord_cartesian(xlim = c(0, 1)) +
labs(x = TeX('\\mathit{p}(\\mathit{y}^{\\mathrm{rep}}_{\\mathit{i}} < \\mathit{y_i} | \\mathit{y})'),
labs(x = TeX(r"($\textit{p}(\textit{y}^{\textrm{rep}}_{\textit{i}} < \textit{y_i} | \textit{y})$)"),
y = '', title = title1) +
scale_y_continuous(breaks=NULL)
#* Plot ECDF of PIT values. Ideally ECDF should be close to diagonal line
ggplot(data=data.frame(x=Ty), aes(x)) +
stat_ecdf(geom = "step", color=4) +
xlim(c(0,1))+
labs(x="Observed PIT values", y="ECDF")+
annotate(geom="segment",x=0,y=0,xend=1,yend=1)
```

0 comments on commit 1454485

Please sign in to comment.