# nlxb: Nash variant of Marquardt nonlinear least squares solution... In nlsr: Functions for Nonlinear Least Squares Solutions

## Description

Given a nonlinear model expressed as an expression of the form `lhs ~ formula_for_rhs` and a start vector where parameters used in the model formula are named, 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.

## Usage

 ```1 2``` ``` nlxb(formula, start, trace=FALSE, data, lower=-Inf, upper=Inf, masked=NULL, weights=NULL, control) ```

## Arguments

 `formula` This is a modeling formula of the form (as in `nls`) `lhsvar ~ rhsexpression` for example, `y ~ b1/(1+b2*exp(-b3*tt))` You may also give this as a string. Note that the residuals are computed within this code using `residual <- rhsexpression - lhsvar` which is the negative of the usual choice, but the sum of squares is the same. `start` A named parameter vector. For our example, we could use `start=c(b1=1, b2=2.345, b3=0.123)` `trace` Logical `TRUE` if we want intermediate progress to be reported. Default is `FALSE`. `data` A data frame containing the data of the variables in the formula. This data may, however, be supplied directly in the parent frame. `lower` Lower bounds on the parameters. If a single number, this will be applied to all parameters. Default `-Inf`. `upper` Upper bounds on the parameters. If a single number, this will be applied to all parameters. Default `Inf`. `masked` Character vector of quoted parameter names. These parameters will NOT be altered by the algorithm. Masks may also be defined by setting lower and upper bounds equal for the parameters to be fixed. Note that the starting parameter value must also be the same as the lower and upper bound value. `weights` 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. `control` A list of controls for the algorithm. These are: `watch`Monitor progress if `TRUE`. Default is `FALSE`. `phi`Default is `phi=1`, which adds `phi*Identity` to Jacobian inner product. `lamda`Initial Marquardt adjustment (Default `0.0001`). Odd spelling is deliberate. `offset`Shift to test for floating-point equality. Default is `100`. `laminc`Factor to use to increase `lamda`. Default is `10`. `lamdec`Factor to use to decrease `lamda` is `lamdec/laminc`. Default `lamdec=4`. `femax`Maximum function (sum of squares) evaluations. Default is `10000`, which is extremely aggressive. `jemax`Maximum number of Jacobian evaluations. Default is `5000`. `rofftest`Default is `TRUE`. Use a termination test of the relative offset orthogonality type. Useful for nonlinear regression problems. `smallsstest`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`.

## Details

`nlxb` 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.

## Value

A list of the following items

 `coefficients` A named vector giving the parameter values at the supposed solution. `ssquares` The sum of squared residuals at this set of parameters. `resid` The residual vector at the returned parameters. `jacobian` The jacobian matrix (partial derivatives of residuals w.r.t. the parameters) at the returned parameters. `feval` The number of residual evaluations (sum of squares computations) used. `jeval` The number of Jacobian evaluations used.

## Author(s)

John C Nash <nashjc@uottawa.ca>

## References

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

others!!

Function `nls()`, packages `optim` and `optimx`.
 `1` ```cat("See examples in nlsr-package.Rd\n") ```