Skip to content
Prev 304292 / 398503 Next

Optim Problem

On 28-08-2012, at 03:12, Christopher Kelvin wrote:

            
Running the code as given gives an error message 

Error in x[1:b] <- (m[, 1]) : object 'x' not found

So insert

x <- numeric(b) 

just before the for(i in 1:rr)

gives an error message

Error in fn(par, ...) : unused argument(s) (par)
Calls: optim -> <Anonymous> -> fn

Not surprising since the argument list of function z should have the parameter vector that optim is supposed to optimize as first argument.
So change the definition to

z<-function(p,data ){ 
rate<-p[2]
log1<--(n/log(p[2]))-sum(t/(p[2]))+sum(log(exp(-(u/(p[2])))-exp(-(v/(p[2])))))
return(-log1)
}

and this give the error message

Error in optim(start, fn = z, data = h, hessian = T) : 
  function cannot be evaluated at initial parameters

So I give up.
Please fix the example to at least something that is without these errors.

Berend