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

Luis Ridao Cruz luisr at hav.fo
Wed Sep 30 15:51:51 CEST 2009


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),fn,method="L-BFGS-B",lower=c(0.001, 0.001)
        ,upper = rep(Inf, 2), hessian=TRUE, control=list(trace=1))

iter    0 value 3.011784
final  value 2.802694 
converged
$par
[1] 4.6597779 0.3860387

$value
[1] 2.802694

$counts
function gradient 
      17       17 

$convergence
[1] 0

$message
[1] "CONVERGENCE: REL_REDUCTION_OF_F <= FACTR*EPSMCH"

WHich gives an estimate of stDev = 0.38
while the empirical stDev = 1.94

Is there anything wrong above in the code?

Thanks in advance




More information about the R-help mailing list