[R] Maximization under constraits

Ben Bolker bolker at ufl.edu
Fri Jul 25 19:32:33 CEST 2008


Daniela Garavaglia <danygaravaglia84 <at> virgilio.it> writes:

> 
> I'm looking for a R function which can maximise this logliklihood function,
> under the constraits a>0 e b>0
> 
> f<-function(param){
> 
>   a<-param[1]
> 
>   b <-param[2]
> 
> log(prod)-(a*s2)-(b*s)-n*log(1-((0.5*b/sqrt(a))*(exp((b^2)/(4*a)))*((sqrt(pi
> ))*(1-pnorm(-b/(2*sqrt(a)), mean=0, sd=1)))))}
> 

  If you're really just looking for "box constraints" (independent
inequalities on different parameters) then optim(...,method="L-BFGS-B",
lower=c(0,0)) should work fine [or maybe lower=c(0.002,0.002) if
you want to make absolutely sure you don't hit the boundaries]

  If you use stats4::mle or bbmle::mle2 (which are both wrappers
for optim(), so the advice above applies) you will be able to
do a little bit more with the results -- e.g. draw profiles and
get profile confidence intervals

  Ben Bolker



More information about the R-help mailing list