## ----include = FALSE----------------------------------------------------------
knitr::opts_chunk$set(
  collapse = TRUE,
  comment = "#>"
)

## ----setup, message = F-------------------------------------------------------
library(baytaAAR)

## ----spitalfields data, echo = T----------------------------------------------
data(spitalfields, package = "baytaAAR")
head(spitalfields)

## ----spitalfields bayta, echo = TRUE, eval=FALSE------------------------------
# spitalfields_res <- bay.ta(
#   framework = "NIMBLE",
#   algorithm = "mnorm",
#   multicore = F,
#   method = spitalfields[,c(2:6)],
#   minimum_age = 16,
#   parameters = c("b", "a", "beta0", "beta", "thresh", "age.s", "Ustar"),
#   thinSteps = 200,
#   numSavedSteps = 500,
#   seed = 331
# )

## ----load spitalfields_res, echo = FALSE--------------------------------------
spitalfields_res <- baytaAAR:::spitalfields_res

## ----spitalfields age.estimate.summary, echo = TRUE---------------------------
summary_list <- lapply(c("Mode", "Median", "Mean"), function(choice) {
  age.comp.summary(mcmc_list = spitalfields_res, 
                   known_age = spitalfields$Age,
                   mean_choice = choice)})
summary_mat <- do.call(rbind, summary_list)
rownames(summary_mat) <- c("Mode", "Median", "Mean")
summary_mat |> t() |> knitr::kable(digits = 2)

## ----spitalfields binom test--------------------------------------------------
sequential.binom.test(spitalfields_res,
                      HDImass = c(seq(0.5, 0.9, 0.1), 0.95),
                      known_age = spitalfields$Age) |>
  knitr::kable(digits = 3)

## ----spitalfields plot, fig.width=8, fig.height=6, fig.align = 'center', warning=FALSE----
diagnostic.summary(spitalfields_res, HDImass = 0.95) |>
  age.comp.plot(known_age = spitalfields$Age)

