[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
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?
Thanks,
Cliff



More information about the R-help mailing list