diff --git a/NEWS.md b/NEWS.md index aa0f4736..f03a344b 100644 --- a/NEWS.md +++ b/NEWS.md @@ -2,6 +2,8 @@ ## New features +* Added default value for `antigen_isos` argument in `log_likelihood()` (#286) + * Updated enteric fever example article with upgraded code and visualizations (#290) * Added template for reporting Issues diff --git a/R/llik.R b/R/log_likelihood.R similarity index 70% rename from R/llik.R rename to R/log_likelihood.R index 47b6c6d3..2022a83c 100644 --- a/R/llik.R +++ b/R/log_likelihood.R @@ -1,7 +1,9 @@ -#' Calculate log-likelihood +#' @title Calculate log-likelihood #' #' @description -#' Calculates the log-likelihood of a set of cross-sectional antibody response data, for a given incidence rate (`lambda`) value. +#' Calculates the log-likelihood of a set of cross-sectional antibody response +#' data, for a given incidence rate (`lambda`) value. +#' #' `r lifecycle::badge("deprecated")` #' #' `llik()` was renamed to [log_likelihood()] to create a more @@ -9,47 +11,45 @@ #' #' @keywords internal #' @export - -llik <- function( - lambda, - pop_data, - antigen_isos, - curve_params, - noise_params, - verbose = FALSE, - ...) { +llik <- function(...) { lifecycle::deprecate_warn("1.0.0", "llik()", "log_likelihood()") - log_likelihood(lambda, - pop_data, - antigen_isos, - curve_params, - noise_params, - verbose) + log_likelihood(...) } -#' Calculate log-likelihood +#' @title Calculate log-likelihood #' #' @description -#' Calculates the log-likelihood of a set of cross-sectional antibody response data, for a given incidence rate (`lambda`) value. -#' @param pop_data a [data.frame()] with cross-sectional serology data per antibody and age, and additional columns -#' @param antigen_isos Character vector listing one or more antigen isotypes. Values must match `pop_data`. -#' @param curve_params a [data.frame()] containing MCMC samples of parameters from the Bayesian posterior distribution of a longitudinal decay curve model. The parameter columns must be named: -#' - `antigen_iso`: a [character()] vector indicating antigen-isotype combinations +#' Calculates the log-likelihood of a set of cross-sectional antibody response +#' data, for a given incidence rate (`lambda`) value. +#' @param pop_data a [data.frame()] with cross-sectional serology data +#' by antibody and age, and additional columns +#' @param antigen_isos Character vector listing one or more antigen isotypes. +#' Values must match `pop_data`. +#' @param curve_params a [data.frame()] containing MCMC samples of parameters +#' from the Bayesian posterior distribution of a longitudinal decay curve model. +#' The parameter columns must be named: +#' - `antigen_iso`: a [character()] vector indicating antigen-isotype +#' combinations #' - `iter`: an [integer()] vector indicating MCMC sampling iterations #' - `y0`: baseline antibody level at $t=0$ ($y(t=0)$) #' - `y1`: antibody peak level (ELISA units) #' - `t1`: duration of infection -#' - `alpha`: antibody decay rate (1/days for the current longitudinal parameter sets) +#' - `alpha`: antibody decay rate +#' (1/days for the current longitudinal parameter sets) #' - `r`: shape factor of antibody decay -#' @param noise_params a [data.frame()] (or [tibble::tibble()]) containing the following variables, specifying noise parameters for each antigen isotype: -#' * `antigen_iso`: antigen isotype whose noise parameters are being specified on each row +#' @param noise_params a [data.frame()] (or [tibble::tibble()]) +#' containing the following variables, +#' specifying noise parameters for each antigen isotype: +#' * `antigen_iso`: antigen isotype whose noise parameters are being specified +#' on each row #' * `nu`: biological noise #' * `eps`: measurement noise #' * `y.low`: lower limit of detection for the current antigen isotype #' * `y.high`: upper limit of detection for the current antigen isotype #' #' @param verbose logical: if TRUE, print verbose log information to console -#' @param ... additional arguments passed to other functions (not currently used). +#' @param ... additional arguments passed to other functions +#' (not currently used). #' @inheritParams f_dev #' @return the log-likelihood of the data with the current parameter values #' @export @@ -84,19 +84,19 @@ llik <- function( log_likelihood <- function( lambda, pop_data, - antigen_isos, curve_params, noise_params, + antigen_isos = get_biomarker_levels(pop_data), verbose = FALSE, ...) { # Start with zero total - nllTotal <- 0 + nll_total <- 0 # Loop over antigen_isos - for (cur_antibody in antigen_isos) - { + for (cur_antibody in antigen_isos) { # the inputs can be lists, after `split(~antigen_ios)` - # this gives some speedups compared to running filter() every time .nll() is called + # this gives some speedups compared to running filter() every time .nll() + # is called if (!is.data.frame(pop_data)) { cur_data <- pop_data[[cur_antibody]] cur_curve_params <- curve_params[[cur_antibody]] @@ -124,7 +124,7 @@ log_likelihood <- function( } } - nllSingle <- + nll_single <- f_dev( lambda = lambda, csdata = cur_data, @@ -133,11 +133,12 @@ log_likelihood <- function( ) # if (!is.na(nllSingle)) # not meaningful for vectorized f_dev() - { - nllTotal <- nllTotal + nllSingle # DEM note: summing log likelihoods represents an independence assumption for multiple Antibodies, given time since seroconversion - } + nll_total <- nll_total + nll_single + # note: summing log likelihoods represents an independence assumption + # for multiple Antibodies, given time since seroconversion + } # Return total log-likelihood - return(-nllTotal) + return(-nll_total) } diff --git a/man/dot-nll.Rd b/man/dot-nll.Rd index 08ab530b..ba119ecf 100644 --- a/man/dot-nll.Rd +++ b/man/dot-nll.Rd @@ -12,21 +12,30 @@ \item{...}{ Arguments passed on to \code{\link[=log_likelihood]{log_likelihood}} \describe{ - \item{\code{pop_data}}{a \code{\link[=data.frame]{data.frame()}} with cross-sectional serology data per antibody and age, and additional columns} - \item{\code{antigen_isos}}{Character vector listing one or more antigen isotypes. Values must match \code{pop_data}.} - \item{\code{curve_params}}{a \code{\link[=data.frame]{data.frame()}} containing MCMC samples of parameters from the Bayesian posterior distribution of a longitudinal decay curve model. The parameter columns must be named: + \item{\code{pop_data}}{a \code{\link[=data.frame]{data.frame()}} with cross-sectional serology data +by antibody and age, and additional columns} + \item{\code{antigen_isos}}{Character vector listing one or more antigen isotypes. +Values must match \code{pop_data}.} + \item{\code{curve_params}}{a \code{\link[=data.frame]{data.frame()}} containing MCMC samples of parameters +from the Bayesian posterior distribution of a longitudinal decay curve model. +The parameter columns must be named: \itemize{ -\item \code{antigen_iso}: a \code{\link[=character]{character()}} vector indicating antigen-isotype combinations +\item \code{antigen_iso}: a \code{\link[=character]{character()}} vector indicating antigen-isotype +combinations \item \code{iter}: an \code{\link[=integer]{integer()}} vector indicating MCMC sampling iterations \item \code{y0}: baseline antibody level at $t=0$ ($y(t=0)$) \item \code{y1}: antibody peak level (ELISA units) \item \code{t1}: duration of infection -\item \code{alpha}: antibody decay rate (1/days for the current longitudinal parameter sets) +\item \code{alpha}: antibody decay rate +(1/days for the current longitudinal parameter sets) \item \code{r}: shape factor of antibody decay }} - \item{\code{noise_params}}{a \code{\link[=data.frame]{data.frame()}} (or \code{\link[tibble:tibble]{tibble::tibble()}}) containing the following variables, specifying noise parameters for each antigen isotype: + \item{\code{noise_params}}{a \code{\link[=data.frame]{data.frame()}} (or \code{\link[tibble:tibble]{tibble::tibble()}}) +containing the following variables, +specifying noise parameters for each antigen isotype: \itemize{ -\item \code{antigen_iso}: antigen isotype whose noise parameters are being specified on each row +\item \code{antigen_iso}: antigen isotype whose noise parameters are being specified +on each row \item \code{nu}: biological noise \item \code{eps}: measurement noise \item \code{y.low}: lower limit of detection for the current antigen isotype diff --git a/man/est.incidence.Rd b/man/est.incidence.Rd index 58b19797..ce207ed6 100644 --- a/man/est.incidence.Rd +++ b/man/est.incidence.Rd @@ -21,20 +21,27 @@ est.incidence( \arguments{ \item{pop_data}{a \link{data.frame} with cross-sectional serology data per antibody and age, and additional columns} -\item{curve_params}{a \code{\link[=data.frame]{data.frame()}} containing MCMC samples of parameters from the Bayesian posterior distribution of a longitudinal decay curve model. The parameter columns must be named: +\item{curve_params}{a \code{\link[=data.frame]{data.frame()}} containing MCMC samples of parameters +from the Bayesian posterior distribution of a longitudinal decay curve model. +The parameter columns must be named: \itemize{ -\item \code{antigen_iso}: a \code{\link[=character]{character()}} vector indicating antigen-isotype combinations +\item \code{antigen_iso}: a \code{\link[=character]{character()}} vector indicating antigen-isotype +combinations \item \code{iter}: an \code{\link[=integer]{integer()}} vector indicating MCMC sampling iterations \item \code{y0}: baseline antibody level at $t=0$ ($y(t=0)$) \item \code{y1}: antibody peak level (ELISA units) \item \code{t1}: duration of infection -\item \code{alpha}: antibody decay rate (1/days for the current longitudinal parameter sets) +\item \code{alpha}: antibody decay rate +(1/days for the current longitudinal parameter sets) \item \code{r}: shape factor of antibody decay }} -\item{noise_params}{a \code{\link[=data.frame]{data.frame()}} (or \code{\link[tibble:tibble]{tibble::tibble()}}) containing the following variables, specifying noise parameters for each antigen isotype: +\item{noise_params}{a \code{\link[=data.frame]{data.frame()}} (or \code{\link[tibble:tibble]{tibble::tibble()}}) +containing the following variables, +specifying noise parameters for each antigen isotype: \itemize{ -\item \code{antigen_iso}: antigen isotype whose noise parameters are being specified on each row +\item \code{antigen_iso}: antigen isotype whose noise parameters are being specified +on each row \item \code{nu}: biological noise \item \code{eps}: measurement noise \item \code{y.low}: lower limit of detection for the current antigen isotype diff --git a/man/est.incidence.by.Rd b/man/est.incidence.by.Rd index 123a4b16..3111521c 100644 --- a/man/est.incidence.by.Rd +++ b/man/est.incidence.by.Rd @@ -23,20 +23,27 @@ est.incidence.by( \arguments{ \item{pop_data}{a \link{data.frame} with cross-sectional serology data per antibody and age, and additional columns corresponding to each element of the \code{strata} input} -\item{curve_params}{a \code{\link[=data.frame]{data.frame()}} containing MCMC samples of parameters from the Bayesian posterior distribution of a longitudinal decay curve model. The parameter columns must be named: +\item{curve_params}{a \code{\link[=data.frame]{data.frame()}} containing MCMC samples of parameters +from the Bayesian posterior distribution of a longitudinal decay curve model. +The parameter columns must be named: \itemize{ -\item \code{antigen_iso}: a \code{\link[=character]{character()}} vector indicating antigen-isotype combinations +\item \code{antigen_iso}: a \code{\link[=character]{character()}} vector indicating antigen-isotype +combinations \item \code{iter}: an \code{\link[=integer]{integer()}} vector indicating MCMC sampling iterations \item \code{y0}: baseline antibody level at $t=0$ ($y(t=0)$) \item \code{y1}: antibody peak level (ELISA units) \item \code{t1}: duration of infection -\item \code{alpha}: antibody decay rate (1/days for the current longitudinal parameter sets) +\item \code{alpha}: antibody decay rate +(1/days for the current longitudinal parameter sets) \item \code{r}: shape factor of antibody decay }} -\item{noise_params}{a \code{\link[=data.frame]{data.frame()}} (or \code{\link[tibble:tibble]{tibble::tibble()}}) containing the following variables, specifying noise parameters for each antigen isotype: +\item{noise_params}{a \code{\link[=data.frame]{data.frame()}} (or \code{\link[tibble:tibble]{tibble::tibble()}}) +containing the following variables, +specifying noise parameters for each antigen isotype: \itemize{ -\item \code{antigen_iso}: antigen isotype whose noise parameters are being specified on each row +\item \code{antigen_iso}: antigen isotype whose noise parameters are being specified +on each row \item \code{nu}: biological noise \item \code{eps}: measurement noise \item \code{y.low}: lower limit of detection for the current antigen isotype diff --git a/man/graph.loglik.Rd b/man/graph.loglik.Rd index f4b51a69..ca953c30 100644 --- a/man/graph.loglik.Rd +++ b/man/graph.loglik.Rd @@ -19,29 +19,38 @@ graph.loglik( ) } \arguments{ -\item{pop_data}{a \code{\link[=data.frame]{data.frame()}} with cross-sectional serology data per antibody and age, and additional columns} +\item{pop_data}{a \code{\link[=data.frame]{data.frame()}} with cross-sectional serology data +by antibody and age, and additional columns} -\item{curve_params}{a \code{\link[=data.frame]{data.frame()}} containing MCMC samples of parameters from the Bayesian posterior distribution of a longitudinal decay curve model. The parameter columns must be named: +\item{curve_params}{a \code{\link[=data.frame]{data.frame()}} containing MCMC samples of parameters +from the Bayesian posterior distribution of a longitudinal decay curve model. +The parameter columns must be named: \itemize{ -\item \code{antigen_iso}: a \code{\link[=character]{character()}} vector indicating antigen-isotype combinations +\item \code{antigen_iso}: a \code{\link[=character]{character()}} vector indicating antigen-isotype +combinations \item \code{iter}: an \code{\link[=integer]{integer()}} vector indicating MCMC sampling iterations \item \code{y0}: baseline antibody level at $t=0$ ($y(t=0)$) \item \code{y1}: antibody peak level (ELISA units) \item \code{t1}: duration of infection -\item \code{alpha}: antibody decay rate (1/days for the current longitudinal parameter sets) +\item \code{alpha}: antibody decay rate +(1/days for the current longitudinal parameter sets) \item \code{r}: shape factor of antibody decay }} -\item{noise_params}{a \code{\link[=data.frame]{data.frame()}} (or \code{\link[tibble:tibble]{tibble::tibble()}}) containing the following variables, specifying noise parameters for each antigen isotype: +\item{noise_params}{a \code{\link[=data.frame]{data.frame()}} (or \code{\link[tibble:tibble]{tibble::tibble()}}) +containing the following variables, +specifying noise parameters for each antigen isotype: \itemize{ -\item \code{antigen_iso}: antigen isotype whose noise parameters are being specified on each row +\item \code{antigen_iso}: antigen isotype whose noise parameters are being specified +on each row \item \code{nu}: biological noise \item \code{eps}: measurement noise \item \code{y.low}: lower limit of detection for the current antigen isotype \item \code{y.high}: upper limit of detection for the current antigen isotype }} -\item{antigen_isos}{Character vector listing one or more antigen isotypes. Values must match \code{pop_data}.} +\item{antigen_isos}{Character vector listing one or more antigen isotypes. +Values must match \code{pop_data}.} \item{x}{sequence of lambda values to graph} diff --git a/man/llik.Rd b/man/llik.Rd index 38fa4961..4cf84bc8 100644 --- a/man/llik.Rd +++ b/man/llik.Rd @@ -1,21 +1,15 @@ % Generated by roxygen2: do not edit by hand -% Please edit documentation in R/llik.R +% Please edit documentation in R/log_likelihood.R \name{llik} \alias{llik} \title{Calculate log-likelihood} \usage{ -llik( - lambda, - pop_data, - antigen_isos, - curve_params, - noise_params, - verbose = FALSE, - ... -) +llik(...) } \description{ -Calculates the log-likelihood of a set of cross-sectional antibody response data, for a given incidence rate (\code{lambda}) value. +Calculates the log-likelihood of a set of cross-sectional antibody response +data, for a given incidence rate (\code{lambda}) value. + \ifelse{html}{\href{https://lifecycle.r-lib.org/articles/stages.html#deprecated}{\figure{lifecycle-deprecated.svg}{options: alt='[Deprecated]'}}}{\strong{[Deprecated]}} \code{llik()} was renamed to \code{\link[=log_likelihood]{log_likelihood()}} to create a more diff --git a/man/log_likelihood.Rd b/man/log_likelihood.Rd index ade719ab..7a9267e9 100644 --- a/man/log_likelihood.Rd +++ b/man/log_likelihood.Rd @@ -1,5 +1,5 @@ % Generated by roxygen2: do not edit by hand -% Please edit documentation in R/llik.R +% Please edit documentation in R/log_likelihood.R \name{log_likelihood} \alias{log_likelihood} \title{Calculate log-likelihood} @@ -7,9 +7,9 @@ log_likelihood( lambda, pop_data, - antigen_isos, curve_params, noise_params, + antigen_isos = get_biomarker_levels(pop_data), verbose = FALSE, ... ) @@ -17,39 +17,50 @@ log_likelihood( \arguments{ \item{lambda}{a \link{numeric} vector of incidence parameters, in events per person-year} -\item{pop_data}{a \code{\link[=data.frame]{data.frame()}} with cross-sectional serology data per antibody and age, and additional columns} +\item{pop_data}{a \code{\link[=data.frame]{data.frame()}} with cross-sectional serology data +by antibody and age, and additional columns} -\item{antigen_isos}{Character vector listing one or more antigen isotypes. Values must match \code{pop_data}.} - -\item{curve_params}{a \code{\link[=data.frame]{data.frame()}} containing MCMC samples of parameters from the Bayesian posterior distribution of a longitudinal decay curve model. The parameter columns must be named: +\item{curve_params}{a \code{\link[=data.frame]{data.frame()}} containing MCMC samples of parameters +from the Bayesian posterior distribution of a longitudinal decay curve model. +The parameter columns must be named: \itemize{ -\item \code{antigen_iso}: a \code{\link[=character]{character()}} vector indicating antigen-isotype combinations +\item \code{antigen_iso}: a \code{\link[=character]{character()}} vector indicating antigen-isotype +combinations \item \code{iter}: an \code{\link[=integer]{integer()}} vector indicating MCMC sampling iterations \item \code{y0}: baseline antibody level at $t=0$ ($y(t=0)$) \item \code{y1}: antibody peak level (ELISA units) \item \code{t1}: duration of infection -\item \code{alpha}: antibody decay rate (1/days for the current longitudinal parameter sets) +\item \code{alpha}: antibody decay rate +(1/days for the current longitudinal parameter sets) \item \code{r}: shape factor of antibody decay }} -\item{noise_params}{a \code{\link[=data.frame]{data.frame()}} (or \code{\link[tibble:tibble]{tibble::tibble()}}) containing the following variables, specifying noise parameters for each antigen isotype: +\item{noise_params}{a \code{\link[=data.frame]{data.frame()}} (or \code{\link[tibble:tibble]{tibble::tibble()}}) +containing the following variables, +specifying noise parameters for each antigen isotype: \itemize{ -\item \code{antigen_iso}: antigen isotype whose noise parameters are being specified on each row +\item \code{antigen_iso}: antigen isotype whose noise parameters are being specified +on each row \item \code{nu}: biological noise \item \code{eps}: measurement noise \item \code{y.low}: lower limit of detection for the current antigen isotype \item \code{y.high}: upper limit of detection for the current antigen isotype }} +\item{antigen_isos}{Character vector listing one or more antigen isotypes. +Values must match \code{pop_data}.} + \item{verbose}{logical: if TRUE, print verbose log information to console} -\item{...}{additional arguments passed to other functions (not currently used).} +\item{...}{additional arguments passed to other functions +(not currently used).} } \value{ the log-likelihood of the data with the current parameter values } \description{ -Calculates the log-likelihood of a set of cross-sectional antibody response data, for a given incidence rate (\code{lambda}) value. +Calculates the log-likelihood of a set of cross-sectional antibody response +data, for a given incidence rate (\code{lambda}) value. } \examples{ library(dplyr) diff --git a/man/sim.cs.Rd b/man/sim.cs.Rd index 74b2ccd0..01bae0a6 100644 --- a/man/sim.cs.Rd +++ b/man/sim.cs.Rd @@ -45,14 +45,18 @@ sim.cs( \item{add.noise}{a \code{\link[=logical]{logical()}} indicating whether to add biological and measurement noise} -\item{curve_params}{a \code{\link[=data.frame]{data.frame()}} containing MCMC samples of parameters from the Bayesian posterior distribution of a longitudinal decay curve model. The parameter columns must be named: +\item{curve_params}{a \code{\link[=data.frame]{data.frame()}} containing MCMC samples of parameters +from the Bayesian posterior distribution of a longitudinal decay curve model. +The parameter columns must be named: \itemize{ -\item \code{antigen_iso}: a \code{\link[=character]{character()}} vector indicating antigen-isotype combinations +\item \code{antigen_iso}: a \code{\link[=character]{character()}} vector indicating antigen-isotype +combinations \item \code{iter}: an \code{\link[=integer]{integer()}} vector indicating MCMC sampling iterations \item \code{y0}: baseline antibody level at $t=0$ ($y(t=0)$) \item \code{y1}: antibody peak level (ELISA units) \item \code{t1}: duration of infection -\item \code{alpha}: antibody decay rate (1/days for the current longitudinal parameter sets) +\item \code{alpha}: antibody decay rate +(1/days for the current longitudinal parameter sets) \item \code{r}: shape factor of antibody decay }} diff --git a/man/sim.cs.multi.Rd b/man/sim.cs.multi.Rd index 3f8cd593..fe2204cc 100644 --- a/man/sim.cs.multi.Rd +++ b/man/sim.cs.multi.Rd @@ -53,14 +53,18 @@ sim.cs.multi( \item \code{"long"} (one measurement per row) or \item \code{"wide"} (one serum sample per row) }} - \item{\code{curve_params}}{a \code{\link[=data.frame]{data.frame()}} containing MCMC samples of parameters from the Bayesian posterior distribution of a longitudinal decay curve model. The parameter columns must be named: + \item{\code{curve_params}}{a \code{\link[=data.frame]{data.frame()}} containing MCMC samples of parameters +from the Bayesian posterior distribution of a longitudinal decay curve model. +The parameter columns must be named: \itemize{ -\item \code{antigen_iso}: a \code{\link[=character]{character()}} vector indicating antigen-isotype combinations +\item \code{antigen_iso}: a \code{\link[=character]{character()}} vector indicating antigen-isotype +combinations \item \code{iter}: an \code{\link[=integer]{integer()}} vector indicating MCMC sampling iterations \item \code{y0}: baseline antibody level at $t=0$ ($y(t=0)$) \item \code{y1}: antibody peak level (ELISA units) \item \code{t1}: duration of infection -\item \code{alpha}: antibody decay rate (1/days for the current longitudinal parameter sets) +\item \code{alpha}: antibody decay rate +(1/days for the current longitudinal parameter sets) \item \code{r}: shape factor of antibody decay }} }} diff --git a/man/stratify_data.Rd b/man/stratify_data.Rd index 7dacbcbb..fba7c6f0 100644 --- a/man/stratify_data.Rd +++ b/man/stratify_data.Rd @@ -15,20 +15,27 @@ stratify_data( ) } \arguments{ -\item{curve_params}{a \code{\link[=data.frame]{data.frame()}} containing MCMC samples of parameters from the Bayesian posterior distribution of a longitudinal decay curve model. The parameter columns must be named: +\item{curve_params}{a \code{\link[=data.frame]{data.frame()}} containing MCMC samples of parameters +from the Bayesian posterior distribution of a longitudinal decay curve model. +The parameter columns must be named: \itemize{ -\item \code{antigen_iso}: a \code{\link[=character]{character()}} vector indicating antigen-isotype combinations +\item \code{antigen_iso}: a \code{\link[=character]{character()}} vector indicating antigen-isotype +combinations \item \code{iter}: an \code{\link[=integer]{integer()}} vector indicating MCMC sampling iterations \item \code{y0}: baseline antibody level at $t=0$ ($y(t=0)$) \item \code{y1}: antibody peak level (ELISA units) \item \code{t1}: duration of infection -\item \code{alpha}: antibody decay rate (1/days for the current longitudinal parameter sets) +\item \code{alpha}: antibody decay rate +(1/days for the current longitudinal parameter sets) \item \code{r}: shape factor of antibody decay }} -\item{noise_params}{a \code{\link[=data.frame]{data.frame()}} (or \code{\link[tibble:tibble]{tibble::tibble()}}) containing the following variables, specifying noise parameters for each antigen isotype: +\item{noise_params}{a \code{\link[=data.frame]{data.frame()}} (or \code{\link[tibble:tibble]{tibble::tibble()}}) +containing the following variables, +specifying noise parameters for each antigen isotype: \itemize{ -\item \code{antigen_iso}: antigen isotype whose noise parameters are being specified on each row +\item \code{antigen_iso}: antigen isotype whose noise parameters are being specified +on each row \item \code{nu}: biological noise \item \code{eps}: measurement noise \item \code{y.low}: lower limit of detection for the current antigen isotype diff --git a/tests/testthat/_snaps/log_likelihood.md b/tests/testthat/_snaps/log_likelihood.md new file mode 100644 index 00000000..4fd146e4 --- /dev/null +++ b/tests/testthat/_snaps/log_likelihood.md @@ -0,0 +1,4 @@ +# `log_likelihood()` gives consistent results + + -9268.8238 + diff --git a/tests/testthat/test-log_likelihood.R b/tests/testthat/test-log_likelihood.R new file mode 100644 index 00000000..0a4e3d72 --- /dev/null +++ b/tests/testthat/test-log_likelihood.R @@ -0,0 +1,34 @@ +test_that("`log_likelihood()` gives consistent results", { + library(dplyr) + library(tibble) + + # load in longitudinal parameters + dmcmc <- load_curve_params("https://osf.io/download/rtw5k") + + xs_data <- "https://osf.io/download//n6cp3/" %>% + load_pop_data() + + # Load noise params + cond <- tibble( + antigen_iso = c("HlyE_IgG", "HlyE_IgA"), + nu = c(0.5, 0.5), + # Biologic noise (nu) + eps = c(0, 0), + # M noise (eps) + y.low = c(1, 1), + # low cutoff (llod) + y.high = c(5e6, 5e6) + ) # high cutoff (y.high) + + # Calculate log-likelihood + ll_AG <- log_likelihood( # nolint: object_name_linter + pop_data = xs_data, + curve_params = dmcmc, + noise_params = cond, + antigen_isos = c("HlyE_IgG", "HlyE_IgA"), + lambda = 0.1 + ) + + expect_snapshot_value(ll_AG) + +})