minFit: Methods for Function 'minFit' in Package 'momentfit' ~~

minFit-methodsR Documentation

Methods for Function minFit in Package momentfit ~~

Description

This is a method to minimize a function using an algorithm defined by the minAlgo class. This is way of homogenizing the call of minimization functions. It is used by solveGmm to offer the possibility of using external solvers.

Usage

## S4 method for signature 'minAlgoNlm'
minFit(object, start, fct, gr,
...)

## S4 method for signature 'minAlgoStd'
minFit(object, start, fct, gr,
...)

Arguments

object

A object of class minAlgo created by algoObj.

start

A vector of starting values.

fct

The function to minimize.

gr

An optional function that returns the gradient. The arguments of fct and gr must be identical.

...

Arguments to pass the optimization algorithm and to the functions fct and gr.

Value

A list with the following elements:

solution

The vector of solution for the minimization problem.

value

The value of the function at the solution.

message

The convergence message from the solver.

convergence

The convergence code from the solver.

Methods

signature(model = "minAlgoStd")

This class includes all solvers that have a standard set of arguments. These arguments are the function, the gradient and the starting values (e.g. optim).

signature(model = "minAlgoNlm")

This method is for solvers like nlm. The solver is quite different from any other solvers, because the gradient is returned by the main function as an attribute. That's why it needs a different method to use it.

Examples

f <- function(x, a=2, b=4) (x[1]-a)^2+(x[2]-b)^2
g <- function(x, a=2, b=4) c(2*(x[1]-a), 2*(x[2]-b))

## Using optim

algo1 <- algoObj("optim")
minFit(algo1, start=c(1,1), fct=f, gr=g, method="BFGS", b=6)

## Using nlm: very different structure, but same call

algo2 <- algoObj("nlm")
minFit(algo2, start=c(1,1), fct=f, gr=g, b=6)


momentfit documentation built on June 26, 2024, 3 p.m.