Question

I have done it in Excel but need to run a proper simulation in R.

I need to minimize function F(x) (x is a vector) while having constraints that sum(x)=1, all values in x are [0,1] and another function G(x) > G_0.

I have tried it with optim and constrOptim. None of them give you this option.

Was it helpful?

Solution

The problem you are referring to is (presumably) a non-linear optimization with non-linear constraints. This is one of the most general optimization problems.

The package I have used for these purposes is called nloptr: see here. From my experience, it is both versatile and fast. You can specify both equality and inequality constaints by setting eval_g_eq and eval_g_ineq, correspondingly. If the jacobians are known explicitly (can be derived analytically), specify them for faster convergence; otherwise, a numerical approximation is used.

Use this list as a general reference to optimization problems.

OTHER TIPS

Write the set of equations using the Lagrange multiplier, then solve using the R command nlm.

You can do this in the OpenMx Package (currently host at the site listed below. Aiming for 2.0 relase on cran this year)

It is a general purpose package mostly used for Structural Equation Modelling, but handling nonlinear constraints.

FOr your case, make an mxModel() with your algebras expressed in mxAlgebras() and the constraints in mxConstraints()

When you mxRun() the model, the algebras will be solved within the constraints, if possible.

http://openmx.psyc.virginia.edu/

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top