[R] for help about MLE in R

Peter Dalgaard p.dalgaard at biostat.ku.dk
Fri Feb 6 01:07:25 CET 2004


"Edward Sun" <edwardweisun at hotmail.com> writes:

> Dear Sir,
> 
> I am using R to estimate two parameters in Normal distribution. I
> generated 100 normal distributed numbers, on which to estimate the
> parameter. The syntax is:
> 
> >fn<-function(x)-50*log((y)^2)+50*log(2*pi)-(1/2*(z^2))*(sum((x-y)^2))
> >out<-nlm(fn, x, hessian=TRUE)
> 
> but it does not work. Could you please help me to compose the syntax
> for the purpose that find maximum likelihood estimates of the
> generated random numbers by direct maximization of the likelihood
> function?

Apologies if this wasn't a homework question, but

a) That is not the likelihood function. Try fn(0). What is the z doing
in there? The log((y)^2) makes the whole thing vector valued, which
you do not want. Get this right first and perhaps do a plot of the
function values.

b) Second argument to nlm is supposed to be a starting value for the
parameter (e.g., 0.5), and you seem to be thinking differently. Also
note that you are feeding the log-likelihood to a *minimizer*.

-- 
   O__  ---- Peter Dalgaard             Blegdamsvej 3  
  c/ /'_ --- Dept. of Biostatistics     2200 Cph. N   
 (*) \(*) -- University of Copenhagen   Denmark      Ph: (+45) 35327918
~~~~~~~~~~ - (p.dalgaard at biostat.ku.dk)             FAX: (+45) 35327907




More information about the R-help mailing list