You wrote MAXIMIZE this function, why not using the maximize option of
constrOptim?
If you read the help file, you will find that if you set the control fnscale
to a negative value, maximisation
is performed.
constrOptim(c(1,1),neg_loglik, grad=NULL, ui=rbind(c(1,0),c(0,1)),
ci=c(0,0),control=list(fnscale=-1))
Best regards
Bart
babydany84 wrote:
>
> 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]]
>
> ______________________________________________
> [email protected] 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.
>
>
--
View this message in context:
http://www.nabble.com/maximization-under-constraits-tp18870935p18890806.html
Sent from the R help mailing list archive at Nabble.com.
______________________________________________
[email protected] 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.