Next: rhatvar()
Up: Arima Macros Help File
Previous: neg2logLarma()
Contents
Usage:
nlreg(b,x,y [,func],param [,resid:resmac,crit:vec,active:active,\
maxit:itmax,minit:itmin,print:T, keep:T, quiet:T])
b REAL vector of starting values for the iterative fitting
x REAL matrix
y REAL vector
func macro; func(b,x,param) computes a vector of fitted values for y
(not allowed with 'resid')
param a vector or structure of additional parameters for func or NULL
vec vector(numsig, nsigsq, delta), 3 criteria for convergence
numsig = number of digits of accuracy in coefficients
nsiqsq = number of digits of accuracy in residual SS
delta = norm of gradient threshhold
active LOGICAL vector the same length as b
resmac macro; resmac(b,x,y [,param]) computes a vector of residuals from
a function defined or directly referenced in resmac.
func should be omitted when resid:resmac is an argument.
Conversely, when resid:resmac is not an argument, argument
func is required
deriv optional macro; deriv(b,x,y,param,j) computes derivative of
f with respect to b[j], returning a vector the same length as y
itmin the minimum number >= 0 of iterations performed
itmax the maximum number >= itmin of iterations allowed
print If T, partial results printed at each iteration
keep If T, nlreg() returns the structure returned by levmar()
with components, coefs, hessian, jacobian, gradient,
rss, residuals, nobs, iter, iconv plus component edf
quiet If F (default, unless keep:T), no summary results are
printed. quiet:T is illegal without keep:T
|
Keywords:
nonlinear fitting
Proper help has not yet been written. The following is based on the
comment lines in the macro header.
nlreg() is a macro for carrying out nonlinear least squares regression.
It uses macro levmar() to do the actual minimization. The function
fitted and/or residuals from the function are specified by macros in the
argument list. Derivatives may be computed by a macro. If no macro to
compute derivatives is provided, derivatives are computed numerically.
Usage:
nlreg(b,x,y [,func],param [,resid:resmac, deriv:deriv, crit:vec,\
active:active,maxit:itmax,minit:itmin,print:T, keep:T, quiet:T])
b REAL vector of starting values for the iterative fitting
x REAL matrix
y REAL vector
func macro; func(b,x,param) computes a vector of fitted values for y
(not allowed with 'resid')
param a vector or structure of additional parameters for func or NULL
vec vector(numsig, nsigsq, delta), 3 criteria for convergence
numsig = number of digits of accuracy in coefficients
nsiqsq = number of digits of accuracy in residual SS
delta = norm of gradient threshhold
active LOGICAL vector the same length as b. active[i] = F means
b[i] is kept constant and does not participate in iteration
resmac macro; resmac(b,x,y [,param]) computes a vector of residuals from
a function defined or directly referenced in resmac. func
should be omitted when resid:resmac is an argument. Conversely,
when resid:resmac is not an argument, argument func is required
deriv optional macro; deriv(b,x,y,param,j) computes derivative of
f with respect to b[j], returning a vector the same length as y
itmin the minimum number >= 0 of iterations performed
itmax the maximum number >= itmin of iterations allowed
print If T, partial results printed at each iteration
keep If T, nlreg() returns the structure returned by levmar()
with components, coefs, hessian, jacobian, gradient,
rss, residuals, nobs, iter, iconv plus component edf
quiet If F (default, unless keep:T), no summary results are
printed. quiet:T is illegal without keep:T
Example:
Fit the function b1 + b2*b3^x to data from Snedecor and Cochran with
starting values b1 = b2 = 40 and b3 = 1.
Cmd> x <- vector(0,1,2,3,4,5)
Cmd> y <- vector(57.5, 45.7, 38.7, 35.3, 33.1, 32.3)
Cmd> func <- macro("@b <- $1; @b[1]+@b[2]*@b[3]^($2)", dollars:T)
Cmd> nlreg(vector(40,40,1),x,y,func) # arg 1 start values
Coef StdErr t P Value
B 1 30.814 0.25646 120.15 1.271e-06
B 2 26.738 0.28744 93.021 2.7387e-06
B 3 0.54948 0.0094835 57.94 1.1326e-05
---------------------------------------------------
N: 6, MSE: 0.040751, DF: 3
Converged with relative change in all coefs < 1e-05 in 7 iterations
Cmd> funcres <- macro("($3) - func($1,$2)") # computes residuals
Cmd> nlreg(vector(40,40,1),x,y,resid:funcres) # identical
Coef StdErr t P Value
B 1 30.814 0.25646 120.15 1.271e-06
B 2 26.738 0.28744 93.021 2.7387e-06
B 3 0.54948 0.0094835 57.94 1.1326e-05
---------------------------------------------------
N: 6, MSE: 0.040751, DF: 3
Converged with relative change in all coefs < 1e-05 in 7 iterations
See also levmar().
Gary Oehlert
2003-01-15