Re: [R] Optim(...) estimate of stDev far too low

2009-09-30 Thread Peter Ehlers
Luis, I don't think that you want log() in fn. Try it with pdf=-sum(dnorm(x, media, st, TRUE)) (and note the x, rather than xx). -Peter Ehlers Luis Ridao Cruz wrote: R-help, I'm just trying to find the ML (maximum likelihood) estimates of the mean and standard deviation of a set of observ

[R] Optim(...) estimate of stDev far too low

2009-09-30 Thread Luis Ridao Cruz
R-help, I'm just trying to find the ML (maximum likelihood) estimates of the mean and standard deviation of a set of observations: >xx=c(2.5,3.5,4,6,6.5,7.5) fn<-function(params,x=xx) { media<-params[1] st <-params[2] pdf=-sum(dnorm(log(xx),log(media),st,TRUE)) return(pdf) } optim(c(mu,stdev