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)))))} I''ve tried maxlik constrOptim e donlp2 but without success. Thanks so much!!! [[alternative HTML version deleted]]
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
Hi Daniela, Will the "optim" function with the method "L-BFGS-B" work for you? Look for the "lower" argument in the function. Ritwik On Fri, Jul 25, 2008 at 9:07 AM, Daniela Garavaglia <danygaravaglia84 at virgilio.it> wrote:> > 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)))))} > > > > I've tried maxlik constrOptim e donlp2 but without success. > > > > Thanks so much!!! > > > > > > > [[alternative HTML version deleted]] > > ______________________________________________ > R-help at r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code.-- Ritwik Sinha ritwik.sinha at gmail.com | +12033042111 | http://ritwik.sinha.googlepages.com/
I''m an Italian student looking for help. How can I maximize this function? neg_loglik<-function(param){ a<-param[1] b <-param[2] -(log(pr)-(a*s2)-(b*s)+n*log(2*a)-n*log(1-(b/sqrt(a))*exp((b^2)/(4*a))*(sqrt (pi))*(1-pnorm(b/(2*sqrt(a)), mean=0, sd=1))*1)) } Con> pr[1] 4.37124e+113> s2[1] 270486> s[1] 3646> n[1] 71>Is a -(loglikelihood function), the parameter a e b are positive. I''ve used the function max<-constrOptim(c(1,1),neg_loglik, grad=NULL, ui=rbind(c(1,0),c(0,1)), ci=c(0,0)) but without success cause I think the max is only local. Great wishes Daniela [[alternative HTML version deleted]]