From 07e6c3e21854116387806fb4fb3c49f58fbb60c1 Mon Sep 17 00:00:00 2001 From: Sebastian Funk Date: Wed, 16 Oct 2024 14:08:12 +0100 Subject: [PATCH 1/9] update documentation of alpha --- R/opts.R | 8 ++++---- man/gp_opts.Rd | 8 ++++---- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/R/opts.R b/R/opts.R index 66d8c56d2..5812c4f6f 100644 --- a/R/opts.R +++ b/R/opts.R @@ -457,9 +457,9 @@ backcalc_opts <- function(prior = c("reports", "none", "infections"), #' of the Gaussian process kernel. Should be approximately the expected variance #' of the logged Rt. #' -#' @param alpha_sd Numeric, defaults to 0.01. The standard deviation of the -#' magnitude parameter of the Gaussian process kernel. Should be approximately -#' the expected standard deviation of the logged Rt. +#' @param alpha_sd Numeric, defaults to 0.1. The standard deviation of the +#' magnitude parameter of the Gaussian process kernel. Can be tuned to adjust +#' the uncertainty about the expected variance of the logged Rt. #' #' @param kernel Character string, the type of kernel required. Currently #' supporting the Matern kernel ("matern"), squared exponential kernel ("se"), @@ -508,7 +508,7 @@ gp_opts <- function(basis_prop = 0.2, ls_min = 0, ls_max = 60, alpha_mean = 0, - alpha_sd = 0.01, + alpha_sd = 0.1, kernel = c("matern", "se", "ou", "periodic"), matern_order = 3 / 2, matern_type, diff --git a/man/gp_opts.Rd b/man/gp_opts.Rd index c9bbf2d9e..845ce33ad 100644 --- a/man/gp_opts.Rd +++ b/man/gp_opts.Rd @@ -12,7 +12,7 @@ gp_opts( ls_min = 0, ls_max = 60, alpha_mean = 0, - alpha_sd = 0.01, + alpha_sd = 0.1, kernel = c("matern", "se", "ou", "periodic"), matern_order = 3/2, matern_type, @@ -49,9 +49,9 @@ this is smaller.} of the Gaussian process kernel. Should be approximately the expected variance of the logged Rt.} -\item{alpha_sd}{Numeric, defaults to 0.01. The standard deviation of the -magnitude parameter of the Gaussian process kernel. Should be approximately -the expected standard deviation of the logged Rt.} +\item{alpha_sd}{Numeric, defaults to 0.1. The standard deviation of the +magnitude parameter of the Gaussian process kernel. Can be tuned to adjust +the uncertainty about the expected variance of the logged Rt.} \item{kernel}{Character string, the type of kernel required. Currently supporting the Matern kernel ("matern"), squared exponential kernel ("se"), From f76fc07bb49c3b59e3b359c5a84164ddab5d7eda Mon Sep 17 00:00:00 2001 From: Sebastian Funk Date: Wed, 16 Oct 2024 14:08:34 +0100 Subject: [PATCH 2/9] update vignette --- vignettes/gaussian_process_implementation_details.Rmd | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/vignettes/gaussian_process_implementation_details.Rmd b/vignettes/gaussian_process_implementation_details.Rmd index e596f8520..fa42703cf 100644 --- a/vignettes/gaussian_process_implementation_details.Rmd +++ b/vignettes/gaussian_process_implementation_details.Rmd @@ -120,7 +120,7 @@ t^* = \frac{t - \frac{1}{2}t_\mathrm{GP}}{\frac{1}{2}t_\mathrm{GP}} Relevant priors are \begin{align} -\alpha &\sim \mathcal{Normal}(0, \sigma_{\alpha}) \\ +\alpha &\sim \mathcal{Normal}(\mu_\alpha, \sigma_{\alpha}) \\ \rho &\sim \mathcal{LogNormal} (\mu_\rho, \sigma_\rho)\\ \end{align} @@ -133,7 +133,8 @@ m_\rho &= 21 \\ s_\rho &= 7 \\ \rho_\mathrm{min} &= 0\\ \rho_\mathrm{max} &= 60\\ -\sigma_\alpha &= 0.05\\ +\mu_\alpha &= 0\\ +\sigma_\alpha &= 0.1 \end{align} # References From 50013727ce7fb5734d61fe71528bcfba1e22e96e Mon Sep 17 00:00:00 2001 From: Sebastian Funk Date: Wed, 16 Oct 2024 15:08:45 +0100 Subject: [PATCH 3/9] correctly use variance / sd in alpha doc --- R/opts.R | 6 +++--- man/gp_opts.Rd | 6 +++--- vignettes/gaussian_process_implementation_details.Rmd | 7 ++++--- 3 files changed, 10 insertions(+), 9 deletions(-) diff --git a/R/opts.R b/R/opts.R index 5812c4f6f..7770f0a0c 100644 --- a/R/opts.R +++ b/R/opts.R @@ -454,12 +454,12 @@ backcalc_opts <- function(prior = c("reports", "none", "infections"), #' this is smaller. #' #' @param alpha_mean Numeric, defaults to 0. The mean of the magnitude parameter -#' of the Gaussian process kernel. Should be approximately the expected variance -#' of the logged Rt. +#' of the Gaussian process kernel. Should be approximately the expected standard +#' deviation of the logged Rt. #' #' @param alpha_sd Numeric, defaults to 0.1. The standard deviation of the #' magnitude parameter of the Gaussian process kernel. Can be tuned to adjust -#' the uncertainty about the expected variance of the logged Rt. +#' the uncertainty about the expected standard deviation of the logged Rt. #' #' @param kernel Character string, the type of kernel required. Currently #' supporting the Matern kernel ("matern"), squared exponential kernel ("se"), diff --git a/man/gp_opts.Rd b/man/gp_opts.Rd index 845ce33ad..dc166543a 100644 --- a/man/gp_opts.Rd +++ b/man/gp_opts.Rd @@ -46,12 +46,12 @@ scale. Updated in \code{\link[=create_gp_data]{create_gp_data()}} to be the leng this is smaller.} \item{alpha_mean}{Numeric, defaults to 0. The mean of the magnitude parameter -of the Gaussian process kernel. Should be approximately the expected variance -of the logged Rt.} +of the Gaussian process kernel. Should be approximately the expected standard +deviation of the logged Rt.} \item{alpha_sd}{Numeric, defaults to 0.1. The standard deviation of the magnitude parameter of the Gaussian process kernel. Can be tuned to adjust -the uncertainty about the expected variance of the logged Rt.} +the uncertainty about the expected standard deviation of the logged Rt.} \item{kernel}{Character string, the type of kernel required. Currently supporting the Matern kernel ("matern"), squared exponential kernel ("se"), diff --git a/vignettes/gaussian_process_implementation_details.Rmd b/vignettes/gaussian_process_implementation_details.Rmd index fa42703cf..18c96021e 100644 --- a/vignettes/gaussian_process_implementation_details.Rmd +++ b/vignettes/gaussian_process_implementation_details.Rmd @@ -44,21 +44,22 @@ with the following choices available for the kernel $k$ ## Matérn 3/2 covariance kernel (the default) \begin{equation} -k(\Delta t) = \alpha \left( 1 + \frac{\sqrt{3} \Delta t}{l} \right) \exp \left( - \frac{\sqrt{3} \Delta t}{l}\right) +k(\Delta t) = \alpha^2 \left( 1 + \frac{\sqrt{3} \Delta t}{l} \right) \exp \left( - \frac{\sqrt{3} \Delta t}{l}\right) \end{equation} with $l>0$ and $\alpha > 0$ the length scale and magnitude, respectively, of the kernel. +Note that here and later we use a slightly different definition of $\alpha$ compared to Riutort-Mayol et al. [@approxGP], where this is defined as our $\alpha^2$. ## Squared exponential kernel \begin{equation} -k(\Delta t) = \alpha \exp \left( - \frac{1}{2} \frac{(\Delta t^2)}{l^2} \right) +k(\Delta t) = \alpha^2 \exp \left( - \frac{1}{2} \frac{(\Delta t^2)}{l^2} \right) \end{equation} ## Ornstein-Uhlenbeck (Matérn 1/2) kernel \begin{equation} -k(\Delta t) = \alpha \exp{\left( - \frac{\Delta t}{2 l^2} \right)} +k(\Delta t) = \alpha^2 \exp{\left( - \frac{\Delta t}{2 l^2} \right)} \end{equation} ## Matérn 5/2 covariance kernel From 68c7b033760e64995f01fbecd2a124016841cf57 Mon Sep 17 00:00:00 2001 From: Sebastian Funk Date: Wed, 16 Oct 2024 15:09:56 +0100 Subject: [PATCH 4/9] update tests --- tests/testthat/test-create_gp_data.R | 2 +- tests/testthat/test-gp_opts.R | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/testthat/test-create_gp_data.R b/tests/testthat/test-create_gp_data.R index b1f7cc765..f177f38d6 100644 --- a/tests/testthat/test-create_gp_data.R +++ b/tests/testthat/test-create_gp_data.R @@ -11,7 +11,7 @@ test_that("create_gp_data returns correct default values when GP is disabled", { expect_equal(gp_data$ls_sdlog, convert_to_logsd(21, 7)) expect_equal(gp_data$ls_min, 0) expect_equal(gp_data$ls_max, 3.54, tolerance = 0.01) - expect_equal(gp_data$alpha_sd, 0.01) + expect_equal(gp_data$alpha_sd, 0.1) expect_equal(gp_data$gp_type, 2) # Default to Matern expect_equal(gp_data$nu, 3 / 2) expect_equal(gp_data$w0, 1.0) diff --git a/tests/testthat/test-gp_opts.R b/tests/testthat/test-gp_opts.R index cd848b75c..682a5cfa2 100644 --- a/tests/testthat/test-gp_opts.R +++ b/tests/testthat/test-gp_opts.R @@ -6,7 +6,7 @@ test_that("gp_opts returns correct default values", { expect_equal(gp$ls_sd, 7) expect_equal(gp$ls_min, 0) expect_equal(gp$ls_max, 60) - expect_equal(gp$alpha_sd, 0.01) + expect_equal(gp$alpha_sd, 0.1) expect_equal(gp$kernel, "matern") expect_equal(gp$matern_order, 3 / 2) expect_equal(gp$w0, 1.0) From 445f61be543c240a8fcec39762517c6f7f2e9326 Mon Sep 17 00:00:00 2001 From: Sebastian Funk Date: Thu, 17 Oct 2024 09:04:31 +0100 Subject: [PATCH 5/9] Revert "update tests" This reverts commit 68c7b033760e64995f01fbecd2a124016841cf57. --- tests/testthat/test-create_gp_data.R | 2 +- tests/testthat/test-gp_opts.R | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/testthat/test-create_gp_data.R b/tests/testthat/test-create_gp_data.R index f177f38d6..b1f7cc765 100644 --- a/tests/testthat/test-create_gp_data.R +++ b/tests/testthat/test-create_gp_data.R @@ -11,7 +11,7 @@ test_that("create_gp_data returns correct default values when GP is disabled", { expect_equal(gp_data$ls_sdlog, convert_to_logsd(21, 7)) expect_equal(gp_data$ls_min, 0) expect_equal(gp_data$ls_max, 3.54, tolerance = 0.01) - expect_equal(gp_data$alpha_sd, 0.1) + expect_equal(gp_data$alpha_sd, 0.01) expect_equal(gp_data$gp_type, 2) # Default to Matern expect_equal(gp_data$nu, 3 / 2) expect_equal(gp_data$w0, 1.0) diff --git a/tests/testthat/test-gp_opts.R b/tests/testthat/test-gp_opts.R index 682a5cfa2..cd848b75c 100644 --- a/tests/testthat/test-gp_opts.R +++ b/tests/testthat/test-gp_opts.R @@ -6,7 +6,7 @@ test_that("gp_opts returns correct default values", { expect_equal(gp$ls_sd, 7) expect_equal(gp$ls_min, 0) expect_equal(gp$ls_max, 60) - expect_equal(gp$alpha_sd, 0.1) + expect_equal(gp$alpha_sd, 0.01) expect_equal(gp$kernel, "matern") expect_equal(gp$matern_order, 3 / 2) expect_equal(gp$w0, 1.0) From 8fc929956461651f3bea2520ee91e7f9090a4665 Mon Sep 17 00:00:00 2001 From: Sebastian Funk Date: Thu, 17 Oct 2024 09:05:20 +0100 Subject: [PATCH 6/9] Revert prior change --- R/opts.R | 2 +- vignettes/gaussian_process_implementation_details.Rmd | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/R/opts.R b/R/opts.R index 7770f0a0c..a5698925b 100644 --- a/R/opts.R +++ b/R/opts.R @@ -508,7 +508,7 @@ gp_opts <- function(basis_prop = 0.2, ls_min = 0, ls_max = 60, alpha_mean = 0, - alpha_sd = 0.1, + alpha_sd = 0.01, kernel = c("matern", "se", "ou", "periodic"), matern_order = 3 / 2, matern_type, diff --git a/vignettes/gaussian_process_implementation_details.Rmd b/vignettes/gaussian_process_implementation_details.Rmd index 18c96021e..2a8360431 100644 --- a/vignettes/gaussian_process_implementation_details.Rmd +++ b/vignettes/gaussian_process_implementation_details.Rmd @@ -135,7 +135,7 @@ s_\rho &= 7 \\ \rho_\mathrm{min} &= 0\\ \rho_\mathrm{max} &= 60\\ \mu_\alpha &= 0\\ -\sigma_\alpha &= 0.1 +\sigma_\alpha &= 0.01 \end{align} # References From 7f42ad5f64fcbe0ea8e63b816c9ec8155c92c637 Mon Sep 17 00:00:00 2001 From: Sebastian Funk Date: Thu, 17 Oct 2024 09:08:17 +0100 Subject: [PATCH 7/9] re-render docs --- man/gp_opts.Rd | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/man/gp_opts.Rd b/man/gp_opts.Rd index dc166543a..45160a893 100644 --- a/man/gp_opts.Rd +++ b/man/gp_opts.Rd @@ -12,7 +12,7 @@ gp_opts( ls_min = 0, ls_max = 60, alpha_mean = 0, - alpha_sd = 0.1, + alpha_sd = 0.01, kernel = c("matern", "se", "ou", "periodic"), matern_order = 3/2, matern_type, From e1d4ed52e63d72f3724e8c2aeb1849d93d24f27e Mon Sep 17 00:00:00 2001 From: Sebastian Funk Date: Thu, 17 Oct 2024 13:36:21 +0100 Subject: [PATCH 8/9] refine wording (where GP applies depends on model) --- R/opts.R | 7 ++++--- man/gp_opts.Rd | 7 ++++--- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/R/opts.R b/R/opts.R index a5698925b..7e9f0aa94 100644 --- a/R/opts.R +++ b/R/opts.R @@ -455,11 +455,12 @@ backcalc_opts <- function(prior = c("reports", "none", "infections"), #' #' @param alpha_mean Numeric, defaults to 0. The mean of the magnitude parameter #' of the Gaussian process kernel. Should be approximately the expected standard -#' deviation of the logged Rt. +#' deviation of the Gaussian process (logged Rt in case of the renewal model, +#' logged infections in case of the nonmechanistic model). #' #' @param alpha_sd Numeric, defaults to 0.1. The standard deviation of the #' magnitude parameter of the Gaussian process kernel. Can be tuned to adjust -#' the uncertainty about the expected standard deviation of the logged Rt. +#' how far alpha is allowed to deviate form its prior mean (`alpha_mean`). #' #' @param kernel Character string, the type of kernel required. Currently #' supporting the Matern kernel ("matern"), squared exponential kernel ("se"), @@ -508,7 +509,7 @@ gp_opts <- function(basis_prop = 0.2, ls_min = 0, ls_max = 60, alpha_mean = 0, - alpha_sd = 0.01, + alpha_sd = 0.05, kernel = c("matern", "se", "ou", "periodic"), matern_order = 3 / 2, matern_type, diff --git a/man/gp_opts.Rd b/man/gp_opts.Rd index 45160a893..57866fde8 100644 --- a/man/gp_opts.Rd +++ b/man/gp_opts.Rd @@ -12,7 +12,7 @@ gp_opts( ls_min = 0, ls_max = 60, alpha_mean = 0, - alpha_sd = 0.01, + alpha_sd = 0.05, kernel = c("matern", "se", "ou", "periodic"), matern_order = 3/2, matern_type, @@ -47,11 +47,12 @@ this is smaller.} \item{alpha_mean}{Numeric, defaults to 0. The mean of the magnitude parameter of the Gaussian process kernel. Should be approximately the expected standard -deviation of the logged Rt.} +deviation of the Gaussian process (logged Rt in case of the renewal model, +logged infections in case of the nonmechanistic model).} \item{alpha_sd}{Numeric, defaults to 0.1. The standard deviation of the magnitude parameter of the Gaussian process kernel. Can be tuned to adjust -the uncertainty about the expected standard deviation of the logged Rt.} +how far alpha is allowed to deviate form its prior mean (\code{alpha_mean}).} \item{kernel}{Character string, the type of kernel required. Currently supporting the Matern kernel ("matern"), squared exponential kernel ("se"), From cc2494077688912538685b47422cd56f88635105 Mon Sep 17 00:00:00 2001 From: Sebastian Funk Date: Thu, 17 Oct 2024 14:59:53 +0100 Subject: [PATCH 9/9] revert stray prior re-change --- R/opts.R | 2 +- man/gp_opts.Rd | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/R/opts.R b/R/opts.R index 7e9f0aa94..94f7406d6 100644 --- a/R/opts.R +++ b/R/opts.R @@ -509,7 +509,7 @@ gp_opts <- function(basis_prop = 0.2, ls_min = 0, ls_max = 60, alpha_mean = 0, - alpha_sd = 0.05, + alpha_sd = 0.01, kernel = c("matern", "se", "ou", "periodic"), matern_order = 3 / 2, matern_type, diff --git a/man/gp_opts.Rd b/man/gp_opts.Rd index 57866fde8..984baee1f 100644 --- a/man/gp_opts.Rd +++ b/man/gp_opts.Rd @@ -12,7 +12,7 @@ gp_opts( ls_min = 0, ls_max = 60, alpha_mean = 0, - alpha_sd = 0.05, + alpha_sd = 0.01, kernel = c("matern", "se", "ou", "periodic"), matern_order = 3/2, matern_type,