x <- 0:10
y <- c(26, 17, 13, 12, 20, 5, 9, 8, 5, 4, 8)
d <- data.frame(x,y)
## we have a choice here: (1) don't impose boundaries on the parameters,
## put up with warning messages about NaN values:
fit1 <- mle2(y~dpois(lambda=ymax/(1+x/xhalf)),
start=list(ymax=1,xhalf=1),
data=d)
p1 <- suppressWarnings(profile(fit1))
plot(p1,main=c("first","second"),
xlab=c(~y[max],~x[1/2]),ylab="Signed square root deviance",
show.points=TRUE)
suppressWarnings(confint(fit1)) ## recomputes profile
confint(p1) ## operates on existing profile
suppressWarnings(confint(fit1,method="uniroot"))
## alternatively, we can use box constraints to keep ourselves
## to positive parameter values ...
fit2 <- update(fit1,method="L-BFGS-B",lower=c(ymax=0.001,xhalf=0.001))
if (FALSE) {
p2 <- profile(fit2)
plot(p2,show.points=TRUE)
## but the fit for ymax is just bad enough that the spline gets wonky
confint(p2) ## now we get a warning
confint(fit2,method="uniroot")
## bobyqa is a better-behaved bounded optimizer ...
## BUT recent (development, 2012.5.24) versions of
## optimx no longer allow single-parameter fits!
if (require(optimx)) {
fit3 <- update(fit1,
optimizer="optimx",
method="bobyqa",lower=c(ymax=0.001,xhalf=0.001))
p3 <- profile(fit3)
plot(p3,show.points=TRUE)
confint(p3)
}
}
Run the code above in your browser using DataLab