[R] constrOptim

Joanne Lee lee.jiyun at gmail.com
Wed Aug 1 20:31:19 CEST 2007


Hi,

I'm having trouble using the constrOptim function to generate the
9-component vector argmin of the function ELfsds:

ELfsds <- function(pvechat){
	LG=0
	for(i in 1:9){
		LG=LG+log(pvechat[i])
	}
	return(-LG)	
}

with accompanying gradient function:

gradfunc <- function(thetavec){
	g=1/(9*thetavec)
	return(g)
}

The constraints on the optimization problem are:
1 - components of potentialargmin must add to 1.
2 - each potentialargmin component must be (weakly) positive and
(weakly) less than 1.
3 - potentialargmin %*% c(1,2,3,4,5,6,7,8,9) = 4.5

I'm starting the optimization routine at:
thetatest = c(0.02, 0.2755, 0.139, 0.0955, 0.1025, 0.125, 0.13, 0.055,
0.0575), which satisfies all constraints and was found through
trial-and-error guessing.

The constrOptim line I've been using is:

pvec <- constrOptim( thetatest, ELfsds, gradfunc,
ui = rbind( -diag(9), dvec, -dvec, rep(-1,9), rep(1,9) ),
ci = cbind( c(rep(-1,9), fsdmean-0.005, -fsdmean-0.005, -1.005, 0.995) ) )
(constraints in constrOptim are phrased such that (ui %*% thetatest - ci >= 0))

constrOptim says that the argmin of the function is exactly thetatest.
I'm confident that I didn't select the argmin with thetatest. I would
really appreciate any input you have on this code -- I've been staring
at it for a while and feel like I'm just banging my head into the wall
now. Thank you very much for your time and help!!!

Best regards,
Joanne



More information about the R-help mailing list