From be8feaf7f6bf9b37192f146611a80ff1957d8bdd 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 bd08b2b44..fb0693252 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 fe6eda285cbb36b2a195ce2bb363d3564b28efae 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 1562a7faa8218cb2ee510b4bcd921f03754e1c75 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 fb0693252..8fc05d48c 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 17c735261918a217d74e4f516e72f9ee241091ef 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 eabb0aef84f0efc2373485c329be41bba09f5ce7 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 6c8d1930f5ceb3c8c1ab33754a97578dde61d229 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 8fc05d48c..586b8c8f6 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 f52c42d0173685cbc1f9481ed0eb401442c23d95 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 f9e7acc32e85d4787dbb02500d332ed252c3210b 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 586b8c8f6..13016d05c 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 25dde1547b989f897f9fd3a1da78cb648db1553a 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 13016d05c..fa4592e40 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,