Learn R Programming

qpcR (version 1.3-7.1)

pcrfit: Workhorse function for qPCR model fitting

Description

This is the workhorse function of the qpcR package that fits one of the available models to qPCR data using (weighted) nonlinear least-squares (Levenberg-Marquardt) fitting from nlsLM of the 'minpack.lm' package.

Usage

pcrfit(data, cyc = 1, fluo, model = l4, start = NULL, 
       offset = 0, weights = NULL, verbose = TRUE, ...)

Arguments

data
the name of the dataframe containing the qPCR runs.
cyc
the column containing the cycle data. Defaults to 1.
fluo
the column(s) containing the raw fluorescence data of the run(s). If more than one column is given, the model will be built with the replicates. See 'Details' and 'Examples'.
model
the model to be used for the analysis. Defaults to 'l4'.
start
a vector of starting values that can be supplied externally.
offset
an offset cycle number from the second derivative cut-off cycle for all MAK methods. See 'Details' and 'Example'.
weights
a vector with same length as data containing possible weights for the nonlinear fit, or an expression to calculate weights from. See 'Details'.
verbose
logical. If TRUE, fitting and convergence results will be displayed in the console.
...
other parameters to be passed to nlsLM.

Value

  • A model of class 'nls' and 'pcrfit' with the following items attached:
  • DATAthe initial data used for fitting.
  • MODELthe model used for fitting.
  • call2the call to pcrfit.
  • parMatthe trace of the parameter values. Can be used to track problems.
  • opt.methoddefaults to "LM".

encoding

latin1

Details

This is a newer (from qpcR 1.3-7 upwards) version of pcrfit. It is a much simpler implementation containing only the LM-Algorithm for fitting, but this fitting routine has proven to be so robust that other optimization routines (such as in optim) could safely be removed. The fitting is done with the new nlsLM function of the 'minpack.lm' package, which gives a model of class 'nls' as output. This function is to be used at the single run level or on replicates (by giving several columns). The latter will build a single model based on the replicate values. If many models should be built on a cohort of replicates, use modlist and replist. The offset value defines the offset cycles from the second derivative maximum that is used as a cut-off criterion in the MAK methods. See 'Examples'. Since version 1.3-7, an expression given as a character string can be supplied to the weights argument. This expression, which is transferred to qpcR:::wfct, defines how the vector of weights is calculated from the data. In principle, five different parameters can be used to define weights: "x" relates to the cycles $x_i$, "y" relates to the raw fluorescence values $y_i$, "error" relates to the error $\sigma(y_{i, j})$ of replicates $j$, "fitted" relates to the fitted values $\hat{y}_i$ of the fit, "resid" relates to the residuals $y_i - \hat{y}_i$ of the fit. For "fitted" and "resid", the model is fit unweighted by pcrfit, the fitted/residual values extracted and these subsequently used for refitting the model with weights. These parameters can be used solely or combined to create a weights vector for different regimes. The most commonly used are (see also 'Examples'): Inverse of response (raw fluorescence) $\frac{1}{y_i}$: "1/y" Square root of predictor (Cycles) $\sqrt{x_i}$: "sqrt(x)" Inverse square of fitted values: $\frac{1}{\hat{y}^2_i}$: "1/fitted^2" Inverse variance $\frac{1}{\sigma^2(y_{i, j})}$: "1/error^2"

References

Bioassay analysis using R. Ritz C & Streibig JC. J Stat Soft (2005), 12: 1-22. A Method for the Solution of Certain Problems in Least Squares. K. Levenberg. Quart Appl Math (1944), 2: 164-168. An Algorithm for Least-Squares Estimation of Nonlinear Parameters. D. Marquardt. SIAM J Appl Math (1963), 11: 431-441.

Examples

Run this code
## simple l4 fit of F1.1 of the 'reps' dataset
m1 <- pcrfit(reps, 1, 2, l4) 
plot(m1)

## supply own starting values
pcrfit(reps, 1, 2, l4, start = c(-5, -0.05, 11, 16)) 

## make a replicate model,
## use inverse variance as weights
m2 <- pcrfit(reps, 1, 2:5, l5, weights = "1/error^2")
plot(m2)

## fit a mechanistic 'mak2' model
## to -1 cycle from SDM
m3 <- pcrfit(reps, 1, 2, mak2, offset = -1)
plot(m3)

Run the code above in your browser using DataLab