[R] mle2 simple question - sigma?

Peter Dalgaard p.dalgaard at biostat.ku.dk
Thu Nov 20 02:16:52 CET 2008


Rice, Cliff G (DFW) wrote:
> I'm trying to get started with maximum likelihood estimation with a
> simple regression equivalent out of Bolker (Ecological Models and Data
> in R, p302).
> 
> With this code:
> #Basic example regression
> library(bbmle)
> RegData<-data.frame(c(0.3,0.9,0.6),c(1.7,1.1,1.5))
> names(RegData)<-c("x", "y")
> 
> linregfun = function(a,b,sigma) {
>   Y.pred = a+b*x
>   -sum(dnorm(y,mean=Y.pred,sd=sigma,log=TRUE))
> }
> SigA<-mle2(linregfun, start=list(a=0.5, b=2), data=RegData)
> #Or
> SigB<-mle2(y~dnorm(mean=a+b*x,sd=sigma),start=list(a=0.5, b=2),
> data=RegData)
> 
> I get:
> #Messages
> #SigA>>Error in dnorm(y, mean = Y.pred, sd = sigma, log = TRUE) :
> #  element 3 is empty;
> #   the part of the args list of '.Internal' being evaluated was:
> #   (x, mean, sd, log)
> #SigB>>Error in eval(expr, envir, enclos) : object "sigma" not found
> 
> Obviously, I'm missing something, but what?

A starting value for sigma, I think.

(Incidentally, if you start with sigma close to its apparent MLE of 
0.047, it refuses to converge from those starting values for a and b.)


-- 
    O__  ---- Peter Dalgaard             Øster Farimagsgade 5, Entr.B
   c/ /'_ --- Dept. of Biostatistics     PO Box 2099, 1014 Cph. K
  (*) \(*) -- University of Copenhagen   Denmark      Ph:  (+45) 35327918
~~~~~~~~~~ - (p.dalgaard at biostat.ku.dk)              FAX: (+45) 35327907



More information about the R-help mailing list