I’m trying to minimize a custom function. It should accept five parameters and the data set and do all sorts of calculations, producing a single number as an output. I want to find a combination of five input parameters which yields smallest output of my function.

**Answer**

I wrote a post listing a few tutorials using `optim`

.

Here is a quote of the relevant section:

`optim`

and a custom created objectivefunction, such as a minus log-likelihood function provides a powerful tool for

parameter estimation of custom models.

- Scott Brown’s tutorial includes an example of

this. - Ajay Shah has an example

of writing a likelihood function and then getting a maximum likelihood

estimate using`optim`

. - Benjamin Bolker has great material available on the web from his book

Ecological Models and Data in R.

PDFs, Rnw, and R code for early versions of the chapters are provided on

the website.

Chapter 6 (likelihood and all that)

, 7 (the gory details of model fitting),

and 8 (worked likelihood estimation examples). - Brian Ripley has a set of slides on simulation and optimisation in R.

In particular it provides a useful discussion of the various optimisation

algorithms available using`optim`

“.

**Attribution***Source : Link , Question Author : user333 , Answer Author : Henrik*