I have successfully implemented a maximum likelihood estimation of model parameters with bounds by creating a likelihood function that returns NA or Inf values when the function is out of bounds. I optimize the function using optim in R
.
detailed example available on github
Quick example:
likelihood.fun<-function(par, ...){
likelihood<- -sum(dnorm(..., log=T))
if(any(c(par[1]<0,
par[1]>5,
par[2]>5,
par[2]<0)){likelihood<-NA}
return(likelihood)
}
Is this equivalent to box optimization or deprecated compare to box optimization?
If this is not equivalent:
How can I implement this using
optim(..., method="L-BFGS-B", lower=c(...), upper=c(...))
from example, this does not seem to work:
optim(..., method="L-BFGS-B", lower=c(0,0), upper=c(5,5))
or
constrOptim()
This is linked to this question on constrOptim.