nlfb: Nash variant of Marquardt nonlinear least squares solution...

Description Usage Arguments Details Value Author(s) References See Also Examples

View source: R/nlfb.R


Given a nonlinear model expressed as a vector valued residual function resfn and a start vector of parameter values for that function, attempts to find the minimum of the residual sum of squares using the Nash variant (Nash, 1979) of the Marquardt algorithm, where the linear sub-problem is solved by a qr method. This is a restructured version of a function by the same name from package nlmrt which is now deprecated.


   nlfb(start, resfn, jacfn=NULL, trace=FALSE, lower=-Inf, upper=Inf, 
         maskidx=NULL, weights=NULL, data=NULL, control, ...)



A function that evaluates the residual vector for computing the elements of the sum of squares function at the set of parameters start. Where this function is created by actions on a formula or expression in nlxb, this residual vector will be created by evaluation of the 'model - data', rather than the conventional 'data - model' approach. The sum of squares is the same.


A function that evaluates the Jacobian of the sum of squares function, that is, the matrix of partial derivatives of the residuals with respect to each of the parameters. If NULL (default), uses an approximation.

The Jacobian MUST be returned as the attribute "gradient" of this function, allowing jacfn to have the same name and be the same code block as resfn, which may permit some efficiencies of computation.


A named parameter vector. For our example, we could use start=c(b1=1, b2=2.345, b3=0.123) nls() takes a list, and that is permitted here also.


Logical TRUE if we want intermediate progress to be reported. Default is FALSE.


Lower bounds on the parameters. If a single number, this will be applied to all parameters. Default -Inf.


Upper bounds on the parameters. If a single number, this will be applied to all parameters. Default Inf.


Vector if indices of the parameters to be masked. These parameters will NOT be altered by the algorithm. Note that the mechanism here is different from that in nlxb which uses the names of the parameters.


A vector of fixed weights. The objective function that will be minimized is the sum of squares where each residual is multiplied by the square root of the corresponding weight. Default (NULL) implies unit weights.


Data frame of variables used by resfn and jacfn to compute the required residuals and Jacobian.


A list of controls for the algorithm. These are:


Monitor progress if TRUE. Default is FALSE.


Default is phi=1, which adds phi*Identity to Jacobian inner product.


Initial Marquardt adjustment (Default 0.0001). Odd spelling is deliberate.


Shift to test for floating-point equality. Default is 100.


Factor to use to increase lamda. Default is 10.


Factor to use to decrease lamda is lamdec/laminc. Default lamdec=4.


Maximum function (sum of squares) evaluations. Default is 10000, which is extremely aggressive.


Maximum number of Jacobian evaluations. Default is 5000.


Stepsize to use to computer numerical Jacobian approximatin. Default is 1e-7.


Default is TRUE. Use a termination test of the relative offset orthogonality type. Useful for nonlinear regression problems.


Default is TRUE. Exit the function if the sum of squares falls below (100 * .Machine$double.eps)^4 times the initial sumsquares. This is a test for a “small” sum of squares, but there are problems which are very extreme for which this control needs to be set FALSE.


Any data needed for computation of the residual vector from the expression rhsexpression - lhsvar. Note that this is the negative of the usual residual, but the sum of squares is the same. It is not clear how the dot variables should be used, since data should be in 'data'.


nlfb attempts to solve the nonlinear sum of squares problem by using a variant of Marquardt's approach to stabilizing the Gauss-Newton method using the Levenberg-Marquardt adjustment. This is explained in Nash (1979 or 1990) in the sections that discuss Algorithm 23.

In this code, we solve the (adjusted) Marquardt equations by use of the qr.solve(). Rather than forming the J'J + lambda*D matrix, we augment the J matrix with extra rows and the y vector with null elements.


A list of the following items


A named vector giving the parameter values at the supposed solution.


The sum of squared residuals at this set of parameters.


The residual vector at the returned parameters.


The jacobian matrix (partial derivatives of residuals w.r.t. the parameters) at the returned parameters.


The number of residual evaluations (sum of squares computations) used.


The number of Jacobian evaluations used.


John C Nash <>


Nash, J. C. (1979, 1990) _Compact Numerical Methods for Computers. Linear Algebra and Function Minimisation._ Adam Hilger./Institute of Physics Publications


See Also

Function nls(), packages optim and optimx.


cat("See examples in nls-package.Rd\n")

nlsr documentation built on Aug. 20, 2021, 9:08 a.m.