Tags: additional, customised, distributions, function, likelihood, matlab, minimise, mle, mlecustom, negative, parameters, parametersof, programming, touse

using mle with additional parameters in likelihood function

On Programmer » Matlab

3,240 words with 3 Comments; publish: Tue, 29 Apr 2008 15:11:00 GMT; (200109.38, « »)

Hi,

I want to use mle (mlecustom) to find the parameters

of my customised distributions. While I am able to

use minimise the negative likelihood using fminsearch,

I want to use directy mle.

My nll function used in fminsearch is defined as

function nll = negloglik(params, x, additionalparameter)

I know that I have to add freq and cens to my function.

But how to pass the additionalparameter argument to mle?

Thanks,

F.

All Comments

Leave a comment...

  • 3 Comments
    • Farid wrote:

      > Hi,

      > I want to use mle (mlecustom) to find the parameters

      > of my customised distributions. While I am able to

      > use minimise the negative likelihood using fminsearch,

      > I want to use directy mle.

      > My nll function used in fminsearch is defined as

      > function nll = negloglik(params, x, additionalparameter)

      > I know that I have to add freq and cens to my function.

      > But how to pass the additionalparameter argument to mle?

      Assuming those addition parameters are constant, use a nested or an anonymou

      s

      function. This demo:

      <<http://www.mathworks.com/products/s...mdist1demo.html>>

      describes both.

      Hope this helps.

      - Peter Perkins

      The MathWorks, Inc.

      #1; Tue, 29 Apr 2008 15:13:00 GMT
    • Dear Peter,

      I did what was said there. So here my piece of code

      % That part is ok.

      try

      [params, fval, err] = fminsearch(.matlab.todaysummary.com.negloglik, params0, optimset,

      x, thresh);

      catch

      disp(lasterr)

      end

      where thres is the truncation point.

      % Not ok

      NLLfunction = .matlab.todaysummary.com.(x, params) negloglik(params, x, thres);

      [paramEsts,paramCIs] = mle(x, 'nloglf', NLLfunction, ...

      'start', params0, 'lower',[-Inf,0],

      'options', optimset)

      function nll = negloglik(params, x, thresh)

      mu = params(1);

      sigma = params(2);

      n = length(x);

      nll=-(sum(log(lognpdf(x, mu, sigma))) - n*log((1 -

      logncdf(threshold, mu, sigma))));

      end

      I get the following message:

      ? Error using ==> stats\private\mlecustom>checkFunErrs

      The following error occurred while trying to evaluate

      the user-supplied nloglf function '.matlab.todaysummary.com.(x, params) negloglik(params, x,

      threshold)':

      Error using ==> bis_lognmle>.matlab.todaysummary.com.(x, params) negloglik(params, x,

      threshold)

      Too many input arguments.

      Error in ==> stats\private\mlecustom at 143

      checkFunErrs('nloglf',nloglfFun,start,da

      ta,cens,freq,nloglfAddArgs,hav

      eGrad);

      Error in ==> mle at 219

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

      Error in ==> bis_lognmle at 26

      [paramEsts,paramCIs] = mle(x, 'nloglf', NLLfunction, ...

      #2; Tue, 29 Apr 2008 15:14:00 GMT
    • There is no error in the function negloglik.

      Just for posting the request, I remplaced threshold

      by thres.

      function nll = negloglik(params, x, threshold)

      mu = params(1);

      sigma = params(2);

      n = length(x);

      nll=-(sum(log(lognpdf(x, mu, sigma))) - n*log((1 -

      logncdf(threshold, mu, sigma))));

      end

      #3; Tue, 29 Apr 2008 15:15:00 GMT