Using fminsearch to estimate utility function with MLE
Show older comments
Hello.
I have a slight issue which I hope you guys can help me with. I want to estimate the alpha (a) of a simple utility function of the form
EU(P,V) = P*V^a
where P is probability of outcome, and V is magnitude of outcome. The response variable (riskChoice) is 1 for risky choice, and 0 for non-risky choice. I want to use maximum likelihood with a logit link-function to estimate the binary choice model
1/1(e^(w*(EUrisk^a-EUcertain^a))
where EUrisk(cert) is the expected value of the risky(certain) option at each timepoint t, and w is some weight. From the above, I am interested in estimating w and a, using MLE.
I have the following in MATLAB
F = @(a,w) (1/(1 + exp(w*(euCert.^a - euRisk.^a))))';
logF1 = @(a,w) log(1/(1 + (exp(w*(euCert.^a - euRisk.^a)))))';
logF2 = @(a,w) log(1-F(a,w));
And the (negative, since I want a max.) log-likelihood looks like
NLL = @(a,w) -(sum(riskChoice.*logF1(a,w)+(1-riskChoice).*logF2(a,w)));
Problem No. 1:
When evaluating NLL in a certain (theoretically realistic) point, such as NLL(0.2,2) i get a NaN response. Actually, I get NaN responses for almost all values I put in there. I'm thinking that I have made some mistake in writing up the model? I can't seem to figure out the mistake!
Problem No. 2:
When I use the code below, I get the following error:
initParam = zeros(100,numel(euRisk));
paramFrom = -10:0.1:10;
allOptWs=zeros(100,2);
modelEvi=zeros(100,1);
for r = 1:100
a=rand*10;
w=rand*20;
initWs = [a w];
optWs = fminsearch(NLL,initWs);
allOptWs(r,:) = optWs;
modelEvi(r) = NLL(optWs);
end
Error using @(a,w)-(sum(riskChoice.*logF1(a,w)+(1-riskChoice).*logF3(a,w)))
Not enough input arguments.
Error in fminsearch (line 191)
fv(:,1) = funfcn(x,varargin{:});
I think this might have something to do with fminsearch only accepting one array? If this suspicion is correct, how exactly do I go about making sure that both a and w are in one array?
Thanks in advance!
Accepted Answer
More Answers (2)
1 Comment
Use element-wise division. In fact, use element-wise everything,
>> F=vectorize(F)
F =
@(p)(1./(1+exp(p(2).*(euCert.^p(1)-euRisk.^p(1)))))
Tobias
on 25 Sep 2014
Categories
Find more on Log Plots 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!