From 776212cd5e24124273ce963b61fee471a3c3f2ea Mon Sep 17 00:00:00 2001 From: Douglas Ezra Morrison Date: Fri, 17 Nov 2023 16:13:41 -0800 Subject: [PATCH] delete out-of-date vignettes (for now) --- vignettes/example-analysis.Rmd | 117 ------ vignettes/installation.Rmd | 116 ------ vignettes/methodology.Rmd | 428 ------------------- vignettes/simulation.Rmd | 61 --- vignettes/tutorial.Rmd | 614 ---------------------------- vignettes/typhoid-controls.Rmd | 29 -- vignettes/typhoid-seroincidence.Rmd | 135 ------ 7 files changed, 1500 deletions(-) delete mode 100644 vignettes/example-analysis.Rmd delete mode 100644 vignettes/installation.Rmd delete mode 100644 vignettes/methodology.Rmd delete mode 100644 vignettes/simulation.Rmd delete mode 100644 vignettes/tutorial.Rmd delete mode 100644 vignettes/typhoid-controls.Rmd delete mode 100644 vignettes/typhoid-seroincidence.Rmd diff --git a/vignettes/example-analysis.Rmd b/vignettes/example-analysis.Rmd deleted file mode 100644 index 5b29d02e..00000000 --- a/vignettes/example-analysis.Rmd +++ /dev/null @@ -1,117 +0,0 @@ ---- -title: "example-analysis" -output: - rmarkdown::html_vignette: - toc: yes -vignette: > - %\VignetteIndexEntry{example-analysis} - %\VignetteEngine{knitr::rmarkdown} - %\VignetteEncoding{UTF-8} ---- - -```{r, include = FALSE} -knitr::opts_chunk$set( - collapse = TRUE, - comment = "#>" -) -``` - -```{r setup} -library(serocalculator) -library(Hmisc) -library(dplyr) -``` - -```{r "load data"} - -# load longitudinal parameter MC sample -fs::path_package( - "extdata", - "pertussis-iggpt2.rda", - package = "serocalculator") |> - load() # output: longpar.mc - -lp = longpar.mc$IgG -day2yr <- 365.25; -ln.pars <- data.frame( - y1 = lp$y1, # peak levels - alpha = day2yr * lp$alpha, # decay rate (per year) - d = lp$r -1); # shape (r-1 offset from exp) - -library(readr) -#read simulated data -raw.data = fs::path_package( - "extdata", - "SimulDat.txt", - package = "serocalculator") |> - readr::read_table() |> - rename(AGE = '"AGE"', IgG = '"IgG"') - -``` - -```{r} - -cat.bnd = seq(0,80,by=5); -n.cats = length(cat.bnd)-1; # define age categories -age.cat = cut(raw.data$AGE, breaks = cat.bnd, right = FALSE) |> as.numeric() - -clean.data = data.frame( - age = floor(raw.data$AGE) + 0.5, - IgG = raw.data$IgG, - cat = age.cat) - -# define global parameters -cond <- data.frame( - nu=2.5, # B noise - eps=0.3, # M noise - y.low=2.5, # low cutoff - y.high=5e4); # high cutoff - -lambda = 0.015 # initial estimate: starting value -log.lambda = log(lambda) -log.lmin = log(lambda/10); -log.lmax=log(10*lambda) # seroincidence rate interval -log.lambda.est = matrix(0, nrow=n.cats, ncol=6, - dimnames = list( - rep("",n.cats), - c("","ml.est", "lwr0.05", "upr0.95", - "LLF","N iter."))) -# loop over age categories -system.time( - for (k.cat in 1:n.cats) # per age category - { - cat(k.cat,"\n") - y.cat = as.vector(subset(clean.data,subset=clean.data$cat==as.character(k.cat), - select="IgG"))$IgG; - a.cat = as.vector(subset(clean.data,subset=clean.data$cat==as.character(k.cat), - select="age"))$age; - cs.data <- data.frame(y=y.cat, a=a.cat); - objfunc <- function(llam){ - # add terms, e.g. for other antibodies - # res < fdev(llam,cs1,ln1,cond1) + fdev(llam,cs2,ln2,cond2) + ... - # return(res) - return(fdev(llam,cs.data,ln.pars,cond)); - } - # seroincidence estimation - - fit = nlm(objfunc,log.lambda, - hessian=TRUE,print.level=0,stepmax=(log.lmax-log.lmin)/4); - - log.lambda.est[k.cat,] = c(k.cat, - fit$estimate, - fit$estimate + qnorm(c(0.05))*sqrt(1/fit$hessian), - fit$estimate + qnorm(c(0.95))*sqrt(1/fit$hessian), - fit$minimum, - fit$iterations) - - log.lambda=log.lambda.est[k.cat,2] - }) - -``` - -```{r} -# check results in log.lambda.est: -pander::pander(log.lambda.est) - -``` - diff --git a/vignettes/installation.Rmd b/vignettes/installation.Rmd deleted file mode 100644 index 7cbdcd20..00000000 --- a/vignettes/installation.Rmd +++ /dev/null @@ -1,116 +0,0 @@ ---- -title: "Serocalculator package installation manual" -author: "UC Davis Seroepidemiology Research Group (SERG)" -date: "`r Sys.Date()`" -output: - rmarkdown::html_vignette: - toc: yes - pdf_document: - toc: yes -header-includes: -- \setkeys{Gin}{height=2.8in, keepaspectratio} - \DeclareUnicodeCharacter{2010}{-} -vignette: > - %\VignetteIndexEntry{Serocalculator package installation manual} - %\VignetteEngine{knitr::rmarkdown} - %\VignetteEncoding{UTF-8} ---- - -```{r, echo = FALSE} -# Grab package version and date from DESCRIPTION file. -pkgName = "serocalculator" -pkgVersion <- packageDescription(pkgName)$Version -pkgDate <- packageDescription(pkgName)$Date -pkgBaseFileName <- paste(pkgName, pkgVersion, sep = "_") -pkgUrl <- gsub("\n", "", packageDescription(pkgName)$URL) -pkgPath <- "https://ucd-serg.github.io/serocalculator/" -library("knitr") -``` - -\newpage - -# 1. Introduction - -Package **`r pkgName`** is written in programming language R and end user must have access to a -working installation of R engine. This document describes the most common setup with R installed -locally on the user's computer. The screenshots refer to the classical R interface, but the package -can also be opened in other Graphical User Interfaces for R like e.g. -[RStudio](http://www.rstudio.com/products/RStudio/). - -# 2. Installation steps - -R is a free software program and can be downloaded from [http://cran.r-project.org/](http://cran.r-project.org/). -After downloading the appropriate version for your computer's operating system, install R on your computer following the standard procedure -applicable to the operating system. For Windows the file to be downloaded is the so-called *base* -distribution: [http://cran.r-project.org/bin/windows/base/](http://cran.r-project.org/bin/windows/base/). - -## 2.1. Installing R - -Start the R installer and follow the presented steps: - -```{r echo=FALSE, fig.pos="!h", fig.align='center'} -include_graphics("fig/setup1.png") -``` - -It is advised to have R installed in folder that does not contain spaces, therefore please adjust -the destination location accordingly: - -```{r echo=FALSE, fig.pos="!h", fig.align='center'} -include_graphics("fig/setup2.png") -``` - -The **serocalculator** package is compatible with both the 32-bit and the 64-bit version of R. -Choose the preferred platform (or both). If unsure install the 32-bit version only, however -on compatible platforms the 64-bit version may provide better performance: - -```{r echo=FALSE, fig.pos="!h", fig.align='center'} -include_graphics("fig/setup3.png") -``` - -It is advised to select *Registry entries* in the next step for best experience: - -```{r echo=FALSE, fig.pos="!h", fig.align='center'} -include_graphics("fig/setup4.png") -``` - -R interpreter, when installed on Windows, can be invoked from the start menu folder named **R**. - -Start the preferred version of R (if both the 32-bit: *R i386* and the 64-bit: *x64* are installed). -Graphical user interface for R interpreter will start in a new window: - -```{r echo=FALSE, fig.pos="!h", fig.align='center'} -include_graphics("fig/RGui1.png") -``` - -## 2.2. Installing *serocalculator* package - -Since this is a new installation of R, the **serocalculator** package must be installed before first use. As of 09/20/2023, **serocalculator** is still in development. To install the development version, you must install the **devtools** package and then download **serocalculator** from GitHub. - -```r -install.packages("devtools") -devtools::install_github("ucd-serg/serocalculator") -``` - -# 3. Post-installation - -Successful installation can be confirmed by loading the package into the workspace -and exploring help files and manuals distributed with the package: -```{r, eval=FALSE} -# Load package "seroincidence". -library(serocalculator) - -# Show R help for the package. -?serocalculator - -# Show tutorial for the package. -vignette(topic = "tutorial", package = "serocalculator") -``` - -Additionally, most package details can be found when executing the following commands: -```{r} -# Show description. -packageDescription("serocalculator") - -# Show citation. -citation("serocalculator") -``` diff --git a/vignettes/methodology.Rmd b/vignettes/methodology.Rmd deleted file mode 100644 index b77b59a0..00000000 --- a/vignettes/methodology.Rmd +++ /dev/null @@ -1,428 +0,0 @@ ---- -title: "Serocalculator package methodology" -author: "European Centre for Disease Prevention and Control (ECDC)" -date: '`r Sys.Date()`' -output: - rmarkdown::html_vignette: - toc: yes - pdf_document: - toc: yes -header-includes: -- \usepackage{subfigure} - \DeclareUnicodeCharacter{2010}{-} -references: -- id: teunis_etal12_biomarker - DOI: 10.1002/sim.5322 - author: - - family: Teunis - given: P. F. M. - - family: van Eijkeren - given: J. C. - - family: Ang - given: C. W. - - family: van Duynhoven - given: Y. T. - - family: Simonsen - given: J. B. - - family: Strid - given: M. A. - - family: van Pelt - given: W. - container-title: Statistics in Medicine - issue: 20 - issued: - month: 9 - year: 2012 - page: 2240-2248 - title: 'Biomarker dynamics: estimating infection rates from serological data' - type: article-journal - volume: 31 -- id: degraaf_etal14wh - author: - - family: de Graaf - given: W. F. - - family: Kretzschmar - given: M. E. E. - - family: Teunis - given: P. F. M. - - family: Diekmann - given: O. - container-title: Epidemics - DOI: 10.1016/j.epidem.2014.08.002 - issued: - month: 12 - year: 2014 - page: 1-7 - title: 'A two-phase within-host model for immune response and its application to serological profiles of pertussis' - type: article-journal - volume: 9 -- id: teunis_etal16withinhost - author: - - family: Teunis - given: P. F. M. - - family: van Eijkeren - given: J. C. - - family: de Graaf - given: W. F. - - family: Bonačić Marinović - given: A. - - family: Kretzschmar - given: M. E. E. - container-title: Epidemics - DOI: 10.1016/j.epidem.2016.04.001 - issued: - month: 9 - year: 2016 - page: 33-39 - title: 'Linking the seroresponse to infection to within-host heterogeneity in antibody production' - type: article-journal - volume: 16 -- id: satten_etal04 - author: - - family: Satten - given: G. A. - - family: Kong - given: F. - - family: Wright - given: D. J. - - family: Glynn - given: S. A. - - family: Schreiber - given: G. B. - container-title: Biostatistics - DOI: 10.1093/biostatistics/5.1.145 - issued: - month: 1 - year: 2004 - page: 145-151 - title: 'How special is a ‘special’ interval: modeling departure from length‐biased sampling in renewal processes' - type: article-journal - volume: 5 - issue: 1 -- id: zelen04 - author: - - family: Zelen - given: M. - container-title: Lifetime Data Analysis - issued: - month: 12 - year: 2004 - page: 325-334 - title: 'Forward and backward recurrence times and length biased sampling: age specific models' - type: article-journal - volume: 10 - issue: 4 -- id: degreeff_etal12 - author: - - family: de Greeff - given: S. C. - - family: Teunis - given: P. F. M. - - family: de Melker - given: H. E. - - family: Mooi - given: F. R. - - family: Notermans - given: D. W. - - family: Elvers - given: B. - - family: Schellekens - given: J. F. P. - container-title: Clinical and Vaccine Immunology - DOI: 10.1128/CVI.00229-12 - issued: - month: 9 - year: 2012 - page: 1452-1456 - title: 'Two-Component Cluster Analysis of a Large Serodiagnostic Database for Specificity of Increases of IgG Antibodies against Pertussis Toxin in Paired Serum Samples and of Absolute Values in Single Serum Samples' - type: article-journal - volume: 19 - issue: 9 -fontsize: 11pt -vignette: > - %\VignetteIndexEntry{Serocalculator package methodology} - %\VignetteEngine{knitr::rmarkdown} - %\VignetteEncoding{UTF-8} ---- - - - -\newpage - -# Introduction - -The revised seroincidence calculator package provides three refinements to the method for -calculating seroincidence published earlier [@teunis_etal12_biomarker] and implemented in R package -**seroincidence**, versions 1.x: (1) inclusion of infection episode with rising antibody levels, (2) -non--exponential decay of serum antibodies after infection, and (3) age--dependent correction for -subjects who have never seroconverted. It is important to note that, although the implemented -methods use a specific parametric model, as proposed in [@degraaf_etal14wh] and augmented in -[@teunis_etal16withinhost], the methods used to calculate the likelihood function allow -seroresponses of arbitrary shape. - -# 1. A simple model for the seroresponse - -The current version of the serocalculator package uses the model of [@teunis_etal16withinhost] for -the shape of the seroresponse: -$$ -\begin{array}{l@{\qquad}l} -\text{Infection/colonization episode} & \text{Waning immunity episode}\\ -b^{\prime}(t) = \mu_{0}b(t) - cy(t) & b(t) = 0 \\ -y^{\prime}(t) = \mu y(t) & y^{\prime}(t) = -\nu y(t)^r \\ -\end{array} -$$ - -With baseline antibody concentration $y(0) = y_{0}$ and initial pathogen concentration -$b(0) = b_{0}$. The serum antibody response $y(t)$ can be written as -$$ -y(t) = y_{+}(t) + y_{-}(t) -$$ -where -\begin{align*} -y_{+}(t) & = y_{0}\text{e}^{\mu t}[0\le t 1$, -log concentrations decrease rapidly after infection has terminated, but decay then slows down and -low antibody concentrations are maintained for a long period. When $r$ approaches 1, exponential -decay is restored. - -# 2. Backward recurrence time - -Considering the (fundamental) uniform distribution $u_{f}$ of sampling within a given interval, the -interval length distribution $p(\Delta t)$ and the distribution of (cross--sectionally) sampled -interval length [@teunis_etal12_biomarker] -$$ -q(\Delta t) = \frac{p(\Delta t)\cdot\Delta t}{\overline{\Delta t_{p}}} -$$ -the joint distribution of backward recurrence time and cross--sectional interval length is the -product $u_{f}\cdot q$ because these probabilities are independent. - -The distribution of backward recurrence time is the marginal distribution -\begin{align*} -u(\tau) & = \int_{\Delta t=0}^{\infty} u_{f}(\tau;\Delta t)\cdot q(\Delta t)\text{d}\Delta t\\ - & = \int_{0}^{\infty}\frac{[0\le\tau\le\Delta t]}{\Delta t}\cdot \frac{p(\Delta t)\cdot - \Delta t}{\overline{\Delta t_{p}}}\text{d}\Delta t\\ - & = \frac{1}{\overline{\Delta t_{p}}}\int_{\tau}^{\infty}p(\Delta t)\text{d}\Delta t -\end{align*} - -# 3. Incidence of seroconversions - -To calculate the incidence of seroconversions, as in [@teunis_etal12_biomarker], the distribution -$p(\Delta t)$ of intervals $\Delta t$ between seroconversions, is important. Assuming any subject is -sampled completely at random during their intervals between seroconversions, and accounting for -interval length bias [@satten_etal04; @zelen04], the distribution of backward recurrence times -$\tau$ can be written as [@teunis_etal12_biomarker] -$$ -u(\tau) = \frac{1}{\overline{\Delta t}} \int_{\tau=0}^{\infty}p(\Delta t)\text{d}\Delta t - = \frac{1-P(\Delta t)}{\overline{\Delta t}} -$$ -where $\overline{\Delta t}$ is the $p$--distribution expected value of $\Delta t$. - -This density is employed to estimate seroconversion rates. The antibody concentration $y$ is the -observable quantity, and we need to express the probability (density) of observed $y$ in terms of -the density of backward recurrence time. - -First, the backward recurrence time can $\tau$ be expressed as a function of the serum antibody -concentration $y$ -$$ -\tau(y) = \tau_{+}(y) + \tau_{-}(y) -$$ -where -\begin{align*} -\tau_{+}(y) & = \displaystyle{\frac{1}{\mu}} \log\left(\displaystyle{\frac{y_{+}}{y_{0}}}\right) [0\le \tau - %\VignetteIndexEntry{simulation} - %\VignetteEngine{knitr::rmarkdown} - %\VignetteEncoding{UTF-8} ---- - -```{r, include = FALSE} -knitr::opts_chunk$set( - collapse = TRUE, - comment = "#>" -) -``` - -```{r setup} -library(serocalculator) -library(dplyr) -``` - -```{r} -set.seed(1) -n = 480 -lambda = 0.036 -age = runif(n = n, min = 0, max = 80) -S1 = S2 = rep(0, n) - -for (i in 1:n) -{ - a = 0 - while(S2[i] < age[i]) - { - delta = rexp(n = 1, rate = lambda) - S2[i] = S2[i] + delta - } - - S1[i] = S2[i] - delta - - -} - -data = tibble( - age, - S1, - S2, - W = S2 - S1, - T1 = age - S1, - `min(W,age)` = min(W, age), - rel = T1/`min(W,age)` - -) - -hist(data$T1, breaks = 50) -hist(data$rel, breaks = 50) - - -``` - diff --git a/vignettes/tutorial.Rmd b/vignettes/tutorial.Rmd deleted file mode 100644 index 32ba774c..00000000 --- a/vignettes/tutorial.Rmd +++ /dev/null @@ -1,614 +0,0 @@ ---- -title: "Serocalculator package tutorial" -author: "UC Davis SeroEpidemiology Group" -date: "`r Sys.Date()`" -output: - bookdown::html_document2: - base_format: rmarkdown::html_vignette - toc: true -header-includes: "\\DeclareUnicodeCharacter{2010}{-}" -bibliography: references.bib -fontsize: 11pt -vignette: > - %\VignetteIndexEntry{Serocalculator package tutorial} - %\VignetteEncoding{UTF-8} - %\VignetteEngine{knitr::rmarkdown} ---- - - - -```{r, echo = FALSE} -pkgName = "serocalculator" -pkgUrl <- gsub("\n", "", packageDescription(pkgName)$URL) -``` - -\newpage - -# Introduction - -Antibody levels measured in a (cross–sectional) population sample can be translated into an estimate -of the frequency with which seroconversions (infections) occur in the sampled population. In simple -terms: the presence of many high antibody concentrations indicates that many subjects likely -experienced infection recently, while mostly low concentrations indicate a low frequency of -infections in the sampled population. More information about ELISA methods can be found on -[ECDC web site](https://www.ecdc.europa.eu/en/publications-data/seroincidence-calculator-tool). - -In order to thus interpret the measured cross-sectional antibody concentrations, characteristics of -the time course of the serum antibody response must be known. For any antibody detected in the -cross–sectional sample, a quantitative description of its dynamics following infection -(seroconversion to an elevated concentration, followed by a gradual decrease) must be available. In -published studies, this information on the time course of the serum antibody response has been -obtained from follow–up data in subjects who had a symptomatic episode following infection. The -onset of symptoms thus provided a proxy for the time that infection occurred. Care must be taken -that longitudinal and cross–sectional measurements of antibody concentrations are calibrated on the -same scale (or, preferably, expressed in identical units). - -The time course of the serum antibody response to infection is assumed generic: anyone infected by -the same pathogen is expected to produce a response similar to those seen in the symptomatic cohort -used for the follow–up study. Thus, the strategy is to set up a longitudinal model from a follow–up -study once, and use the thus obtained information to analyze many different cross–sectional data -sets. - -Note that it must be assumed that such variation in the time course of antibody concentrations among -individuals as observed in the longitudinal cohort is the same as in the population where the -cross-sectional sample was taken, where this variation cannot be observed. - -Analysis of longitudinal data and estimation of the required parameters is separated from the -estimation of seroincidences, because (1) there are few longitudinal data sets available and they -are difficult (and expensive) to obtain, (2) such longitudinal models may be considered *generic*, -presumably describing a physiological phenomenon that is similiar in any infected individual, and -(3) setting up and running the longitudinal model requires additional skills, not necessary for use -of the sero–incidence calculator script - -# The seroincidence estimator - -Package **serocalculator** was designed to calculate incidence of seroconversion, by using the -longitudinal seroresponse characteristics. The distribution of serum antibody concentrations in a -cross–sectional population sample is calculated, as a function of the (longitudinal) seroresponse -and the frequency of seroconversion (or seroincidence). Given the seroresponse, this (marginal) -distribution of antibody concentrations can be fitted to the cross-sectional data, by adjusting the -seroconversion frequency, thus providing a means to estimate the seroconversion frequency. - -## Time course of serum antibodies - -The seroresponse, the time course of serum antibodies following seroconversion (infection) is -described by means of a set of parameters describing it. These parameters may include: - -a) baseline antibody concentration, -b) time to reach peak antibody concentration, -c) magnitude of the peak concentration, and -d) antibody decay parameters describing the time course (shape and rate) of antibody decay. - -A model description that is used for the serocalculator is described in [@Simonsen_2009; @Teunis_2012]. An alternative -model, simplified but with improved interpretation of the underlying biological mechanisms, is given -in [@de_Graaf_2014] and further improved in [@Teunis_2016]. - -The current model assumes that upon exposure to an initial inoculum, pathogen concentrations -increase exponentially. Presence of pathogens (antigen presented to the immune system) signals an -increase in antibody production, resulting in exponentially increasing serum antibody -concentrations. Increased activity of the immune system, as signalled by circulating antibodies, -causes inactivation or die–off of pathogens, with a rate proportional to the serum antibody -concentration. Ultimately, when all pathogens are removed, infection is over and the promotion of -antibody production stops. Then the decay phase starts, and serum antibody concentrations decrease. -Antibody decay in the serum compartment may start fast and slow down later, resulting in -non–exponential decay. In [@Teunis_2016] this is modelled using a shape parameter, allowing gradual adjustment -between exponential (log–linear) and strongly non–exponential decay. - -## Heterogenity - -The five parameters describing the seroresponse (in round brackets names of corresponding -parameters used in the package, see [section 3.2.2](#longParams) for details): baseline antibody -concentration (`y0` and `yb`), time to peak (`t1`), peak antibody concentration (`y1`), decay rate -(`alpha`) and shape factor of the decay curve (`r`) are not fixed numbers. In a population of -subjects, individuals each have their own seroresponse, different from those of other subjects. -Therefore, these parameters are provided as a (joint) distribution, describing their variation among -individuals in the sampled population. Of course, such a distribution depends on the pathogen, the -detected antibody, and even the detection assay. - -Estimates for these seroresponse parameters may be obtained by fitting the model to longitudinal -data. Typically, such data are collected in patients with confirmed infection, where the time of -infection is detected by appearance of symptoms. Ideally, blood samples are taken at several times -post infection, up to a period long enough to reliably estimate the shape of the serum antibody -decay curve. - -A Bayesian hierarchical framework allows for individual variation in seroresponses, so that one -obtains the (posterior) joint distribution of the parameters as a (Markov chain) Monte Carlo sample, -of all relevant parameters [@Teunis_2016]. - -Note that, due to the limited number of iterations in the Monte Carlo sample, the generated -incidence estimates will show minor variations: if the same calculation is run twice, the outcomes -may differ slightly. If this variation should be smaller, the size of the Monte Carlo sample may be -increased. This however will slow down the calculations. - -## Incidence estimation - -The longitudinal seroresponses are considered generic: they represent the time course of (specific) -human serum antibodies against a (specific) pathogen. Therefore, with any cross–sectional sample of -the same antibodies in a human population, an incidence estimate can be calculated. - -Given the longitudinal response characteristics, **serocalculator** R package provide a rapid and -computationally simple method for calculating seroconversion rates, as published in [@Teunis_2012]. - -The methods on which the seroincidence calculator is based were developed with publicly funded -research. All procedures have been published and are open to the general public, including the core -script on which the seroincidence calculator is based. To make the functionalities provided as -broadly available as possible, R was chosen as the computing platform, because it is free and open -source, and runs on any modern computer operating system. - -## Model variants - -The package contains longitudinal models for seroincidence calculations. Four model variants are -possible, depending on whether seroconversion is instantaneous ($t_{1} = 0$) or not ($t_{1} > 0$), -and whether decay is exponential ($r = 1$) or proceeds as a power function ($r > 1$). Power function -decay allows for rapid inital decay followed by a sustained period of very slow decay [@4]. -Available model variants are described in Table \@ref(tab:model-variants) and Table \@ref(tab:model-variants-available). - -Table: (\#tab:model-variants) Model variants - -|Model | Time to
Seroconversion
($t_{1}$) | Decay
parameter
($r$) | -|-------|-------|-----| -| 1 | 0 | 1 | -| 2 | 0 | > 1 | -| 3 | > 0 | 1 | -| 4 | > 0 | > 1 | - -Table: (\#tab:model-variants-available) Models variants available by pathogen, antibody, and units: - - -| Pathogen | Antibody | Units | 1| 2| 3| 4| -|-------------------------|----------|-------------------|--|--|--|--| -| *Campylobacter jejuni* | IgG | ELISA (Delft) | *| | *| *| -| | IgM | ELISA (Delft) | *| | *| *| -| | IgA | ELISA (Delft) | *| | *| *| -| | IgG | ELISA (SSI) | *| *| | *| -| | IgM | ELISA (SSI) | *| *| | *| -| | IgA | ELISA (SSI) | *| *| | *| -| *Salmonella* | IgG | mixed ELISA (SSI) | *| *| | *| -| | IgM | mixed ELISA (SSI) | *| *| | *| -| | IgA | mixed ELISA (SSI) | *| *| | *| -| *Bordetella pertussis* | IgG-PT | IU | *| *| *| *| - - -# How to use *serocalculator* package - -This section provides step-by-step directions on the usage of the *serocalculator* package. - -## Loading the package - -Functionality of the *serocalculator* package is made available to the end user only once the library -is loaded into the current workspace. Assuming the package is installed already (covered in -[installation.pdf](installation.pdf)) loading is achieved by running the following command in the R -console (bear in mind that the text after character `#` is only a comment): - -```{r} -# Load package "seroincidence" -library(serocalculator) -library(dplyr) -``` - -At this moment all functions required to run the seroincidence calculation are made available. It -can be checked by running: - -```{r, eval=FALSE} -# List all objects (functions and data) exposed by package "serocalculator". -ls("package:serocalculator") -``` - -Here is the resulting output: - -```{r, echo=FALSE} -ls("package:serocalculator") -``` - -We briefly describe the most important objects and functions: - -a) `[DISEASE]Params[MODEL_TYPE]`: Monte Carlo sample of longitudinal response parameters per -antibody for various diseases: Campylobacter, Pertussis, Salmonella. Object class: `list`. -b) `[DISEASE]Sim[Low|Medium|High]Data`: Example simulated antibody levels data measured in a -cross-sectional population for three values of lambda (incidence): 0.036 ("Low"), 0.21 ("Medium") -and 1.15 ("High") (1/yr). Object class: `data.frame`. -c) `getAdditionalData`: Utility function for downloading additional longitudinal response -parameters from an online repository. Files available for download are `coxiellaIFAParams4.zip` and -`yersiniaSSIParams4.zip`. Object class: `function`. -d) `est.incidence.by`: Main function of the package. Estimates seroincidence based on supplied -cross-section antibody levels data and longitudinal response parameters. Object class: `function`. - -## Specifying input data - -There are two sets of inputs to the serology calculator that must always be specified: - -a) Simulated antibody levels measured in cross-sectional population sample (see -`campylobacterSimLowData`, `campylobacterSimMediumData`, etc. above). -b) Longitudinal response characteristic as set of parameters `(y1, alpha, yb, r, y0, mu1, t1)` -(see `campylobacterDelftParams1`, `campylobacterSSIParams2`, etc. above). - -We start with loading antibody levels measured in cross-sectional population sample. - -### Specifying cross-sectional antibody levels data - -The user has a few options of providing this data to the calculator: - -**i) Using supplied sample data** - -Data set `campylobacterSimMediumData` provides an example of a cross-sectional antibody levels data -for Campylobacter. It is loaded into the workspace as soon as the package is loaded, therefore it -can be referenced right away. Here is a small exempt from this data set: - -```{r} -# Show three first rows of "campylobacterSimMediumData" data.frame. -head(campylobacterSimMediumData, 3) -``` - -Let us create the serology data `serologyData` based on this data set: -```{r} -# Assign data.frame "campylobacterDelftData" to object named "serologyData". -serologyData <- campylobacterSimMediumData |> - mutate(AgeCat = cut(Age, 15, labels = FALSE)) - -# Print a few first observations. -head(serologyData) -``` - -You can view the data also in a tabular form: -```{r, eval=FALSE} -View(serologyData) -``` - -We shall pass this object later to the calculator. Object `serologyData` must contain at least one -column named `IgG`, `IgM`, or `IgA`. Additionally, column `Age` is used in the calculations if it is -present. Otherwise, it is created on-the-fly and initialized to `NA` (not available). Column `Age`, -if supplied, is assumed to represent age in days. - -Please, note that the cross-sectional data set can include extra columns allowing performing the -seroincidence calculations stratified per factors available in those data. In the example above -column `AgeCat` can be used as a *stratum* variable. This particular variable is created by -mapping the age in days (column `Age`) into 15 categories, category 1 grouping the youngest subjects -and category 15 grouping the oldest subjects. - -**ii) Loading from external files** - -The user can load her/his own data into an R session. Details on loading specific file types can be -found in online R manual on [R Data Import/Export](http://cran.r-project.org/doc/manuals/r-release/R-data.html). - -It is important that the input data is in a tabular form with each column containing levels measured -for a single antibody type. Column name should indicate name of the measured antibody. For instance, -a comma separated file with the following content: - -``` -IgG, IgM, IgA -5.337300, 0.4414653, 0.3002395 -3.534118, 0.3888226, 0.3543486 -2.144549, 0.3320178, 0.3884205 -2.957854, 0.4967764, 0.3472340 -``` - -is a valid cross-sectional data set. Suppose this file is named `c:\cross-sectional-data.csv`. -Then it can be loaded into R like this: -```{r, eval=FALSE} -# Read content of file "C:\cross-sectional-data.csv" into object named -# "serologyData". -serologyData <- read.csv(file = "C:\\cross-sectional-data.csv") -``` - -### Specifying longitudinal response parameters {#longParams} - -The longitudinal response parameters set consists of the following items: - -- `y1`: antibody peak level (ELISA units) -- `alpha`: antibody decay rate (1/days for the current longitudinal parameter sets) -- `yb`: baseline antibody level at $t$ approaching infinity ($y(t->inf)$) -- `r`: shape factor of antibody decay -- `y0`: baseline antibody level at $t=0$ ($y(t=0)$) -- `mu1`: initial antibody growth rate -- `t1`: duration of infection - -Please, refer to vignette [methodology.pdf](methodology.pdf) for more details on the underlying -methodology. - -End user has three options for loading the response parameters into R session: - -**i) Using supplied data** - -There are a few longitudinal response parameter data sets provided by the package including -Monte-Carlo sample of longitudinal response parameters, like `campylobacterDelftParams4`. -This particular object is a list containing three data.frame objects named `IgG`, `IgM` and `IgA`. -Let's have a pick into each of these two data sets separately (notice character `$` indicating a -sub-object of the parent object): -```{r} -# Show first rows of data.frame "IgG" in list "campylobacterDelftParams4". -head(campylobacterDelftParams4$IgG) - -# Show first rows of data.frame "IgM" in list "campylobacterDelftParams4". -head(campylobacterDelftParams4$IgM) - -# Show first rows of data.frame "IgA" in list "campylobacterDelftParams4". -head(campylobacterDelftParams4$IgA) -``` - -Let us assign object `campylobacterDelftParams4` to variable `responseParams`: -```{r} -responseParams <- campylobacterDelftParams4 -``` - -**ii) Loading from local external files** - -Alternatively, this data can be loaded from an external file. Bear in mind, that most likely -your data is organized into three files, separately for antibody `IgG`, `IgM` and `IgA`. Assuming -that the data is saved into csv files named `IgG.csv`, `IgM.csv` and `IgA.csv` the end user would -run the following code in order to create a valid input to the calculator: -```{r, eval=FALSE} -IgGData <- read.csv(file = "IgG.csv") -IgMData <- read.csv(file = "IgM.csv") -IgAData <- read.csv(file = "IgA.csv") - -# Create a list named "responseData" containing objects named "IgG", "IgM" and -# "IgA". -responseParams <- list(IgG = IgGData, IgM = IgMData, IgA = IgAData) -``` - -Note that object `responseParams` is a list with three dataframes named `IgG`, `IgM` and `IgA` as -required. - -**iii) Loading from an external repository** - -Finally, response parameters can be obtained from an online repository set up for this package. The -repository is hosted on ECDC servers. At the time of publishing this package two files are -available: - -a) `coxiellaIFAParams4.zip`: longitudinal response parameters per antibody for Coxiella. -b) `yersiniaSSIParams4.zip`: longitudinal response parameters per antibody for Yersinia. - -Simply use the supplied utility function `getAdditionalData` to download this data: -```{r, eval=FALSE} -responseParams <- getAdditionalData("coxiellaIFAParams4.zip") -``` - -Internet connection is needed for this function to work. - -## Estimating seroincidence - -Main calculation function provided by package *serocalculator* is called `est.incidence.by`. -It takes several arguments: - -- `data`: A data frame with the cross-sectional data (see variable `serologyData` above). This may - be the whole data set loaded from file, but can also be a subset, e.g. `data = serologyData[1, ]` - to use only the first row. In this tutorial this is the data loaded into variable `serologyData`. - It is a required input. -- `antibodies`: A list of antibodies to be used. This can be a triplet - (`antibodies = c("IgG", "IgM", "IgA")`) or any single antibody (`antibodies = c("IgG")`) or a - combination of any two antibodies. It is a required input. -- `strata`: A list of categories to stratify data. The column `AgeCat` in the example data set can - be used as an example. If `strata = ""` (default), then the whole data set is treated as a single - stratum; if each sample is assigned a unique identifier (e.g. `strata = "AgeCat"`) there are as - many strata as there are samples and an incidence estimate is calculated for each sample. If not - specified, then `strata` is initialized to `""`. -- `params`: A list with the longitudinal parameters for all antibodies specified. In this tutorial - this is the data loaded into variable `responseParams`. It is a required input. -- `censorLimits`: A list of cutoff levels, one for each antibody used. These are antibody levels - below which observations should be treated as censored. It is a required input. -- `par0`: List of parameters for the (lognormal) distribution of antibody concentrations for true - seronegatives (i.e. those who never seroconverted), by named antibody type (corresponding to - `data`). -- `start` A starting value for `log.lambda`. Value of -6 corresponds roughly to 1 day - (`log(1/365.25)`), value of -4 corresponds roughly to 1 week (`log(7/365.25)`). Users are adivised - to experiment with this value to confirm that convergence to the same estimate is obtained. - Default is -6. -- `numCores` Number of processor cores to use for calculations when computing by `strata`. If set to - more than 1 and R package `parallel` is available (installed by default), then the computations by - stratum are executed in parallel. Default is 1, ie. no execution in parallel. - -Here is an example of the *Campylobacter* seroincidence calculation for three antibodies measured, -stratified per `AgeCat`, and with measurements below `0.1` removed: -```{r, eval=FALSE} -# Prepare input data. -serologyData <- campylobacterSimMediumData |> - mutate( - AgeCat = cut(Age, 15, labels = FALSE), - Age = NA) - -responseParams <- campylobacterDelftParams4 - -cutOffs <- list(IgG = 0.1, IgM = 0.1, IgA = 0.1) - -# Baseline distributions: the distributions of antibody concentrations in -# subjects who have never seroconverted. -baseLine <- list(IgG = c(log(0.05), 1), - IgM = c(log(0.005), 1), - IgA = c(log(0.005), 1)) - -# Assign output of function "est.incidence.by" to object named -# "seroincidenceData". Use all available processor cores. -seroincidenceData <- est.incidence.by( - data = serologyData, - antibodies = c("IgG", "IgM", "IgA"), - strata = "AgeCat", - params = responseParams, - censorLimits = cutOffs, - par0 = baseLine, - numCores = parallel::detectCores(), - start = -4) - -# Show content of the output variable... -print(seroincidenceData) -# ...or simply type in the console: 'seroincidenceData' (without "'") and -# press ENTER. -``` - -The following text should be printed. - - ## Seroincidence object estimated given the following setup: - ## a) Antibodies : IgG, IgM, IgA - ## b) Strata : AgeCat - ## c) Censor limits: IgG = 0.1, IgM = 0.1, IgA = 0.1 - ## - ## This object is a list containing the following items: - ## Fits - List of outputs of "optim" function per stratum. - ## Antibodies - Input parameter antibodies of function "est.incidence.by". - ## Strata - Input parameter strata of function "est.incidence.by". - ## CensorLimits - Input parameter censorLimits of function "est.incidence.by". - ## - ## Call summary function to obtain output results. - -The most important output is subobject `Fits` containing raw results on the output incidence. -Translation of these raw results is provided by a custom function `summary` explained in the -following section. - -The cutoff argument is based on censoring of the observed serum antibody measurements [@Strid_2001]. Cut-off -levels must always be specified when calling function `est.incidence.by` (argument -`censorLimits`). Value `0` should be set for antibody measurements where no censoring is needed, for -instance - -```{r, eval=FALSE} -censorLimits <- list(IgG = 0, IgM = 0, IgA = 0) -``` - -Using different censoring levels will produce different results. Choosing higher cut-off causes the -estimates of lambda to decrease. Results should be published together with the chosen cut-off -values. The cut-off level of `0.1` set in the example above is a typical value, but users should set -it to value reflecting the censoring level in the data. - -## Getting a summary of seroincidence - -Output of the calculator should be passed in to function `summary` calculating output results: - -```{r, eval=FALSE} -summary(seroincidenceData) -``` - - ## Seroincidence estimated given the following setup: - ## a) Antibodies : IgG, IgM, IgA - ## b) Strata : AgeCat - ## c) Censor limits: IgG = 0.1, IgM = 0.1, IgA = 0.1 - ## d) Quantiles : 0.025, 0.975 - ## - ## Seroincidence estimates: - ## Lambda.est Lambda.lwr Lambda.upr Deviance Convergence Stratum - ## 1 0.09721890 0.06397004 0.14774909 105.29815 0 1 - ## 2 0.05497303 0.03573489 0.08456817 181.90627 0 2 - ## 3 0.04456096 0.02845903 0.06977327 199.99357 0 3 - ## 4 0.02944038 0.01715302 0.05052964 141.32558 0 4 - ## 5 0.02569781 0.01436524 0.04597053 123.33213 0 5 - ## 6 0.02565297 0.01587275 0.04145941 187.41060 0 6 - ## 7 0.03458616 0.02012722 0.05943207 128.84486 0 7 - ## 8 0.02776873 0.02640621 0.02920154 133.57166 52 8 - ## 9 0.04016261 0.02133209 0.07561541 94.99389 0 9 - ## 10 0.01996477 0.01898409 0.02099612 104.30992 52 10 - ## 11 0.03356017 0.01917771 0.05872886 141.20168 0 11 - ## 12 0.05287648 0.03263923 0.08566140 181.68655 0 12 - ## 13 0.05081097 0.02946963 0.08760729 123.66670 52 13 - ## 14 0.04813104 0.02945312 0.07865371 186.92218 0 14 - ## 15 0.03421042 0.02210895 0.05293569 215.78684 0 15 - -The `summary` function returns a list of objects as well. It contains sub-objects `Antibodies`, -`Strata`, `CensorLimits`, `Quantiles` and `Results`. - -The most important sub-object of the output of the `summary` functions is `Results`, containing -estimates of `Lambda` (annual incidence) together with their lower and upper bounds (`Lambda.lwr` -and `Lambda.upr`, respectively). The default lower bound is 2.5% and the upper bound is 97.5% of the -distribution of `Lambda`. These values can be changed (see [Other examples](#other-examples)). - -Optionally, the summary function returns also `Deviance` (negative log likelihood at the estimated -`Lambda`) and `Convergence` (indicator returned by function `stats::optim`; value of 0 indicates -convergence). - -It may be beneficial to assign output of this function to a variable for further analysis: - -```{r, eval=FALSE} -# Compute seroincidence summary and assign to object "seroincidenceSummary". -seroincidenceSummary <- summary(seroincidenceData) - -# Show the results. -seroincidenceSummary$Results -``` - - ## Lambda.est Lambda.lwr Lambda.upr Deviance Convergence Stratum - ## 1 0.09721890 0.06397004 0.14774909 105.29815 0 1 - ## 2 0.05497303 0.03573489 0.08456817 181.90627 0 2 - ## 3 0.04456096 0.02845903 0.06977327 199.99357 0 3 - ## 4 0.02944038 0.01715302 0.05052964 141.32558 0 4 - ## 5 0.02569781 0.01436524 0.04597053 123.33213 0 5 - ## 6 0.02565297 0.01587275 0.04145941 187.41060 0 6 - ## 7 0.03458616 0.02012722 0.05943207 128.84486 0 7 - ## 8 0.02776873 0.02640621 0.02920154 133.57166 52 8 - ## 9 0.04016261 0.02133209 0.07561541 94.99389 0 9 - ## 10 0.01996477 0.01898409 0.02099612 104.30992 52 10 - ## 11 0.03356017 0.01917771 0.05872886 141.20168 0 11 - ## 12 0.05287648 0.03263923 0.08566140 181.68655 0 12 - ## 13 0.05081097 0.02946963 0.08760729 123.66670 52 13 - ## 14 0.04813104 0.02945312 0.07865371 186.92218 0 14 - ## 15 0.03421042 0.02210895 0.05293569 215.78684 0 15 - -As one may note it is a dataframe with six columns that can be later post-processed with custom -calculations. - -# Other examples - -The following examples show the standard procedure for estimating seroincidence. - -```{r, eval=FALSE} -# 1. Define cross-sectional data. -serologyData <- with(campylobacterSimMediumData, - data.frame( - IgG = IgG.ratio.new, - IgM = IgM.ratio.new, - IgA = IgA.ratio.new)) - -# 2. Define longitudinal response data -responseParams <- campylobacterDelftParams3 - -# 3. Define cut-offs -cutOffs <- list(IgG = 0.25, IgM = 0.25, IgA = 0.25) - -# 4. Baseline distributions -baseLine <- list(IgG = c(log(0.05), 1), - IgM = c(log(0.005), 1), - IgA = c(log(0.005), 1)) - -# 4a. Calculate a single seroincidence rate for all serum samples... -seroincidenceData <- est.incidence.by( - data = serologyData, - antibodies = c("IgG", "IgM", "IgA"), - strata = "", - params = responseParams, - censorLimits = cutOffs, - par0 = baseLine) - -# 4b. ...or calculate a single seroincidence rate for a single serum sample -# (triplet of titres)... -seroincidenceData <- est.incidence.by( - data = serologyData[1, ], - antibodies = c("IgG", "IgM", "IgA"), - strata = "", - params = responseParams, - censorLimits = cutOffs, - par0 = baseLine) - -# 4c. ...or calculate a single seroincidence rate for all serum samples (only IgG) -seroincidenceData <- est.incidence.by( - data = serologyData, - antibodies = c("IgG"), - strata = "", - params = responseParams, - censorLimits = cutOffs, - par0 = baseLine) - -# 5a. Produce summary of the results with 2.5% and 97.5% bounds... -summary(seroincidenceData) - -# 5b. ...or produce summary of the results with 5% and 95% bounds, do not show -# convergence... -summary(seroincidenceData, quantiles = c(0.05, 0.95), showConvergence = FALSE) - -# 5c. ...or produce summary and assign to an object... -seroincidenceSummary <- summary(seroincidenceData) -# ...and work with the results object from now on (here: display the results). -seroincidenceSummary$Results -``` - -\newpage - -# References diff --git a/vignettes/typhoid-controls.Rmd b/vignettes/typhoid-controls.Rmd deleted file mode 100644 index 5edf4d37..00000000 --- a/vignettes/typhoid-controls.Rmd +++ /dev/null @@ -1,29 +0,0 @@ ---- -title: "typhoid-controls" -output: rmarkdown::html_vignette -vignette: > - %\VignetteIndexEntry{typhoid-controls} - %\VignetteEngine{knitr::rmarkdown} - %\VignetteEncoding{UTF-8} ---- - -```{r, include = FALSE} -knitr::opts_chunk$set( - collapse = TRUE, - comment = "#>" -) -``` - -```{r setup} -library(serocalculator) -``` - -```{r} - -library(ggplot2) -typhoid_controls |> - ggplot(aes(x = Age, y = elisa, col = antigen_iso)) + - geom_point() + - geom_smooth() -``` - diff --git a/vignettes/typhoid-seroincidence.Rmd b/vignettes/typhoid-seroincidence.Rmd deleted file mode 100644 index d78fbe32..00000000 --- a/vignettes/typhoid-seroincidence.Rmd +++ /dev/null @@ -1,135 +0,0 @@ ---- -title: "Typhoid Seroincidence" -output: rmarkdown::html_vignette -vignette: > - %\VignetteIndexEntry{Typhoid Seroincidence} - %\VignetteEngine{knitr::rmarkdown} - %\VignetteEncoding{UTF-8} ---- -# Introduction - -This vignette provides users with an example analysis using the *serocalculator* package. Users will be able to determine the seroincidence of typhoid fever in the sample population using existing longitudinal antibody dynamics collected from Bangladesh, Ghana, Nepal, and Pakistan, plus a simulated cross-sectional serosurvey. - -## References -Aiemjoy, K., Seidman, J. C., Saha, S., Munira, S. J., Islam Sajib, M. S., Sium, S. M. al, Sarkar, A., Alam, N., Zahan, F. N., Kabir, M. S., Tamrakar, D., Vaidya, K., Shrestha, R., Shakya, J., Katuwal, N., Shrestha, S., Yousafzai, M. T., Iqbal, J., Dehraj, I. F., … Andrews, J. R. (2022). Estimating typhoid incidence from community-based serosurveys: a multicohort study. The Lancet. Microbe, 3(8), e578–e587. https://doi.org/10.1016/S2666-5247(22)00114-8 - - - -```{r, include = FALSE} -knitr::opts_chunk$set( - collapse = TRUE, - comment = "#>" -) -``` -# Sample Analysis -## 1. Load packages -The first step in conducting this analysis is to load our necessary packages. Follow the [installation instructions] https://ucd-serg.github.io/serocalculator/ if you have not already installed *serocalculator*. (Still in development as of 10/17/2023) - -```{r setup} - -#library(devtools) -#install_github("UCD-SERG/serocalculator") -library(serocalculator) -library(tidyverse) -``` - -## 2. Load data -### a. Load and prepare longitudinal parameter data -The next step is to load the longitudinal data to set the antibody decay parameters. In this example, these parameters were modeled with Bayesian hierarchical models to fit two-phase power-function decay models to the longitudinal antibody responses among confirmed enteric fever cases. - -These parameters include the following: -* y0 = baseline -* y1 = peak antibody responses -* t1 = time to peak -* α = decay rate -* r = decay shape - -We also create two additional variables, *alpha* and *d*. *Alpha* is the annual decay rate, which is calculated from the daily decay rate in this example. *d* is 1-r, the decay shape. _______ - -Finally, we select only the variables needed for the analysis. - -```{r longdata} -c.hlye.IgG <- - fs::path_package( - "extdata", - "dmcmc_hlyeigg_09.30.rds", - package = "serocalculator") |> #Load longitudinal parameters dataset - readRDS()%>% - mutate(alpha = alpha*365.25, #Create alpha and d - d = r-1) %>% - select(y1, alpha, d) #Select only the variables needed for analysis -``` - -### b. Load and prepare simulated data -The simulated data represent a cross-sectional serosurvey conducted in a representative sample of the general population without regard to disease status. Here, we are assuming a force of infection (FOI, *lambda*) of 0.2. This means that we assume that there will be 0.2 cases per person in the general population during the time period of interest. - -In this scenario, we have selected hlye and IgG as our target measures. Users may select different serologic markers depending on what is available. From the original dataset, we rename our variables to *y* and *a*. Finally, we once again limit the dataset to only the variables needed for the analysis. - -``` {r simdata} -library(fs) # filesystem utility functions -p.hlye.IgG <- - fs::path_package( - package = "serocalculator", - "extdata/simpophlyeigg.2.csv") %>% #Load simulated cross-sectional dataset - read_csv() %>% - rename( #rename variables - y = y.smpl, - a = a.smpl) %>% - select(y, a) #Select only the variables needed for analysis -``` - - -### c. Set conditions for simulated data -Next, we must set conditions based on some assumptions about the simulated data. This will differ based on background knowledge of the cross-sectional data. - -[Need more here, plus simplify variable names] - -``` {r conditions} -cond.hlye.IgG <- data.frame( - nu = 1.027239, # B noise - eps = 0.2, # M noise - y.low = 0.0, # low cutoff - y.high = 5e4); -``` - - -## 3. Estimate Seroincidence -Finally, we are ready to begin seroincidence estimation. We define our starting value as 0.5, which will also define our initial estimate for lambda (FOI). Then we set up values for the confidence interval. - -(Add explanation for each section below) -[Need more information on starting estimate vs estimate mentioned for simulated data] - - -```{r seroinc} -start <- .05 - -lambda = start # initial estimate: starting value -log.lambda = log(lambda) -log.lmin=log(lambda/10) -log.lmax=log(10*lambda) - - - -objfunc <- function(llam){ - return(res <- fdev(llam, p.hlye.IgG, c.hlye.IgG, cond.hlye.IgG)) -} - - -fit <- nlm(objfunc,log.lambda, - hessian=TRUE,print.level=0,stepmax=(log.lmax-log.lmin)/4) - - -#lambda, lower, upper, LF min -log.lambda.est <- c(exp(fit$estimate), - exp(fit$estimate + qnorm(c(0.025))*sqrt(1/fit$hessian)), - exp(fit$estimate + qnorm(c(0.975))*sqrt(1/fit$hessian)), - fit$minimum) - - -log.lambda.est -``` - -## Conclusions -In our simulated data, we found that the estimated seroincidence of typhoid is ______. - -