Using Optimization Toolbox to Estimate Population Parameters

1 view (last 30 days)
I'm working on an economics research paper on labor supply. I'd like to uncover the population parameters for 'alpha' - the disutility of work. To avoid getting into the background, this problem can be simplified down to the following equation:
Y* = max(utility(w,Y,X,k))
= max(w*Y - X*Y^(1-k)/(1-k))
where w and k are constants, Y is a vector of possible values for labor, Y* is the value of labor that maximizes utility, and X is alpha, a variable that is log-normally distributed for the population.
I have real data for Y*, Y, w, and k from which I'd eventually like to derive the true parameters of alpha, but first I'd like to feed MATLAB fake data to ensure that the optimization routine is working.
I wrote the following function to find the square difference between the Y* generated from guessed X paramenters and the true Y*.
if true
% code
function[difference] = min_dif(x,k,fake_labor_data,numsims)
%%SETUP
% Separate out individual paramaters:
mu = x(1);
sigma = x(2);
%
%%DRAW ALPHAS FOR SAMPLE
alpha_draws = lognrnd(mu,sigma,[numsims,1]);
alpha_draws = repmat(alpha_draws,1,31);
%
%%UTILITY
% Replicate task matrix for all simulations
L = 0:1:30;
L = repmat(L,numsims,1);
% Calculate each person's utility for each of the possible tasks:
utility = 7 * L - alpha_draws .* L .^ (1+k) / (1+k);
% Find the task with the maximum utility for each person:
[~,index] = max(utility,[],2);
labor_supplied = index - 1;
%
%%DISTRIBUTION OF LABOR
[a,~] = hist(labor_supplied,unique(labor_supplied));
dist_labor = a' ./ numsims ;
%
%%SQUARED DIFFERENCE
cdf_sim = cumsum(dist_labor)';
cdf_act = cumsum(fake_labor_data,2);
% Calculate Difference
diff = sum(((cdf_sim - cdf_act).^2),2);
difference = diff;
end
end
I then use fmincon to minimize the difference and return the estimated X parameters:
if true
% code
tic
[param_estimates,func,exitflag] = fmincon( @(x) ...
min_dif(x,k,fake_labor_data,numsims),options);
toc
end
But it's not working. The solver barely moves at all, and has never returned the correct parameters. What can I do?

Accepted Answer

Alan Weiss
Alan Weiss on 23 Oct 2015
I don't really understand your code, but I see some things that make me suspect that you aren't getting what you think you are getting.
Optimization Toolbox solvers assume that the objective function is deterministic. Yet you draw pseudorandom numbers in your objective function with the lognrnd call, and you don't reset the seed after every run. So you can expect that your objective function is random, not deterministic, and so the solver can easily fail.
There are several things that you can do about this. One is, as I implied, reset your seed so the objective function is deterministic. Even better, you can create the pseudorandom numbers outside the objective function as a deterministic set, and simply pass them in, as you passed other data.
For more information, see Optimizing a Simulation or ODE, especially the section Problems in Stochastic Functions.
It is also possible that you should be using a different solver, such as lsqnonlin, which is the solver of choice for nonlinear least squares. But I might misunderstand your problem, so take this suggestion with a grain of salt. If I am correct, you shouldn't sum the squares of differences, you should just pass the vector of differences to lsqnonlin.
Good luck,
Alan Weiss
MATLAB mathematical toolbox documentation

More Answers (0)

Categories

Find more on Problem-Based Optimization Setup in Help Center and File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!