maxNR(fn, grad = NULL, hess = NULL, start, print.level = 0,
tol = 1e-08, reltol=sqrt(.Machine$double.eps), gradtol = 1e-06,
steptol = 1e-10, lambdatol = 1e-06, qrtol = 1e-10,
iterlim = 15,
constPar = NULL, activePar=rep(TRUE, nParam), ...)
fn
should
return NA
. See details for constaNULL
, numeric
gradient is used. It must return a gradient vector, or matrix where
columns correspond to individual parameters. The column sums
are treated as gradient components (this is ustol
, return
code=2
.gradtol
, return code=1
.NA
, the step length
is halved and a new attempt is made. This procedure is repeated
until step < steptol
-lambdatol
, a suitable diagonal matrix is subtracted from the
Hessian (quadratic hill-climbing) in oiterlim
iterations, return code=4
.fn
, grad
and
hess
.fn
value at maximum (the last calculated value
if not converged).code
.code=3
with following components:
fn
value at theta0
}
One way is to put
constPar
to non-NULL. Second possibility is to signal by
fn
which parameters are constant and change the values of the
parameter vector. The value of fn
may have following attributes:
constVal
and newVal
is that the
latter parameters are not set to constants. If the attribute
newVal
is present, the new function value is allowed to be below
the previous one.
Goldfeld, S. M. and Quandt, R. E., 1972, Nonlinear Methods in Econometrics. Amsterdam: North-Holland
nlm
for Newton-Raphson optimization,
optim
for different gradient-based optimization
methods.## ML estimation of exponential duration model:
t <- rexp(100, 2)
loglik <- function(theta) sum(log(theta) - theta*t)
## Note the log-likelihood and gradient are summed over observations
gradlik <- function(theta) sum(1/theta - t)
hesslik <- function(theta) -100/theta^2
## Estimate with numeric gradient and Hessian
a <- maxNR(loglik, start=1, print.level=2)
summary(a)
## You would probably prefer 1/mean(t) instead ;-)
## Estimate with analytic gradient and Hessian
a <- maxNR(loglik, gradlik, hesslik, start=1)
summary(a)
Run the code above in your browser using DataLab