nlminb                 package:stats                 R Documentation

_O_p_t_i_m_i_z_a_t_i_o_n _u_s_i_n_g _P_O_R_T _r_o_u_t_i_n_e_s

_D_e_s_c_r_i_p_t_i_o_n:

     Unconstrained and constrained optimization using PORT routines.

_U_s_a_g_e:

     nlminb(start, objective, gradient = NULL, hessian = NULL,
            scale = 1, control = list(), lower = -Inf, upper = Inf, ...)

_A_r_g_u_m_e_n_t_s:

   start: numeric vector, initial values for the parameters to be
          optimized. 

objective: Function to be minimized.  Must return a scalar value
          (possibly NA/Inf).  The first argument to 'objective' is the
          vector of parameters to be optimized, whose initial values
          are supplied through 'start'.  Further arguments (fixed
          during the course of the optimization) to 'objective' may be
          specified as well (see '...'). 

gradient: Optional function that takes the same arguments as
          'objective' and evaluates the gradient of 'objective' at its
          first argument.  Must return a vector as long as 'start'. 

 hessian: Optional function that takes the same arguments as
          'objective' and evaluates the hessian of 'objective' at its
          first argument.  Must return a square matrix of order
          'length(start)'.  Only the lower triangle is used. 

   scale: See PORT documentation (or leave alone).

 control: A list of control parameters. See below for details.

lower, upper: vectors of lower and upper bounds, replicated to be as
          long as 'start'.  If unspecified, all parameters are assumed
          to be unconstrained. 

     ...: Ffurther arguments to be supplied to 'objective'.

_D_e_t_a_i_l_s:

     The PORT documentation is at <URL:
     http://netlib.bell-labs.com/cm/cs/cstr/153.pdf>.

_V_a_l_u_e:

     A list with components: 

     par: The best set of parameters found.

objective: The value of 'objective' corresponding to 'par'.

convergence: An integer code. '0' indicates successful convergence. 

 message: A character string giving any additional information returned
          by the optimizer, or 'NULL'. For details, see PORT
          documentation. 

iterations: Number of iterations performed.

evaluations: Number of objective function and gradient function
          evaluations

_C_o_n_t_r_o_l _p_a_r_a_m_e_t_e_r_s:

     Possible names in the 'control' list and their default values are:

     '_e_v_a_l._m_a_x' Maximum number of evaluations of the objective function
          allowed.  Defaults to 200.

     '_i_t_e_r._m_a_x' Maximum number of iterations allowed. Defaults to 150.

     '_t_r_a_c_e' The value of the objective function and the parameters is
          printed every trace'th iteration.  Defaults to 0 which
          indicates no trace information is to be printed.

     '_a_b_s._t_o_l' Absolute tolerance.  Defaults to '1e-20'.

     '_r_e_l._t_o_l' Relative tolerance.  Defaults to '1e-10'.

     '_x._t_o_l' X tolerance.  Defaults to '1.5e-8'.

     '_s_t_e_p._m_i_n' Minimum step size.  Defaults to '2.2e-14'.

_A_u_t_h_o_r(_s):

     (of R port) Douglas Bates and Deepayan Sarkar.

_R_e_f_e_r_e_n_c_e_s:

     <URL: http://netlib.bell-labs.com/netlib/port/>

_S_e_e _A_l_s_o:

     'optim' and 'nlm'.

     'optimize' for one-dimensional minimization and 'constrOptim' for
     constrained optimization.

_E_x_a_m_p_l_e_s:

     x <- rnbinom(100, mu = 10, size = 10)
     hdev <- function(par) {
         -sum(dnbinom(x, mu = par[1], size = par[2], log = TRUE))
     }
     nlminb(c(9, 12), hdev)
     nlminb(c(20, 20), hdev, lower = 0, upper = Inf)
     nlminb(c(20, 20), hdev, lower = 0.001, upper = Inf)

     ## slightly modified from the S-PLUS help page for nlminb
     # this example minimizes a sum of squares with known solution y
     sumsq <- function( x, y) {sum((x-y)^2)}
     y <- rep(1,5)
     x0 <- rnorm(length(y))
     nlminb(start = x0, obj = sumsq, y = y)
     # now use bounds with a y that has some components outside the bounds
     y <- c( 0, 2, 0, -2, 0)
     nlminb(start = x0, obj = sumsq, lower = -1, upper = 1, y = y)
     # try using the gradient
     sumsq.g <- function(x,y) 2*(x-y)
     nlminb(start = x0, obj = sumsq, grad = sumsq.g,
            lower = -1, upper = 1, y = y)
     # now use the hessian, too
     sumsq.h <- function(x,y) diag(2, nrow = length(x))
     nlminb(start = x0, obj = sumsq, grad = sumsq.g, hes = sumsq.h,
            lower = -1, upper = 1, y = y)

     ## Rest lifted from optim help page

     fr <- function(x) {   ## Rosenbrock Banana function
         x1 <- x[1]
         x2 <- x[2]
         100 * (x2 - x1 * x1)^2 + (1 - x1)^2
     }
     grr <- function(x) { ## Gradient of 'fr'
         x1 <- x[1]
         x2 <- x[2]
         c(-400 * x1 * (x2 - x1 * x1) - 2 * (1 - x1),
            200 *      (x2 - x1 * x1))
     }
     nlminb(c(-1.2,1), fr)
     nlminb(c(-1.2,1), fr, grr)

     flb <- function(x)
         { p <- length(x); sum(c(1, rep(4, p-1)) * (x - c(1, x[-p])^2)^2) }
     ## 25-dimensional box constrained
     ## par[24] is *not* at boundary
     nlminb(rep(3, 25), flb, 
               lower=rep(2, 25),
               upper=rep(4, 25)) 

