Skip to contents

Calculates negative log-likelihood (deviance) for one antigen:isotype pair and several values of incidence (lambda).

Usage

f_dev(lambda, csdata, lnpars, cond)

Arguments

lambda

a numeric vector of incidence parameters, in events per person-year

Value

a numeric vector of negative log-likelihoods, corresponding to the elements of input lambda

Details

Vectorized version of f_dev0(); interface with C lib serocalc.so

Examples

# \donttest{
library(dplyr)
library(tibble)

# load in longitudinal parameters
curve_params = load_curve_params("https://osf.io/download/rtw5k")
xs_data <- "https://osf.io/download//n6cp3/" %>%
load_pop_data()

#Load noise params
noise_params <- 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)

cur_antibody = "HlyE_IgA"

cur_data =
  xs_data %>%
  dplyr::filter(
   .data$catchment == "dhaka",
   .data$antigen_iso == cur_antibody) %>%
  dplyr::slice_head(n = 100)

cur_curve_params =
  curve_params %>%
  dplyr::filter(.data$antigen_iso == cur_antibody) %>%
  dplyr::slice_head(n = 100)

cur_noise_params =
  noise_params %>%
  dplyr::filter(.data$antigen_iso == cur_antibody)

if(!is.element('d', names(cur_curve_params)))
{
  cur_curve_params =
    cur_curve_params %>%
    dplyr::mutate(
      alpha = .data$alpha * 365.25,
      d = .data$r - 1)
}

lambdas = seq(.1, .2, by = .01)
f_dev(
    lambda = lambdas,
    csdata = cur_data,
    lnpars = cur_curve_params,
    cond = cur_noise_params
  )
#>  [1] 390.8284 383.8554 377.6242 372.0178 366.9449 362.3328 358.1226 354.2657
#>  [9] 350.7216 347.4560 344.4397
# }