[R] mle2 simple question - sigma?

Rice, Cliff G (DFW) Cliff.Rice at dfw.wa.gov
Wed Nov 19 23:26:59 CET 2008

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
names(RegData)<-c("x", "y")

linregfun = function(a,b,sigma) {
  Y.pred = a+b*x
SigA<-mle2(linregfun, start=list(a=0.5, b=2), data=RegData)
SigB<-mle2(y~dnorm(mean=a+b*x,sd=sigma),start=list(a=0.5, b=2),

I get:
#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?

More information about the R-help mailing list