1

I have a problem trying to maximize a log likelihood function in R.

My function has 5 parameters out of which I would like to constrain 3 to be positive while leave the other 2 (which should be very small, close to 0, but either positive or negative) as unconstrained.

How can I do this in R? So far, I have simply ran the constrained maximization in R asking the first 3 parameters to be bigger than 0 and asking for the other 2 to be bigger than a very small negative number (e.g., -300). The code in R looks like this:

optcinstMO<-constrOptim(c(1,1,1,1,1),f=neg.loglik2dLO, data1=x, data2=z, data3=y, method="Nelder-MEad",ui=rbind(c(1,0,0,0,0),c(0,1,0,0,0),c(0,0,1,0,0),c(0,0,0,1,0‌​),c(0,0,0,0,1))ci=c(0,0,0,-300,-300))

where neg.loglik2dLO is the negative log-likelihood function I'm minimizing. Is there any other way of doing this "mixed" maximization problem in R?

Also, can anyone tell me what kind of error (if any) am I introducing to my maximization by using my "home-made" approach?

g_puffo
  • 613
  • 3
  • 11
  • 21
  • That depends on the algorithm you use (you should provide some code). If it allows box constraints, you can often specify them as `[0,Inf]` or `[-Inf,Inf]`. If it does not, you can replace the variables that should be positive with a quantity guaranteed to be positive (e.g., replace `x` with `y^2` or `log(1+exp(y))`). – Vincent Zoonekynd Sep 17 '13 at 17:33
  • Thank you Vincent for your reply. I have updated my question with the R code, like you suggested. – g_puffo Sep 17 '13 at 18:22

0 Answers0