Skip to content
Prev 81931 / 398506 Next

Minimizing a Function with three Parameters

voodooochild at gmx.de wrote:
Hi, Andreas,

You've misread the help file for ?optim.

  fn: A function to be minimized (or maximized), with first
           argument the vector of parameters over which minimization is
           to take place.  It should return a scalar result.

So, your objective function should look like

gl <- function(beta, x) {
   beta0 <- beta[1]
   beta1 <- beta[2]
   alpha <- beta[3]
   v1 <- l1(beta0, beta1, alpha, x)^2
   v2 <- l2(beta0, beta1, alpha, x)^2
   v3 <- l3(beta0, beta1, alpha, x)^2
   v1 + v2 + v3
}

Also, are you aware of ?mle in the stats4 package?

HTH,

--sundar