[R] Trouble with Optimization in "Alabama" Package

Ravi Varadhan rvaradhan at jhmi.edu
Tue Sep 21 17:32:00 CEST 2010


I will take a look and get back to you.

Ravi.

-----Original Message-----
From: r-help-bounces at r-project.org [mailto:r-help-bounces at r-project.org] On
Behalf Of Erik Kimbrough
Sent: Tuesday, September 21, 2010 11:01 AM
To: R-help at r-project.org
Subject: [R] Trouble with Optimization in "Alabama" Package

Hello,

This is my first post to the help request list, so I'm going to err on the
side of giving too much information.

I'm working on writing a simulation in which agents will make repeated
production and exchange decisions with randomly chosen partners.

The idea is, all agents can produce two goods which they want to consume,
they choose a value t in [0,10] which sets their production time allocated
to each good. Then they are matched with another individual with whom they
will trade according to various bargaining algorithms.

I want to write a general purpose optimization that takes their initial
allocations (what they produced) and computes, for example, the solution
which maximizes the product of their utilities from the final allocation,
subject to the constraint that their utilities must be at least as high as
if they didn't trade at all.

Since constrOptim.nl finds the maximizing set of parameters based on the
initial par argument fed to it, I had to include an additional argument to
the functions so I could bring the parameters of the utility functions and
the initial production into the optimization.

I've written the following code but I keep getting strange errors:

library(alabama)

# y is a vector of initial allocations and CobbDouglas preference parameters

#y=c(r1,r2,b1,b2,alpha1,alpha2)

y=c(5,50,60,5,.3,.7)


# p1=c(r1bar,r1bar,b1bar,b1bar) a feasible allocation

p1=c(15,40,50,15)



fn=function(x,...){

return(-1*(((x[1]^y[5])*(x[3]^(1-y[5])))*(((x[2]^y[6])*(x[4]^(1-y[6]))))))

}


hin=function(x,...){

h=rep(NA,2)

h[1]=((x[1]^y[5])*(x[3]^(1-y[5])))-((y[1]^y[5])*(y[3]^(1-y[5])))

h[2]=((x[2]^y[6])*(x[4]^(1-y[6])))-((y[2]^y[6])*(y[4]^(1-y[6])))

return(h)

}

 heq=function(x,...){

h=rep(NA,2)

h[1]=x[1]+x[2]-y[1]-y[2]

h[2]=x[3]+x[4]-y[3]-y[4]

return(h)

}


 ans2=constrOptim.nl(par=p1,fn=fn,hin=hin,heq=heq,control.outer=list(itmax=
1000,mu0=.00001),list(y,y,y))


Any advice or explanation of my errors would be greatly appreciated!

-- 
Erik O. Kimbrough
Department of Economics (AE1)
School of Business and Economics
Maastricht University

	[[alternative HTML version deleted]]

______________________________________________
R-help at r-project.org 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.



More information about the R-help mailing list