Skip to content

Commit

Permalink
Add tables of point estimate estimation results to appendix #55
Browse files Browse the repository at this point in the history
  • Loading branch information
athowes committed Jul 20, 2023
1 parent 43bc360 commit c20ffc7
Show file tree
Hide file tree
Showing 4 changed files with 69 additions and 7 deletions.
72 changes: 65 additions & 7 deletions src/docs_paper/appendix.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -508,30 +508,88 @@ knitr::include_graphics("depends/marginal-sd.png")
knitr::include_graphics("depends/pc-loadings.png")
```

## Estimated normalising constant comparison
## Normalising constant estimation

Add here plots and description of the estimated normalising constant for different PCA-AGHQ settings.

\clearpage

# Comprehensive inference comparison
# Inference comparison

In this section we give further inference comparison results, parameter by parameter.
In this section we give more detailed inference comparison results for each parameter or group of parameters.
For any parameter with length greater than one, the results presented are an average.

## Point estimates

### Posterior mean

```{r}
point_summary <- read_csv("depends/point-estimates.csv")
point_summary <- point_summary %>%
mutate(type = fct_recode(type, "Output" = "output", "Latent" = "latent"))
latex_table_point_estimates <- function(.indicator) {
point_summary %>%
group_by(par, type, indicator, method) %>%
summarise(
rmse = sqrt(mean((truth - approximate)^2)),
mae = mean(abs(truth - approximate))
) %>%
ungroup() %>%
pivot_wider(
names_from = "method",
values_from = c("rmse", "mae")
) %>%
filter(indicator == .indicator) %>%
select(Parameter = par, Type = type, `TMB` = `rmse_TMB`, `PCA-AGHQ` = `rmse_PCA-AGHQ`) %>%
mutate(
Difference = `PCA-AGHQ` - TMB,
`Percent Difference` = (`PCA-AGHQ` - TMB) / TMB
) %>%
gt::gt(groupname_col = "Type") %>%
gt::fmt_number(
columns = c(`TMB`, `PCA-AGHQ`, Difference),
n_sigfig = 2
) %>%
gt::fmt_percent(
columns = `Percent Difference`,
decimals = 1
) %>%
gt::text_transform(
locations = gt::cells_body("Parameter"),
fn = function(x) paste0("\\texttt{", x, "}")
) %>%
gt::as_latex() %>%
as.character()
}
latex_table_point_estimates("Posterior mean estimate") %>%
cat(file = "point-summary-mean.tex")
latex_table_point_estimates("Posterior SD estimate") %>%
cat(file = "point-summary-sd.tex")
```

\input{point-summary-mean.tex}

### Posterior standard deviation

\input{point-summary-sd.tex}

## Distribution tests

### Kolmogorov-Smirnov

```{r}
ks_summary <- readRDS("depends/ks-summary.rds")
ks_summary %>%
ungroup() %>%
filter(type == "Latent field") %>%
select(-type) %>%
rename(TMB = `KS(TMB, tmbstan)`, `PCA-AGHQ` = `KS(aghq, tmbstan)`) %>%
select(Parameter, TMB, `PCA-AGHQ`) %>%
mutate(Difference = TMB - `PCA-AGHQ`) %>%
select(Parameter, TMB = `KS(TMB, tmbstan)`, `PCA-AGHQ` = `KS(aghq, tmbstan)`) %>%
mutate(Difference = `PCA-AGHQ` - TMB) %>%
gt::gt() %>%
gt::summary_rows(
columns = c(`TMB`, `PCA-AGHQ`, Difference),
Expand All @@ -549,7 +607,7 @@ ks_summary %>%
) %>%
gt::text_transform(
locations = gt::cells_body("Difference"),
fn = function(x) ifelse(x > 0, paste0("\\textbf{", x, "}"), paste0(x))
fn = function(x) ifelse(x < 0, paste0("\\textbf{", x, "}"), paste0(x))
) %>%
gt::as_latex() %>%
as.character() %>%
Expand Down
1 change: 1 addition & 0 deletions src/docs_paper/orderly.yml
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ depends:
use:
depends/mean-sd-alt-latent.png: mean-sd-alt-latent.png
depends/mean-sd.csv: mean-sd.csv
depends/point-estimates.csv: point-estimates.csv
- check_hyper-marginals:
id: latest
use:
Expand Down
1 change: 1 addition & 0 deletions src/naomi-simple_point-estimates/orderly.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ artefacts:
- mean-alt-output.png
- sd-output.png
- sd-alt-output.png
- point-estimates.csv

resources:
- point-estimates.Rmd
Expand Down
2 changes: 2 additions & 0 deletions src/naomi-simple_point-estimates/point-estimates.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,8 @@ head(df_plot)
Calculate the root mean square and mean absolute errors between the approximate methods and NUTS (taken to be the truth):

```{r}
write_csv(df_plot, "point-estimates.csv")
df_metrics <- df_plot %>%
group_by(method, indicator, type) %>%
summarise(
Expand Down

0 comments on commit c20ffc7

Please sign in to comment.