Calculate_maxRBA: Calculate maxRBA

View source: R/Calculate_maxRBA.R

Calculate_maxRBAR Documentation

Calculate maxRBA

Description

Calculate_maxRBA calculates the maximum residual after baseline-adjustment for each viral strain

Usage

Calculate_maxRBA(
  dat_list,
  subjectCol = "SubjectID",
  method = c("exp", "lm"),
  yMinZero = FALSE,
  scoreFun = max,
  discretize = c(0.2, 0.3),
  normalize = FALSE,
  scaleResiduals = FALSE,
  responseLabels = paste0(c("low", "moderate", "high"), "Responder"),
  na_action = "na.fail",
  ...
)

Arguments

dat_list

a named list like the one returned by FormatTiters.

subjectCol

the name of the column specifying a subject ID. Default is "SubjectID".

method

a character string specifying the method used to model the relationship between day 0 and fold change values. One of either "lm" for a linear model or "exp" for an exponential model.

yMinZero

a logical specifying whether fitted y values below 0 should be set to 0.

scoreFun

a function applied to all (potentially scaled) residuals for each subject to determine the endpoint. Default is max but sum may also be useful to quantify the total response.

discretize

a vector of quantiles in (0, 0.5] specifying where to make the cutoff for low, moderate and high responses. Default is 20% and 30%.

normalize

Logical specifying whether residuals should be normalized with the inverse normal transform. Default is FALSE.

scaleResiduals

Logical. Should residuals be scaled inversely by the square of the confidence intervals from the linear model.

responseLabels

names for low, moderate and high responses

na_action

how should missing NA values be treated. Default is "na.fail"

...

Additional arguments passed to lm if method == "lm" or nls if method == "exp"

Details

Calculates the baseline-adjusted fold change for each strain of virus using (unnormalized) fold change and baseline titers. Linear regression or an exponential curve is used to remove the effect of baseline titers on fold changes. The score function (scoreFun) is used to combine the adjusted fold change across multiple strains. Missing (NA) values are handled by being returned as missing in the endpoints in the output

Value

A list with the following elements:

models

the models calculated on each strain separately (with names the same as on dat_list)

residualMatrix

the matrix of residuals

maxRBA

a named vector containing the continuous maxRBA endpoint

maxRBA_d<X>

a named vector containing the discrete maxRBA endpoint with cutoffs defined by the <X>% quantile (may be more than 1, see discretize)

Author(s)

Stefan Avey

See Also

lm, nls

Examples

## Prepare the data
titer_list <- FormatTiters(Year2_Titers)

## Using a linear fit
endpoints <- Calculate_maxRBA(titer_list, method = "lm")
summary(endpoints)
## Get discrete endpoints using upper/lower 30%
endpoints$maxRBA_d30

## Get endpoints with a 50% split into high and low
endpoints <- Calculate_maxRBA(titer_list, method = "exp", discretize = 0.5)
endpoints$maxRBA_d50

stefanavey/titer documentation built on Jan. 27, 2023, 3:41 a.m.