I have to estimate the following model for several group of observations : y(1-y) = p[1]*(x^2-y) + p[2]*y*(x-1) + p[3]*(x-y) with constraints : p[1]+p[3] >= 1 p[1]+p[2]+p[3]+1 >= 0 p[3] >= 0 I use the following code : func <- sum((y(1-y) - p[1]*(x^2-y) + p[2]*y*(x-1) + p[3]*(x-y))^2) estim <- optim( c(1,0,0),func, method="L-BFGS-B" , lower=c(1-p[3], -p[1]-p[3]-1, 0) ) and for some group of observations, I observe that the estimated parameters don't respect the constraints, espacially the first. Where's the problem please ?
Florent Bresson <f_bresson at yahoo.fr> writes:> I have to estimate the following model for several > group of observations : > > y(1-y) = p[1]*(x^2-y) + p[2]*y*(x-1) + p[3]*(x-y) > > with constraints : > p[1]+p[3] >= 1 > p[1]+p[2]+p[3]+1 >= 0 > p[3] >= 0 > > I use the following code : > func <- sum((y(1-y) - p[1]*(x^2-y) + p[2]*y*(x-1) + > p[3]*(x-y))^2) > estim <- optim( c(1,0,0),func, method="L-BFGS-B" , > lower=c(1-p[3], -p[1]-p[3]-1, 0) ) > > and for some group of observations, I observe that the > estimated parameters don't respect the constraints, > espacially the first. Where's the problem please ?If you think the boundaries in lower=c(....) are recomputed as the iteration progresses, you're wrong. L-BGFS-B does box constraints only. Instead parametrize using q1=p1+p3 q2=p1+p2+p3 q3=p3 which is easily inverted to get the p's from the q's. Then optimize as a function of q1..q3, substituting the inversion in the expression for func (which btw needs to be a _function_), using the relevant box constraints. -- O__ ---- Peter Dalgaard ??ster Farimagsgade 5, Entr.B c/ /'_ --- Dept. of Biostatistics PO Box 2099, 1014 Cph. K (*) \(*) -- University of Copenhagen Denmark Ph: (+45) 35327918 ~~~~~~~~~~ - (p.dalgaard at biostat.ku.dk) FAX: (+45) 35327907
On Mon, 28 Nov 2005, Florent Bresson wrote:> I have to estimate the following model for several > group of observations : > > y(1-y) = p[1]*(x^2-y) + p[2]*y*(x-1) + p[3]*(x-y) > > with constraints : > p[1]+p[3] >= 1 > p[1]+p[2]+p[3]+1 >= 0 > p[3] >= 0 > > I use the following code : > func <- sum((y(1-y) - p[1]*(x^2-y) + p[2]*y*(x-1) + > p[3]*(x-y))^2) > estim <- optim( c(1,0,0),func, method="L-BFGS-B" , > lower=c(1-p[3], -p[1]-p[3]-1, 0) ) > > and for some group of observations, I observe that the > estimated parameters don't respect the constraints, > espacially the first. Where's the problem please ?User mis-reading the help page! L-BFGS-B handles `box constraints', not linear inequality constraints. You can reparametrize to make these box constraints: use p[3], p[1]+p[3] and p[1]+p[2]+p[3] are variables. -- Brian D. Ripley, ripley at stats.ox.ac.uk Professor of Applied Statistics, http://www.stats.ox.ac.uk/~ripley/ University of Oxford, Tel: +44 1865 272861 (self) 1 South Parks Road, +44 1865 272866 (PA) Oxford OX1 3TG, UK Fax: +44 1865 272595
If I understand this correctly the variables over which you are optimizing are p[1], p[2] and p[3] whereas x and y are fixed and known during the optimization. In that case its a linear programming problem and you could use the lpSolve library which would allow the explicit specification of the constraints. On 11/28/05, Florent Bresson <f_bresson at yahoo.fr> wrote:> I have to estimate the following model for several > group of observations : > > y(1-y) = p[1]*(x^2-y) + p[2]*y*(x-1) + p[3]*(x-y) > > with constraints : > p[1]+p[3] >= 1 > p[1]+p[2]+p[3]+1 >= 0 > p[3] >= 0 > > I use the following code : > func <- sum((y(1-y) - p[1]*(x^2-y) + p[2]*y*(x-1) + > p[3]*(x-y))^2) > estim <- optim( c(1,0,0),func, method="L-BFGS-B" , > lower=c(1-p[3], -p[1]-p[3]-1, 0) ) > > and for some group of observations, I observe that the > estimated parameters don't respect the constraints, > espacially the first. Where's the problem please ? > > ______________________________________________ > R-help at stat.math.ethz.ch mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html >