Skip to contents

Process data for a single antigen: fit a standard curve, establish bounds, normalize samples, and save a plot showing the fit and the samples.

Usage

processSmp(
  smp,
  std,
  bg = NULL,
  smpdil = 1,
  fitlog = "xy",
  ismp = 1:nrow(smp),
  plotdir = "./",
  pname = NULL,
  ptitle = "fit and samples",
  xvar = NULL,
  yvar = NULL,
  smpvar = NULL,
  addvar = NULL,
  dilvar = NULL,
  resvar = "concentration",
  model = "sigmoid",
  Alow = NULL,
  asym = TRUE,
  trim.flat = TRUE,
  interactive = TRUE,
  monot.prompt = FALSE,
  rm.before = FALSE,
  rm.after = interactive,
  maxrm = 2,
  set.bounds = interactive,
  overwrite.bounds = FALSE,
  ifix = NULL,
  extrapolate.low = FALSE,
  extrapolate.up = FALSE,
  optmethod = "Nelder-Mead",
  maxit = 5000,
  stdcol = c("firebrick3", "darkslategray"),
  rugcol = c("cadetblue", "purple", "firebrick2"),
  width = 7,
  height = 6,
  ...
)

Arguments

smp

data frame with sample ID, sample values and other optional variables (e.g. dilution).

std

matrix or data frame with standards for fitting.

bg

values for background spots.

smpdil

single value for sample dilutions (if dilutions are not provided in smp data frame). Ignored if dilvar is provided and the variable is included in smp data frame.

fitlog

character string indicating if standard values should be log-transformed for fitting. If the string contains _x_, xvar will be transformed, if it contains _y_ - yvar.

ismp

indices for samples to be plotted (e.g. to exclude standards that are included in smp data frame).

plotdir

directory for the plots to be saved.

pname

character string for fit plot. If NULL, will be based on ptitle with underscore substituted for space.

ptitle

character string for plot title.

xvar, yvar

character strings for the variables used to fit a standard curve. If NULL, first two columns are assumed to be x and y variables.

smpvar

character string indicating sample variable.

addvar

named vector for additional variables (e.g. date or plate), where element names will be used as variable names in smp.

dilvar, resvar

character strings for dilution variable and results.

model

the model to be fit.

Alow

lower asymptote for the sigmoid model. If NULL, the lower asymptote will be estimated, adding an extra parameter to the model. To fix the asymptote at the level of background, specify "bg". Numeric value of Alow will force the asymptote to be fixed at the provided level.

asym

if TRUE, asymmetry in the fit is allowed, adding an extra parameter to the model.

trim.flat

logical value determining how the values of yvar are trimmed. If TRUE, they will be trimmed at the bounds where the curve starts to flatten out (automatically determined as maxima of the third derivative of the function). If FALSE, yvar will be trimmed at extrema, defined as the range of standards or asymptotes of the fit (whichever are less extreme).

interactive

logical value. If TRUE, the user is prompted to evaluate the standards (and/or the fit) and asked to remove outliers if needed. TRUE value takes precedence over rm.before and rm.after: if both are FALSE, rm.after is reset to TRUE.

monot.prompt

if TRUE, the user is prompted to evaluate the standards and possibly remove outliers if the standards are not monotonic (increasing). FALSE value is ignored if interactive is TRUE.

rm.before

logical value indicating if potential outliers should be removed before the model is fitted. Ignored if interactive is FALSE.

rm.after

logical value indicating if potential outliers should be removed after the model is fitted. Ignored if interactive is FALSE.

maxrm

maximum number of outliers to remove.

set.bounds

if TRUE, the user is given the option to manually set the bound that is not set automatically. In that case, the prompt appears even if interactive is FALSE.

overwrite.bounds

logical value indicating the option to overwrite automatically set bounds. Ignored if interactive is FALSE.

ifix

sorted integer vector of length 3 with indices of standards to be used for getting starting values for optimization.

extrapolate.low

if TRUE, sample values beyond lower bounds will be processed by extrapolation of the standard curve (not recommended). Takes precedence over trim.flat value.

extrapolate.up

if TRUE, sample values beyond upper bounds will be processed by extrapolation of the standard curve (not recommended). Takes precedence over trim.flat value.

optmethod

method to be used in optimization.

maxit

maximum number of iterations in optimization.

stdcol

vector of two colors for the standard points and the fit on the plot.

rugcol

vector of three colors for the rugplot, which indicates sample values (inside the bounds, between the bounds and extrema, and beyond extrema).

width, height

optional parameters for the final saved plot.

...

further graphical parameters.

Value

A list of length three. The first element is a data frame that contains the results; the second is a character string with a flag containing information about removed points, failure to fit the model, manually set bounds, and/or an optional custom note provided by the user during an interactive model-fitting procedure. The last element is the number of sample values for which the results are trimmed.

Details

Note that if fitlog contains _x_ and thus xvar in standards is log-transform before fitting, the results are still returned on a regular scale (values of inverse function are exponentiated and then multiplied by dilution).