From d351e31ec1533cd67300d8ee80132c9e14bc75b3 Mon Sep 17 00:00:00 2001 From: athowes Date: Tue, 15 Oct 2024 21:37:03 +0100 Subject: [PATCH 01/12] Move fitting functions into fit --- R/defaults.R | 32 --------------------------- R/fit.R | 62 ++++++++++++++++++++++++++++++++++++++++++++++++++++ R/generics.R | 3 +++ _pkgdown.yml | 6 ++++- 4 files changed, 70 insertions(+), 33 deletions(-) create mode 100644 R/fit.R diff --git a/R/defaults.R b/R/defaults.R index ab096aac3..144244092 100644 --- a/R/defaults.R +++ b/R/defaults.R @@ -23,35 +23,3 @@ epidist_stancode.default <- function(data, ...) { "See methods(epidist_stancode) for available methods" ) } - -#' Default method used for interface using `brms` -#' -#' @inheritParams epidist -#' @inheritParams epidist_formula -#' @rdname epidist.default -#' @method epidist default -#' @family defaults -#' @export -epidist.default <- function(data, formula = brms::bf(mu ~ 1), - family = "lognormal", prior = NULL, - backend = "cmdstanr", fn = brms::brm, ...) { - epidist_validate(data) - epidist_family <- epidist_family(data, family) - epidist_formula <- epidist_formula( - data = data, family = epidist_family, formula = formula - ) - epidist_prior <- epidist_prior( - data = data, family = family, formula = epidist_formula, prior - ) - epidist_stancode <- epidist_stancode( - data = data, family = epidist_family, formula = epidist_formula - ) - fit <- fn( - formula = epidist_formula, family = epidist_family, prior = epidist_prior, - stanvars = epidist_stancode, backend = backend, data = data, ... - ) - - class(fit) <- c(class(fit), "epidist_fit") - - return(fit) -} diff --git a/R/fit.R b/R/fit.R new file mode 100644 index 000000000..4285380b1 --- /dev/null +++ b/R/fit.R @@ -0,0 +1,62 @@ +#' Fit epidemiological delay distributions using a `brms` interface +#' +#' @inheritParams epidist_validate +#' @param formula A formula object created using `brms::bf`. A formula must be +#' provided for the distributional parameter `mu` common to all `brms` families. +#' Optionally, formulas may also be provided for additional distributional +#' parameters. +#' @param family A description of the response distribution and link function to +#' be used in the model. Every family function has a link argument allowing +#' users to specify the link function to be applied on the response variable. +#' If not specified, default links are used. For details of supported families +#' see [brmsfamily()]. +#' @param prior One or more `brmsprior` objects created by [brms::set_prior()] +#' or related functions. These priors are passed to [epidist_prior()] in the +#' `prior` argument. We recommend caution and the use of prior predictive checks +#' for specifying prior distributions. +#' @param backend Character string naming the package to use as the backend for +#' fitting the Stan model. Options are `"rstan"` and `"cmdstanr"` (the default). +#' This option is passed directly through to `fn`. +#' @param fn The internal function to be called. By default this is `brms::brm`, +#' which performs inference for the specified model. Other options +#' `brms::make_stancode`, which returns the Stan code for the specified model, +#' and `brms::make_standata` which returns the data passed to Stan. These +#' options may be useful for model debugging and extensions. +#' @param ... Additional arguments for method. +#' @family fit +#' @export +epidist <- function(data, formula, family, prior, backend, fn, ...) { + UseMethod("epidist") +} + +#' Default method used for interface using `brms` +#' +#' @inheritParams epidist +#' @inheritParams epidist_formula +#' @rdname epidist.default +#' @method epidist default +#' @family fit +#' @export +epidist.default <- function(data, formula = brms::bf(mu ~ 1), + family = "lognormal", prior = NULL, + backend = "cmdstanr", fn = brms::brm, ...) { + epidist_validate(data) + epidist_family <- epidist_family(data, family) + epidist_formula <- epidist_formula( + data = data, family = epidist_family, formula = formula + ) + epidist_prior <- epidist_prior( + data = data, family = family, formula = epidist_formula, prior + ) + epidist_stancode <- epidist_stancode( + data = data, family = epidist_family, formula = epidist_formula + ) + fit <- fn( + formula = epidist_formula, family = epidist_family, prior = epidist_prior, + stanvars = epidist_stancode, backend = backend, data = data, ... + ) + + class(fit) <- c(class(fit), "epidist_fit") + + return(fit) +} diff --git a/R/generics.R b/R/generics.R index cd5d70147..99fde2d6c 100644 --- a/R/generics.R +++ b/R/generics.R @@ -26,6 +26,7 @@ epidist_validate <- function(data) { epidist_stancode <- function(data, ...) { UseMethod("epidist_stancode") } +<<<<<<< HEAD #' Fit epidemiological delay distributions using a `brms` interface #' @@ -57,3 +58,5 @@ epidist_stancode <- function(data, ...) { epidist <- function(data, formula, family, prior, backend, fn, ...) { UseMethod("epidist") } +======= +>>>>>>> 4cb6f81e (Move fitting functions into fit.R) diff --git a/_pkgdown.yml b/_pkgdown.yml index cf80bfada..3848f00ab 100644 --- a/_pkgdown.yml +++ b/_pkgdown.yml @@ -57,10 +57,14 @@ reference: desc: Functions related to specifying custom `brms` formula contents: - has_concept("formula") -- title: Priors +- title: Prior distributions desc: Functions for specifying prior distributions contents: - has_concept("prior") +- title: Model fitting + desc: Functions for fitting delay distribution models + contents: + - has_concept("fit") - title: Latent individual model desc: Specific methods for the latent individual model contents: From ab8ce1d20bfcc74700e0e6097700dd45c1b30c8e Mon Sep 17 00:00:00 2001 From: athowes Date: Tue, 15 Oct 2024 21:37:26 +0100 Subject: [PATCH 02/12] Create stancode.R --- R/defaults.R | 13 ------------- R/generics.R | 3 +++ R/stancode.R | 28 ++++++++++++++++++++++++++++ _pkgdown.yml | 6 +++++- 4 files changed, 36 insertions(+), 14 deletions(-) create mode 100644 R/stancode.R diff --git a/R/defaults.R b/R/defaults.R index 144244092..e8fa85a35 100644 --- a/R/defaults.R +++ b/R/defaults.R @@ -10,16 +10,3 @@ epidist_validate.default <- function(data, ...) { "See methods(epidist_validate) for available methods" ) } - -#' Default method for defining model specific Stan code -#' -#' @inheritParams epidist_stancode -#' @param ... Additional arguments passed to method. -#' @family defaults -#' @export -epidist_stancode.default <- function(data, ...) { - cli_abort( - "No epidist_stancode method implemented for the class ", class(data), "\n", - "See methods(epidist_stancode) for available methods" - ) -} diff --git a/R/generics.R b/R/generics.R index 99fde2d6c..007b153e2 100644 --- a/R/generics.R +++ b/R/generics.R @@ -10,6 +10,7 @@ epidist_validate <- function(data) { UseMethod("epidist_validate") } +<<<<<<< HEAD #' Define model specific Stan code #' @@ -60,3 +61,5 @@ epidist <- function(data, formula, family, prior, backend, fn, ...) { } ======= >>>>>>> 4cb6f81e (Move fitting functions into fit.R) +======= +>>>>>>> 8cb24d62 (Create stancode.R) diff --git a/R/stancode.R b/R/stancode.R new file mode 100644 index 000000000..674941e2e --- /dev/null +++ b/R/stancode.R @@ -0,0 +1,28 @@ +#' Define model specific Stan code +#' +#' This function is used within [epidist()] to create any custom Stan code which +#' is injected into `brms` via the `stanvars` argument. It is unlikely that +#' as a user you will need this function, but we export it nonetheless to be +#' transparent about what exactly is happening inside of a call to [epidist()]. +#' +#' @inheritParams epidist_validate +#' @param ... Additional arguments passed to method. +#' @rdname epidist_stancode +#' @family stan +#' @export +epidist_stancode <- function(data, ...) { + UseMethod("epidist_stancode") +} + +#' Default method for defining model specific Stan code +#' +#' @inheritParams epidist_stancode +#' @param ... Additional arguments passed to method. +#' @family stan +#' @export +epidist_stancode.default <- function(data, ...) { + cli_abort( + "No epidist_stancode method implemented for the class ", class(data), "\n", + "See methods(epidist_stancode) for available methods" + ) +} diff --git a/_pkgdown.yml b/_pkgdown.yml index 3848f00ab..f23a4db96 100644 --- a/_pkgdown.yml +++ b/_pkgdown.yml @@ -61,8 +61,12 @@ reference: desc: Functions for specifying prior distributions contents: - has_concept("prior") +- title: Stan code + desc: Functions for specifying custom Stan code to put into `brms` + contents: + - has_concept("stan") - title: Model fitting - desc: Functions for fitting delay distribution models + desc: Functions for fitting delay distribution models using `brms` contents: - has_concept("fit") - title: Latent individual model From 5c784904371e4811a955a90819cb89353a4c5af5 Mon Sep 17 00:00:00 2001 From: athowes Date: Tue, 15 Oct 2024 21:38:27 +0100 Subject: [PATCH 03/12] Create validate.R --- R/defaults.R | 13 +------------ R/generics.R | 4 ++++ R/validate.R | 25 +++++++++++++++++++++++++ _pkgdown.yml | 4 ++++ 4 files changed, 34 insertions(+), 12 deletions(-) create mode 100644 R/validate.R diff --git a/R/defaults.R b/R/defaults.R index e8fa85a35..8b1378917 100644 --- a/R/defaults.R +++ b/R/defaults.R @@ -1,12 +1 @@ -#' Default method for data validation -#' -#' @inheritParams epidist_validate -#' @param ... Additional arguments passed to method. -#' @family defaults -#' @export -epidist_validate.default <- function(data, ...) { - cli_abort( - "No epidist_validate method implemented for the class ", class(data), "\n", - "See methods(epidist_validate) for available methods" - ) -} + diff --git a/R/generics.R b/R/generics.R index 007b153e2..6dcf9628e 100644 --- a/R/generics.R +++ b/R/generics.R @@ -1,3 +1,4 @@ +<<<<<<< HEAD #' Validate a data object for use with [epidist()] #' #' This function validates that the provided `data` is suitable to run a @@ -63,3 +64,6 @@ epidist <- function(data, formula, family, prior, backend, fn, ...) { >>>>>>> 4cb6f81e (Move fitting functions into fit.R) ======= >>>>>>> 8cb24d62 (Create stancode.R) +======= + +>>>>>>> 006aeb64 (Create validate.R) diff --git a/R/validate.R b/R/validate.R new file mode 100644 index 000000000..1ce7dbb21 --- /dev/null +++ b/R/validate.R @@ -0,0 +1,25 @@ +#' Validate a data object for use with [epidist()] +#' +#' This function validates that the provided `data` is suitable to run a +#' particular `epidist` model. This may include checking the class of `data`, +#' and that it contains suitable columns. +#' +#' @param data A `data.frame` containing line list data. +#' @family validate +#' @export +epidist_validate <- function(data) { + UseMethod("epidist_validate") +} + +#' Default method for data validation +#' +#' @inheritParams epidist_validate +#' @param ... Additional arguments passed to method. +#' @family validate +#' @export +epidist_validate.default <- function(data, ...) { + cli_abort( + "No epidist_validate method implemented for the class ", class(data), "\n", + "See methods(epidist_validate) for available methods" + ) +} diff --git a/_pkgdown.yml b/_pkgdown.yml index f23a4db96..61f1dbd5d 100644 --- a/_pkgdown.yml +++ b/_pkgdown.yml @@ -41,6 +41,10 @@ reference: desc: Functions for preprocessing data contents: - has_concept("preprocess") +- title: Validation + desc: Functions used to check validity of package objects + contents: + - has_concept("validate") - title: S3 generics desc: S3 generics for delay modelling contents: From 28a9cd32778852f3bc28d8cdb90e0e3bc72046ed Mon Sep 17 00:00:00 2001 From: athowes Date: Tue, 15 Oct 2024 21:39:00 +0100 Subject: [PATCH 04/12] Remove defaults.R and generics.R and pkgdown groups --- R/defaults.R | 1 - R/generics.R | 69 ---------------------------------------------------- _pkgdown.yml | 8 ------ 3 files changed, 78 deletions(-) delete mode 100644 R/defaults.R delete mode 100644 R/generics.R diff --git a/R/defaults.R b/R/defaults.R deleted file mode 100644 index 8b1378917..000000000 --- a/R/defaults.R +++ /dev/null @@ -1 +0,0 @@ - diff --git a/R/generics.R b/R/generics.R deleted file mode 100644 index 6dcf9628e..000000000 --- a/R/generics.R +++ /dev/null @@ -1,69 +0,0 @@ -<<<<<<< HEAD -#' Validate a data object for use with [epidist()] -#' -#' This function validates that the provided `data` is suitable to run a -#' particular `epidist` model. This may include checking the class of `data`, -#' and that it contains suitable columns. -#' -#' @param data A `data.frame` containing line list data. -#' @family generics -#' @export -epidist_validate <- function(data) { - UseMethod("epidist_validate") -} -<<<<<<< HEAD - -#' Define model specific Stan code -#' -#' This function is used within [epidist()] to create any custom Stan code which -#' is injected into `brms` via the `stanvars` argument. It is unlikely that -#' as a user you will need this function, but we export it nonetheless to be -#' transparent about what exactly is happening inside of a call to [epidist()]. -#' -#' @inheritParams epidist_validate -#' @param ... Additional arguments passed to method. -#' @rdname epidist_stancode -#' @family generics -#' @export -epidist_stancode <- function(data, ...) { - UseMethod("epidist_stancode") -} -<<<<<<< HEAD - -#' Fit epidemiological delay distributions using a `brms` interface -#' -#' @inheritParams epidist_validate -#' @param formula A formula object created using [brms::bf()]. A formula must be -#' provided for the distributional parameter `mu` common to all `brms` families. -#' Optionally, formulas may also be provided for additional distributional -#' parameters. -#' @param family A description of the response distribution and link function to -#' be used in the model. Every family function has a link argument allowing -#' users to specify the link function to be applied on the response variable. -#' If not specified, default links are used. For details of supported families -#' see [brmsfamily()]. -#' @param prior One or more `brmsprior` objects created by [brms::set_prior()] -#' or related functions. These priors are passed to [epidist_prior()] in the -#' `prior` argument. We recommend caution and the use of prior predictive checks -#' for specifying prior distributions. -#' @param backend Character string naming the package to use as the backend for -#' fitting the Stan model. Options are `"rstan"` and `"cmdstanr"` (the default). -#' This option is passed directly through to `fn`. -#' @param fn The internal function to be called. By default this is -#' [brms::brm()] which performs inference for the specified model. Other options -#' [brms::make_stancode()], which returns the Stan code for the specified model, -#' and [brms::make_standata()] which returns the data passed to Stan. These -#' options may be useful for model debugging and extensions. -#' @param ... Additional arguments for method. -#' @family generics -#' @export -epidist <- function(data, formula, family, prior, backend, fn, ...) { - UseMethod("epidist") -} -======= ->>>>>>> 4cb6f81e (Move fitting functions into fit.R) -======= ->>>>>>> 8cb24d62 (Create stancode.R) -======= - ->>>>>>> 006aeb64 (Create validate.R) diff --git a/_pkgdown.yml b/_pkgdown.yml index 61f1dbd5d..f5ef239b1 100644 --- a/_pkgdown.yml +++ b/_pkgdown.yml @@ -45,14 +45,6 @@ reference: desc: Functions used to check validity of package objects contents: - has_concept("validate") -- title: S3 generics - desc: S3 generics for delay modelling - contents: - - has_concept("generics") -- title: Method default - desc: Default methods for S3 generics - contents: - - has_concept("defaults") - title: Family desc: Functions related to specifying custom `brms` families contents: From 8b4dd25eb2af7c96af6b930374b4c24b8b23f0e2 Mon Sep 17 00:00:00 2001 From: athowes Date: Tue, 15 Oct 2024 10:30:18 +0100 Subject: [PATCH 05/12] Document --- man/epidist.Rd | 9 ++++----- man/epidist.default.Rd | 9 ++++----- man/epidist_stancode.Rd | 9 ++++----- man/epidist_stancode.default.Rd | 9 ++++----- man/epidist_validate.Rd | 9 ++++----- man/epidist_validate.default.Rd | 9 ++++----- 6 files changed, 24 insertions(+), 30 deletions(-) diff --git a/man/epidist.Rd b/man/epidist.Rd index 6ace0b497..dbb162aa5 100644 --- a/man/epidist.Rd +++ b/man/epidist.Rd @@ -1,5 +1,5 @@ % Generated by roxygen2: do not edit by hand -% Please edit documentation in R/generics.R +% Please edit documentation in R/fit.R \name{epidist} \alias{epidist} \title{Fit epidemiological delay distributions using a \code{brms} interface} @@ -41,8 +41,7 @@ options may be useful for model debugging and extensions.} Fit epidemiological delay distributions using a \code{brms} interface } \seealso{ -Other generics: -\code{\link{epidist_stancode}()}, -\code{\link{epidist_validate}()} +Other fit: +\code{\link{epidist.default}()} } -\concept{generics} +\concept{fit} diff --git a/man/epidist.default.Rd b/man/epidist.default.Rd index 6dac69030..376fb7645 100644 --- a/man/epidist.default.Rd +++ b/man/epidist.default.Rd @@ -1,5 +1,5 @@ % Generated by roxygen2: do not edit by hand -% Please edit documentation in R/defaults.R +% Please edit documentation in R/fit.R \name{epidist.default} \alias{epidist.default} \title{Default method used for interface using \code{brms}} @@ -49,8 +49,7 @@ options may be useful for model debugging and extensions.} Default method used for interface using \code{brms} } \seealso{ -Other defaults: -\code{\link{epidist_stancode.default}()}, -\code{\link{epidist_validate.default}()} +Other fit: +\code{\link{epidist}()} } -\concept{defaults} +\concept{fit} diff --git a/man/epidist_stancode.Rd b/man/epidist_stancode.Rd index 3ed292a52..d86c8010d 100644 --- a/man/epidist_stancode.Rd +++ b/man/epidist_stancode.Rd @@ -1,5 +1,5 @@ % Generated by roxygen2: do not edit by hand -% Please edit documentation in R/generics.R +% Please edit documentation in R/stancode.R \name{epidist_stancode} \alias{epidist_stancode} \title{Define model specific Stan code} @@ -18,8 +18,7 @@ as a user you will need this function, but we export it nonetheless to be transparent about what exactly is happening inside of a call to \code{\link[=epidist]{epidist()}}. } \seealso{ -Other generics: -\code{\link{epidist}()}, -\code{\link{epidist_validate}()} +Other stan: +\code{\link{epidist_stancode.default}()} } -\concept{generics} +\concept{stan} diff --git a/man/epidist_stancode.default.Rd b/man/epidist_stancode.default.Rd index 7154370dd..1aa781741 100644 --- a/man/epidist_stancode.default.Rd +++ b/man/epidist_stancode.default.Rd @@ -1,5 +1,5 @@ % Generated by roxygen2: do not edit by hand -% Please edit documentation in R/defaults.R +% Please edit documentation in R/stancode.R \name{epidist_stancode.default} \alias{epidist_stancode.default} \title{Default method for defining model specific Stan code} @@ -15,8 +15,7 @@ Default method for defining model specific Stan code } \seealso{ -Other defaults: -\code{\link{epidist.default}()}, -\code{\link{epidist_validate.default}()} +Other stan: +\code{\link{epidist_stancode}()} } -\concept{defaults} +\concept{stan} diff --git a/man/epidist_validate.Rd b/man/epidist_validate.Rd index f30fc94cb..06d52bcbf 100644 --- a/man/epidist_validate.Rd +++ b/man/epidist_validate.Rd @@ -1,5 +1,5 @@ % Generated by roxygen2: do not edit by hand -% Please edit documentation in R/generics.R +% Please edit documentation in R/validate.R \name{epidist_validate} \alias{epidist_validate} \title{Validate a data object for use with \code{\link[=epidist]{epidist()}}} @@ -15,8 +15,7 @@ particular \code{epidist} model. This may include checking the class of \code{da and that it contains suitable columns. } \seealso{ -Other generics: -\code{\link{epidist}()}, -\code{\link{epidist_stancode}()} +Other validate: +\code{\link{epidist_validate.default}()} } -\concept{generics} +\concept{validate} diff --git a/man/epidist_validate.default.Rd b/man/epidist_validate.default.Rd index 9c0787ffa..e1c12f87a 100644 --- a/man/epidist_validate.default.Rd +++ b/man/epidist_validate.default.Rd @@ -1,5 +1,5 @@ % Generated by roxygen2: do not edit by hand -% Please edit documentation in R/defaults.R +% Please edit documentation in R/validate.R \name{epidist_validate.default} \alias{epidist_validate.default} \title{Default method for data validation} @@ -15,8 +15,7 @@ Default method for data validation } \seealso{ -Other defaults: -\code{\link{epidist.default}()}, -\code{\link{epidist_stancode.default}()} +Other validate: +\code{\link{epidist_validate}()} } -\concept{defaults} +\concept{validate} From 38ec2e7d8cc50fd9de9194c2b96155e1181c0c33 Mon Sep 17 00:00:00 2001 From: athowes Date: Tue, 15 Oct 2024 10:32:17 +0100 Subject: [PATCH 06/12] Don't need this line --- R/fit.R | 1 - 1 file changed, 1 deletion(-) diff --git a/R/fit.R b/R/fit.R index 4285380b1..d1697e3cf 100644 --- a/R/fit.R +++ b/R/fit.R @@ -32,7 +32,6 @@ epidist <- function(data, formula, family, prior, backend, fn, ...) { #' Default method used for interface using `brms` #' #' @inheritParams epidist -#' @inheritParams epidist_formula #' @rdname epidist.default #' @method epidist default #' @family fit From 2f1b406d41647226d7d3d4e6baa9789ae3f7e7c7 Mon Sep 17 00:00:00 2001 From: athowes Date: Tue, 15 Oct 2024 10:33:20 +0100 Subject: [PATCH 07/12] Standardise providing ... argument to generics --- R/validate.R | 3 ++- man/epidist_validate.Rd | 4 +++- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/R/validate.R b/R/validate.R index 1ce7dbb21..65d86d884 100644 --- a/R/validate.R +++ b/R/validate.R @@ -5,9 +5,10 @@ #' and that it contains suitable columns. #' #' @param data A `data.frame` containing line list data. +#' @param ... Additional arguments passed to method. #' @family validate #' @export -epidist_validate <- function(data) { +epidist_validate <- function(data, ...) { UseMethod("epidist_validate") } diff --git a/man/epidist_validate.Rd b/man/epidist_validate.Rd index 06d52bcbf..bccd9b855 100644 --- a/man/epidist_validate.Rd +++ b/man/epidist_validate.Rd @@ -4,10 +4,12 @@ \alias{epidist_validate} \title{Validate a data object for use with \code{\link[=epidist]{epidist()}}} \usage{ -epidist_validate(data) +epidist_validate(data, ...) } \arguments{ \item{data}{A \code{data.frame} containing line list data.} + +\item{...}{Additional arguments passed to method.} } \description{ This function validates that the provided \code{data} is suitable to run a From 79ff399cfe348f384bb8fa8aaf8a69ca5d4b3fe4 Mon Sep 17 00:00:00 2001 From: athowes Date: Tue, 15 Oct 2024 10:37:24 +0100 Subject: [PATCH 08/12] Remove whitespace --- R/fit.R | 2 -- 1 file changed, 2 deletions(-) diff --git a/R/fit.R b/R/fit.R index d1697e3cf..b712cf350 100644 --- a/R/fit.R +++ b/R/fit.R @@ -54,8 +54,6 @@ epidist.default <- function(data, formula = brms::bf(mu ~ 1), formula = epidist_formula, family = epidist_family, prior = epidist_prior, stanvars = epidist_stancode, backend = backend, data = data, ... ) - class(fit) <- c(class(fit), "epidist_fit") - return(fit) } From 53babbd422def5590e3b2f5ac898a2cc85f032c6 Mon Sep 17 00:00:00 2001 From: athowes Date: Tue, 15 Oct 2024 11:02:47 +0100 Subject: [PATCH 09/12] Fix R CMD CHECK warning --- R/latent_individual.R | 3 ++- man/epidist_validate.epidist_latent_individual.Rd | 4 +++- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/R/latent_individual.R b/R/latent_individual.R index 55c8d7211..86146e106 100644 --- a/R/latent_individual.R +++ b/R/latent_individual.R @@ -72,10 +72,11 @@ as_latent_individual.data.frame <- function(data) { #' `data.frame` with the correct columns. #' #' @param data A `data.frame` containing line list data +#' @param ... ... #' @method epidist_validate epidist_latent_individual #' @family latent_individual #' @export -epidist_validate.epidist_latent_individual <- function(data) { +epidist_validate.epidist_latent_individual <- function(data, ...) { assert_true(is_latent_individual(data)) assert_latent_individual_input(data) assert_names( diff --git a/man/epidist_validate.epidist_latent_individual.Rd b/man/epidist_validate.epidist_latent_individual.Rd index 81d82e537..986b13ded 100644 --- a/man/epidist_validate.epidist_latent_individual.Rd +++ b/man/epidist_validate.epidist_latent_individual.Rd @@ -4,10 +4,12 @@ \alias{epidist_validate.epidist_latent_individual} \title{Validate latent individual model data} \usage{ -\method{epidist_validate}{epidist_latent_individual}(data) +\method{epidist_validate}{epidist_latent_individual}(data, ...) } \arguments{ \item{data}{A \code{data.frame} containing line list data} + +\item{...}{...} } \description{ This function checks whether the provided \code{data} object is suitable for From 264e95f7f2b7516f3833a1a1089e8d5c5a1fe8a2 Mon Sep 17 00:00:00 2001 From: athowes Date: Tue, 15 Oct 2024 21:41:10 +0100 Subject: [PATCH 10/12] Return NULL by default for stancode --- R/stancode.R | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/R/stancode.R b/R/stancode.R index 674941e2e..669e7cf22 100644 --- a/R/stancode.R +++ b/R/stancode.R @@ -21,8 +21,5 @@ epidist_stancode <- function(data, ...) { #' @family stan #' @export epidist_stancode.default <- function(data, ...) { - cli_abort( - "No epidist_stancode method implemented for the class ", class(data), "\n", - "See methods(epidist_stancode) for available methods" - ) + return(NULL) } From 934c204c796263de5d75f614dde7203a3671050a Mon Sep 17 00:00:00 2001 From: athowes Date: Tue, 15 Oct 2024 22:02:58 +0100 Subject: [PATCH 11/12] Add test of Stan code NULL case --- tests/testthat/test-stancode.R | 3 +++ 1 file changed, 3 insertions(+) create mode 100644 tests/testthat/test-stancode.R diff --git a/tests/testthat/test-stancode.R b/tests/testthat/test-stancode.R new file mode 100644 index 000000000..898740509 --- /dev/null +++ b/tests/testthat/test-stancode.R @@ -0,0 +1,3 @@ +test_that("epidist_stancode.default returns NULL", { # nolint: line_length_linter. + expect_null(epidist_stancode(data.frame())) +}) From ff01e8aefd97328e768cfda4dca4fd3df7d37fb8 Mon Sep 17 00:00:00 2001 From: athowes Date: Tue, 15 Oct 2024 23:12:58 +0100 Subject: [PATCH 12/12] Add test for stanvars class --- tests/testthat/test-latent_individual.R | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/tests/testthat/test-latent_individual.R b/tests/testthat/test-latent_individual.R index 9aafac4c5..5675c4c96 100644 --- a/tests/testthat/test-latent_individual.R +++ b/tests/testthat/test-latent_individual.R @@ -50,5 +50,12 @@ test_that("epidist_validate.epidist_latent_individual returns FALSE for incorrec }) test_that("epidist_stancode.epidist_latent_individual produces valid stanvars", { # nolint: line_length_linter. - expect_equal(1, 1) + epidist_family <- epidist_family(prep_obs) + epidist_formula <- epidist_formula( + prep_obs, epidist_family, formula = brms::bf(mu ~ 1) + ) + stancode <- epidist_stancode( + prep_obs, family = epidist_family, formula = epidist_formula + ) + expect_s3_class(stancode, "stanvars") })