The type double function is imsls_d_nonlinear_regression.
Required Arguments
floatfcn (intn_independent, floatxi[], intn_parameters, floattheta[]) User-supplied function to evaluate the function that defines the nonlinear regression problem where xi is an array of length n_independent at which point the function is evaluated and theta is an array of length n_parameters containing the current values of the regression coefficients. Function fcn returns a predicted value at the point xi. In the following, f(xi;θ), or just fi, denotes the value of this function at the point xi, for a given value of θ. (Both xi and θ are arrays.)
intn_parameters (Input) Number of parameters to be estimated.
intn_observations (Input) Number of observations.
intn_independent (Input) Number of independent variables.
floatx[] (Input) Array of size n_observations by n_independent containing the matrix of independent (explanatory) variables.
floaty[] (Input) Array of length n_observations containing the dependent (response) variable.
Return Value
A pointer to an array of length n_parameters containing a solution, for the nonlinear regression coefficients. To release this space, use imsls_free. If no solution can be computed, then NULL is returned.
Synopsis with Optional Arguments
#include<imsls.h>
float*imsls_f_nonlinear_regression (floatfcn(), int n_parameters, intn_observations, intn_independent, floatx[], floaty[],
IMSLS_THETA_GUESS, floattheta_guess[] (Input) Array with n_parameters components containing an initial guess. Default: theta_guess[] = 0.
IMSLS_JACOBIAN, voidjacobian (intn_independent, floatxi[], intn_parameters, floattheta[], floatfjac[]) (Input/Output) User-supplied function to compute the i‑th row of the Jacobian, where the n_independent data values corresponding to the i‑th row are input in xi. Argument theta is an array of length n_parameters containing the regression coefficients for which the Jacobian is evaluated, fjac is the computed n_parameters row of the Jacobian for observation i at theta. Note that each derivative ∂f(xi)/∂θj should be returned in fjac [j− 1] for j = 1, 2, ..., n_parameters.
IMSLS_THETA_SCALE, floattheta_scale[] (Input) Array with n_parameters components containing the scaling array for θ. Array theta_scale is used mainly in scaling the gradient and the distance between two points. See keywords IMSLS_GRADIENT_EPS and IMSLS_STEP_EPS for more details. Default: theta_scale[] = 1.
IMSLS_GRADIENT_EPS, floatgradient_eps (Input) Scaled gradient tolerance. The j-th component of the scaled gradient at θ is calculated as
where g = ∇F(θ), t = theta_scale, and
The value F(θ) is the sum of the squared residuals, SSE, at the point θ.
Convergence is declared if |gi| * max{|θi|, 1.0/ti}/SSE is less than gradient_eps for i= 0, 1, 2, …, n_parameters, where gi is the i‑th component of an internal intermediate gradient vector. Default:
( in double, where ɛ is the machine precision)
IMSLS_STEP_EPS, floatstep_eps (Input) Scaled step tolerance. The j-th component of the scaled step from points θ and θʹ is computed as
where t = theta_scale
Convergence is declared if |gn+ i|/ max{|θi|, 1.0/ti} is less than step_eps for i = 0, 1, 2, …, n, where gn+ i is the i‑th component of the last step and n = n_parameters.
Default: step_eps = ɛ2/3,where ɛ is the machine precision
IMSLS_SSE_REL_EPS, floatsse_rel_eps (Input) Relative SSE function tolerance.
Convergence is declared if the change in SSE is less than or equal to sse_rel_eps * SSE in absolute value.
Default: sse_rel_eps = max(10-10, ɛ2/3), max(10-20, ɛ2/3) in double, where ɛ is the machine precision
IMSLS_SSE_ABS_EPS, floatsse_abs_eps (Input) Absolute SSE function tolerance.
Convergence is declared if SSE is less than sse_abs_eps.
Default: sse_abs_eps = max(10-20,ɛ2), max(10-40, ɛ2) in double, where ɛ is the machine precision
IMSLS_MAX_STEP, floatmax_step (Input) Maximum allowable step size.
Default: max_step = 1000 max (ɛ1, ɛ2), where ɛ1 = (tTθ0)1/2, ɛ2 = ∥t∥2, t = theta_scale, and θ0 = theta_guess
IMSLS_INITIAL_TRUST_REGION, floattrust_region (Input) Size of initial trust region radius. The default is based on the initial scaled Cauchy step.
IMSLS_GOOD_DIGIT, intndigit (Input) Number of good digits in the function. Default: machine dependent
IMSLS_MAX_ITERATIONS, intmax_itn (Input) Maximum number of iterations. Default: max_itn = 100
IMSLS_MAX_SSE_EVALUATIONS, intmax_sse_eval (Input) Maximum number of SSE function evaluations. Default: max_sse_eval = 400
IMSLS_MAX_JACOBIAN_EVALUATIONS, intmax_jacobian (Input) Maximum number of Jacobian evaluations. Default: max_jacobian = 400
IMSLS_TOLERANCE, floattolerance (Input) False convergence tolerance. Default: tolerance = 100* eps, where eps = imsls_f_machine(4) if single precision and eps = imsls_d_machine(4) if double precision
IMSLS_PREDICTED, float**predicted (Output) Address of a pointer to a real internally allocated array of length n_observations containing the predicted values at the approximate solution.
IMSLS_PREDICTED_USER, floatpredicted[] (Output) Storage for array predicted is provided by the user. See IMSLS_PREDICTED.
IMSLS_RESIDUAL, float**residual (Output) Address of a pointer to a real internally allocated array of length n_observations containing the residuals at the approximate solution.
IMSLS_RESIDUAL_USER, floatresidual[] (Output) Storage for array residual is provided by the user. See IMSLS_RESIDUAL.
IMSLS_R, float**r (Output) Address of a pointer to an internally allocated array of size n_parameters×n_parameters containing the R matrix from a QR decomposition of the Jacobian.
IMSLS_R_USER, floatr[] (Output) Storage for array r is provided by the user. See IMSLS_R.
IMSLS_R_COL_DIM, intr_col_dim (Input) Column dimension of array r. Default: r_col_dim = n_parameters
IMSLS_R_RANK, int*rank (Output) Rank of r. Argument rank less than n_parameters may indicate the model is overparameterized.
IMSLS_SSE, float*sse (Output) Residual sum of squares.
IMSLS_RETURN_USER, floattheta_hat[] (Output) User-allocated array of length n_parameters containing the estimated regression coefficients.
IMSLS_VARIANCE_COVARIANCE_MATRIX, float**var_covar (Output) Address of a pointer to an internally allocated array of size n_parameters×n_parameters containing the variance/covariance matrix of the coefficients.
IMSLS_VARIANCE_COVARIANCE_MATRIX_USER, floatvar_covar[] (Output) Storage for array var_covar is provided by the user. See IMSLS_VARIANCE_COVARIANCE_MATRIX.
IMSLS_FCN_W_DATA, floatfcn (intn_independent, floatxi[], intn_parameters, floattheta[]), void*data, (Input) User-supplied function to evaluate the function that defines the nonlinear regression problem, which also accepts a pointer to data that is supplied by the user. data is a pointer to the data to be passed to the user-supplied function. See the Passing Data to User-Supplied Functions at the beginning of this manual for more details.
IMSLS_JACOBIAN_W_DATA, voidjacobian (intn_independent, floatxi[], intn_parameters, floattheta[], floatfjac[]), void*data, (Input) User-supplied function to compute the i‑th row of the Jacobian, which also accepts a pointer to data that is supplied by the user. data is a pointer to the data to be passed to the user-supplied function. See the Passing Data to User-Supplied Functions at the beginning of this manual for more details.
Description
Function imsls_f_nonlinear_regression fits a nonlinear regression model using least squares. The nonlinear regression model is
where the observed values of the yi’s constitute the responses or values of the dependent variable, the known xi’s are the vectors of the values of the independent (explanatory) variables, θ is the vector of p regression parameters, and the ɛi’s are independently distributed normal errors with mean 0 and variance σ2. For this model, a least-squares estimate of θ is also a maximum likelihood estimate of θ.
The residuals for the model are as follows:
A value of θ that minimizes
is a least-squares estimate of θ. Function imsls_f_nonlinear_regression is designed so that the values of the function f(xi; θ) are computed one at a time by a user-supplied function.
Function imsls_f_nonlinear_regression is based on MINPACK routines LMDIF and LMDER by Moré et al. (1980) that use a modified Levenberg-Marquardt method to generate a sequence of approximations to a minimum point. Let
be the current estimate of θ. A new estimate is given by
where sc is a solution to the following:
Here
is the Jacobian evaluated at
The algorithm uses a “trust region” approach with a step bound of δc. A solution of the equations is first obtained for
μc = 0. If ∥sc∥2 < δc
this update is accepted; otherwise, μc is set to a positive value and another solution is obtained. The method is discussed by Levenberg (1944), Marquardt (1963), and Dennis and Schnabel (1983, pp. 129−147, 218−338).
If a user-supplied function is specified in IMSLS_JACOBIAN, the Jacobian is computed analytically; otherwise, forward finite differences are used to estimate the Jacobian numerically. In the latter case, especially if type float is used, the estimate of the Jacobian may be so poor that the algorithm terminates at a noncritical point. In such instances, the user should either supply a Jacobian function, use type double, or do both.
The first stopping criterion for imsls_f_nonlinear_regression occurs when SSE is less than the absolute function tolerance. The second stopping criterion occurs when the norm of the scaled gradient is less than the given gradient tolerance. The third stopping criterion occurs when the scaled distance between the last two steps is less than the step tolerance. The third stopping criterion also generates error IMSLS_LITTLE_FCN_CHANGE. The fourth stopping criterion occurs when the relative change in SSE is less than sse_rel_eps. The fourth stopping criterion also generates error code IMSLS_FALSE_CONVERGENCE. See Dennis and Schnabel (1983, pages 159−161, 278−280, and 347−348) for a discussion of stopping criteria and choice of tolerances.
On some platforms, imsls_f_nonlinear_regression can evaluate the user-supplied functions fcn and jacobian in parallel. This is done only if the function imsls_omp_options is called to flag user-defined functions as thread-safe. A function is thread-safe if there are no dependencies between calls. Such dependencies are usually the result of writing to global or static variables.
Programming Notes
Nonlinear regression allows substantial flexibility over linear regression because the user can specify the functional form of the model. This added flexibility can cause unexpected convergence problems for users that are unaware of the limitations of the software. Also, in many cases, there are possible remedies that may not be immediately obvious. The following is a list of possible convergence problems and some remedies. There is not a one-to-one correspondence between the problems and the remedies. Remedies for some problems also may be relevant for the other problems.
1. A local minimum is found. Try a different starting value. Good starting values often can be obtained by fitting simpler models. For example, for a nonlinear function.
good starting values can be obtained from the estimated linear regression coefficients
and
from a simple linear regression of ln y on ln x. The starting values for the nonlinear regression in this case would be
If an approximate linear model is not clear, then simplify the model by reducing the number of nonlinear regression parameters. For example, some nonlinear parameters for which good starting values are known could be set to these values in order to simplify the model for computing starting values for the remaining parameters.
2. The estimate of θ is incorrectly returned as the same or very close to the initial estimate. This occurs often because of poor scaling of the problem, which might result in the residual sum of squares being either very large or very small relative to the precision of the computer. The optional arguments allow control of the scaling.
3. The model is discontinuous as a function of θ. (The functionf(x;θ) can be a discontinuous function of x.)
4. Overflow occurs during the computations. Make sure the user-supplied functions do not overflow at some value ofθ.
5. The estimate of θ is going to infinity. A parameterization of the problem in terms of reciprocals may help.
6. Some components ofθ are outside known bounds. This can sometimes be handled by making a function that produces artificially large residuals outside of the bounds (even though this introduces a discontinuity in the model function).
Examples
Example 1
In this example (Draper and Smith 1981, p. 518), the following nonlinear model is fit:
Scaled step tolerance satisfied. The current point may be an approximate local solution, but it is also possible that the algorithm is making very slow progress and is not near a solution or that “step_eps” is too big.
Warning Errors
IMSLS_LITTLE_FCN_CHANGE
Both the actual and predicted relative reductions in the function are less than or equal to the relative function tolerance.
IMSLS_TOO_MANY_ITN
Maximum number of iterations exceeded.
IMSLS_TOO_MANY_JACOBIAN_EVAL
Maximum number of Jacobian evaluations exceeded.
IMSLS_UNBOUNDED
Five consecutive steps have been taken with the maximum step length.
IMSLS_FALSE_CONVERGENCE
The iterates appear to be converging to a noncritical point.
Fatal Errors
IMSLS_TOO_MANY_FCN_EVAL
Maximum number of function evaluations exceeded.
IMSLS_STOP_USER_FCN
Request from user supplied function to stop algorithm. User flag = "#".