﻿Matlab: statistics toolbox: mle - matlab.todaysummary.com

# statistics toolbox: mle

3,580 words with 2 Comments; publish: Wed, 07 May 2008 09:26:00 GMT; (20062.50, « »)

Hello group

I am trying to do maximum likelihood... but it does not work

I have a customized function for a triangular distribution and I am

trying to fit this data:

phi = [22 23.2 23.4 24 24 24 24.1 24.3 24.4 24.9 25 25.3 25.5 25.6 26

26.5 27 28.5 29.5 30];

mle(phi,'pdf',.matlab.todaysummary.com.(x,a,m,b)trianglepdf(x,a,

m,b),'start',[23,25,29])

AND THE FUNCTION:

function y = trianglepdf(x, a,m,b)

if max(abs(m-a),abs(b-m)) < 100*eps

error('a = m oder b = m nicht zugelassen')

end

y = zeros(size(x));

for i = 1:length(x)

if x(i) > a & x(i) < m

y(i) = 2*(x(i)-a)/((b-a)*(m-a));

end

if x(i) >= m & x(i) < b

y(i) = 2*(b-x(i))/((b-a)*(b-m));

end

end

return;

I get the error:

? Error using ==> stats/private/mlecustom>llf_pdfcdf

The PDF function returned negative or zero values.

Error in ==> fminsearch at 176

fv(:,1) = funfcn(x,varargin{:});

Error in ==> stats/private/mlecustom at 176

[phat,nll,err,output] = ...

Error in ==> mle at 217

phat = mlecustom(data,varargin{:});

OF COURSE A PDF CAN RETURN ZERO since f(x)>= 0 for all X. and \int

f(x)=1

Thanks for your help

Diego

• ? Error using ==> stats/private/mlecustom>llf_pdfcdf

The PDF function returned negative or zero values.

You could get negative value!!! You need to make sure a < b !

#1; Wed, 07 May 2008 09:27:00 GMT

> OF COURSE A PDF CAN RETURN ZERO since f(x)>= 0 for all X. and \int

> f(x)=1

WELL SURE, but that's going to lead to a negative log-likelihood of Inf, whi

ch

is likely to make the optimizer unhappy, or at least a little disoriented,

depending on which one you're using. Especially if your starting values for

the

parameters lead to an Inf objective at the initial function evaluation, whic

h

yours do. FMINSEARCH, the optimizer that MLE calls by default, can cope wit

h

infinite objective values under some circumstances, sometimes, and will even

take a shot at stepping away from a bad start, but ...

You can turn off that error check using the 'FunValCheck' parameter to MLE,

and

let the chips fall where they may, and you will find in your example that th

at

doesn't help, because of the infinite objective at the starting point. So y

ou

will want to find a starting point with a finite log-likelihood (e.g.

[min(phi)-1 median(phi) max(phi)+1], and perhaps set an upper bound on 'a' (

e.g.

min(phi)) and a lower one on 'b'.

You may also run into problems because, as I read it, you ought to have some

order constraints on your parameters to ensure that a < m < b. MLE does not

support that kind of constraint directly, but you can reparameterize to a,

(m-a), and (b-a), and set lower bounds of zero on the latter two.

Unfortunately, that sort of conflicts with constraints to ensure a finite NL

L,

but it turns out that FMINSEARCH is pretty good at not wandering into region

s

with infinite object, so you may be ok there.

> mle(phi,'pdf',.matlab.todaysummary.com.(x,a,m,b)trianglepdf(x,a,

m,b),'start',[23,25,29])

For what it's worth, you don't need the anonymous function there, .matlab.todaysummary.com.trianglep

df

by itself will work fine.

Hope this helps.

- Peter Perkins

The MathWorks, Inc.

#2; Wed, 07 May 2008 09:28:00 GMT