Skip to content

Commit e8a8f9b

Browse files
committed
Add plot with ESS against KS result for TMB and PCA-AGHQ #55
1 parent 2b25b6a commit e8a8f9b

File tree

5 files changed

+25
-5
lines changed

5 files changed

+25
-5
lines changed

src/docs_paper/appendix.Rmd

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -682,6 +682,10 @@ knitr::include_graphics("depends/rho_a.png")
682682
knitr::include_graphics("depends/alpha_x.png")
683683
```
684684

685+
```{r ks-ess, fig.cap="The ESS was negatively correlated with KS test statistic for both TMB and PCA-AGHQ. This could be explained in two ways. First, harder to sample parameters could be more difficult to estimate with approximate methods. Second, as more effective samples are collected, the NUTS posterior could become closer to the approximate posteriors."}
686+
knitr::include_graphics("depends/ks-ess.png")
687+
```
688+
685689
\clearpage
686690

687691
# Algorithm using Laplace latent field marginals\label{sec:laplace-marginals}

src/docs_paper/orderly.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ depends:
4747
depends/ks-summary.rds: ks-summary.rds
4848
depends/time-taken.csv: time-taken.csv
4949
depends/beta_alpha.rds: beta_alpha.rds
50+
depends/ks-ess.png: ks-ess.png
5051
- plot-tikz_algorithm-flowchart:
5152
id: latest
5253
use:

src/docs_paper/paper.Rmd

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -540,7 +540,8 @@ knitr::include_graphics("depends/mean-sd-alt-output.png")
540540
### Distribution tests
541541

542542
The two-sample Kolmogorov-Smirnov (KS) test statistic [@smirnov1948table] is the maximum absolute difference between two ECDFs $F(\omega) = \frac{1}{n} \sum_{i = 1}^n \mathbb{I}_{\psi_i \leq \omega}$.
543-
See an illustration of the KS test in Figure \ref{fig:ks} and a summary of the results in Table.
543+
See Figure \ref{fig:ks} for an example.
544+
Additionally, we found that KS test results were negatively correlated with ESS (Figure \ref{fig:ks-ess}).
544545

545546
```{r ks, fig.cap="Example KS test for one parameter."}
546547
knitr::include_graphics("figC.png")

src/naomi-simple_ks/ks.Rmd

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -560,18 +560,28 @@ Is there any correlation between the value of $\text{KS}(\texttt{method}, \textt
560560
```{r}
561561
rhats <- bayesplot::rhat(tmbstan$mcmc$stanfit)
562562
ess_ratio <- bayesplot::neff_ratio(tmbstan$mcmc$stanfit)
563-
niter <- 4 * tmbstan_details$niter / tmbstan_details$nthin
563+
niter <- 0.5 * 4 * tmbstan_details$niter / tmbstan_details$nthin
564564
ess <- ess_ratio * niter
565565
566+
fct_reorg <- function(fac, ...) {
567+
fct_recode(fct_relevel(fac, ...), ...)
568+
}
569+
566570
ks_df %>%
567571
filter(type != "Hyper") %>%
572+
mutate(method = fct_reorg(method, "TMB" = "TMB", "PCA-AGHQ" = "aghq")) %>%
568573
left_join(data.frame(ess) %>%
569574
tibble::rownames_to_column("par"),
570575
) %>%
571576
ggplot(aes(x = ess, y = ks)) +
572-
geom_point(alpha = 0.5) +
573-
geom_smooth(method = "lm", color = "#56B4E9") +
577+
geom_point(shape = 1, alpha = 0.5) +
578+
geom_smooth(method = "lm", color = "#56B4E9", fullrange = TRUE) +
579+
stat_poly_eq(use_label("eq"), label.x.npc = "right") +
580+
stat_poly_eq(label.y = 0.9, label.x.npc = "right") +
581+
scale_x_continuous(limits = c(0, NA)) +
574582
facet_grid(~ method) +
575583
theme_minimal() +
576-
labs(x = "ESS", y = "KS(method, tmbstan)")
584+
labs(x = "ESS", y = "KS(method, NUTS)")
585+
586+
ggsave("ks-ess.png", h = 4, w = 6.25)
577587
```

src/naomi-simple_ks/orderly.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,10 @@ artefacts:
2121
description: KS test summary output
2222
filenames:
2323
- ks-summary.rds
24+
- data:
25+
description: Saved plots
26+
filenames:
27+
- ks-ess.png
2428

2529
resources:
2630
- ks.Rmd

0 commit comments

Comments
 (0)