MLE and Anonymous functions - why am I getting undefined arguments?
Show older comments
Apologies, I believe I just put this in the newsreader by mistake.
I'm trying to use maximum likelihood estimation with a logistic probability distribution to estimate the coefficients A, B and C of a model to fit my data.
I have:
P = @(x1, x2, x3, A, B, C) (exp(x1*A + x2*B + x3*C))/(1 + exp(x1*A + x2*B + x3*C));
phat = mle(Rvals, 'pdf', P, 'start', [0, 0, 0]);
My equation will take the form of R = Ax1 + Bx2 + Cx3 so R, x1, x2, and x3 are column vectors with my experimental data.
But I'm getting:
"??? Error using ==> mlecustom>checkFunErrs at 525
The following error occurred while trying to evaluate
the user-supplied pdf function
'@(x1,x2,x3,A,B,C)(exp(x1*A+x2*B+x3*C))/(1+exp(x1*A+x2*B+x3*C))':"
Input argument "B" is undefined.
P is an anonymous function, shouldn't it not care if B is defined? That's the whole point, I'm solving for it. And it's not complaining about A. Have I somehow defined my anonymous function wrong? Thanks in advance for your help.
Answers (1)
Walter Roberson
on 18 Nov 2011
Your pdf parameter must be a function handle to a function that takes a vector and a list of parameters for the distribution. Your 'start' parameter gives starting values for the parameters. You have 3 elements in your start vector, so to match your function handle must take a vector and then three parameters. Instead you are trying to work with 6 inputs, the first 3 of which seem to be known vectors from your workspace, and you are attempting to ignore the vector of data that will be passed in (that corresponds to Rvals)
The closest I can come to what you should do is
P = @(data, A,B,C) (exp(x1*A + x2*B + x3*C))/(1 + exp(x1*A + x2*B + x3*C));
I have not yet been able to determine how the data vector should be used: perhaps it should be subtracted from the result of the division or something like that (thus giving an error term to work with.)
Question: are you sure you should be using the / operator instead of the ./ operator?
Categories
Find more on Uniform Distribution (Continuous) 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!