Learn R Programming

qpcR (version 1.3-2)

pcrfit: Function for qPCR model fitting

Description

This is the main workhorse function of the qpcR package that fits one of the available models to qPCR data using nonlinear least-squares fitting from nls, with sensible starting parameters obtained from either nls.lm (default), newuoa or optim.

Usage

pcrfit(data, cyc = 1, fluo, model = l4, do.optim = TRUE,  
       opt.method = "all", nls.method = "all", 
       start = NULL, robust = FALSE, control = nls.control(), 
       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 containing the raw fluorescence data of the run.
model
the model to be used for the analysis. Defaults to l4.
do.optim
if FALSE, refinement of starting values by any of the optimization methods (see 'Details') will be skipped.
opt.method
all or one of the available optimization methods. See 'Details'.
nls.method
all or one of the available methods in nls. See 'Details'.
start
a vector of starting values that can be supplied externally.
robust
logical. If TRUE, robust nonlinear regression is used. See 'Details'.
control
an optional list of control settings for nls or qpcR:::rnls.
weights
a vector with same length as data containing the weights for the nonlinear fit.
verbose
logical. If TRUE, fitting and convergence results will be displayed in the console.
...
other parameters to be passed to optim, genoud or nls.

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 starting values for each applied method. Can be used to track problems.
  • opt.methodthe parameter opt.method.

encoding

latin1

Details

The fitting procedure works as follows (hopefully ensuring maximum safeness against convergence errors): 1) Approximate starting values are acquired from model$ssfct. 2) Starting values are refined by any of the methods available in optim, the derivative-free quadratic minimization newuoa from package 'minqa' or the Levenberg-Marquardt algorithm (nls.lm). The default setting is all, meaning that the optimization is done in the order "LM", "BFGS", "Nelder-Mead", "minqa" and "SANN". If any of the methods successfully converged, the remaining are skipped and the refined starting values transferred to nls. The opt.methods can be combined to tweak the robustness, whereby the starting parameters are passed to each succeeding method, i.e. rep("Nelder", 5) will do 5 successive Nelder-Mead optimisations or c("LM", "Nelder") will pass the starting values from "LM" to "Nelder". Levenberg-Marquardt ("LM") is very fast and reliable in many scenarios and is thus the default first method. 3) The refined starting values from 2) are fitted with nls using the order "port", "default" (Gauss-Newton) and "plinear". Again, if any of the methods converged, the remaining are skipped. This function is to be used at the single run level. Otherwise use pcrbatch or modlist. The output from the optim methods is checked by ensuring all eigenvalues from the hessian are positive, otherwise a notice will occur and the next method in queue is used. If robust = TRUE, robust nonlinear fitting will be used. To do this, the internal function qpcR:::rnls is called which is a modification of the nlrob function of the 'robustbase' package. Modifications were done such that all available generic functions for objects of class 'nls' can be used on the output of qpcR:::rnls, such as predict, confint etc.

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. Developments of NEWUOA for minimization without derivatives. M. J. D. Powell. IMA Journal of Numerical Analysis (2008), 28: 649-664.

Examples

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

## using BFGS and Nelder from 'optim'
pcrfit(reps, 1, 2, l5, opt.method = c("BFGS", "Nelder-Mead"))

## skip 'optim' method and supply
## own starting values
pcrfit(reps, 1, 2, l4, do.optim = FALSE, start = c(-5, -0.05, 11, 16)) 

## make a robust model
pcrfit(reps, 1, 2, l4, robust = TRUE)

Run the code above in your browser using DataLab