tadpole_R_fit <- function(data=ReedfrogSizepred,
                          start=list(c=0.45,d=13,g=1)) {
  mle2(Kill~dbinom(c*((TBL/d)*exp(1-TBL/d))^g,size=Exposed),
       start=start,
       data=data,
       method="L-BFGS-B",
       lower=c(c=0.003,d=10,g=0),
       upper=c(c=0.8,d=20,g=50),
       control=list(parscale=c(c=0.5,d=10,g=1)))
}

tadpole_R_fitv <- function(data=ReedfrogSizepred,
                           start=list(c=0.45,d=13,g=1)) {
  mle2(Kill~dbinom(c*((TBL/d)*exp(1-TBL/d))^g,size=Exposed),
       start=start,
       data=data,
       optimizer="optimx",
       method="Rvmmin",
       lower=c(c=0.003,d=10,g=0),
       upper=c(c=0.8,d=20,g=50),
       control=list(parscale=c(c=0.5,d=10,g=1)))
}

tadpole_R_profile <- function(fit) {
  profile(fit)
}

tadpole_R_mcmc <- function(fit) {
  require(MCMCpack)
  mcmcfun <- function(p) {
    r <- -do.call(fit@minuslogl,as.list(p))
    if (!is.finite(r)) -100 else r
  }
  MCMCmetrop1R(mcmcfun,
               theta.init=coef(fit),
               mcmc=18000,thin=9)
}

