The Math Forum

Search All of the Math Forum:

Views expressed in these public forums are not endorsed by NCTM or The Math Forum.

Math Forum » Discussions » Software » comp.soft-sys.matlab

Notice: We are no longer accepting new posts, but the forums will continue to be readable.

Topic: Fitting a Gamma Distribution with threshold parameter : ??? Error using ==> minus
Replies: 1   Last Post: Jul 29, 2011 9:23 AM

Advanced Search

Back to Topic List Back to Topic List Jump to Tree View Jump to Tree View   Messages: [ Previous | Next ]

Posts: 8
Registered: 2/14/10
Fitting a Gamma Distribution with threshold parameter : ??? Error using ==> minus
Posted: Jul 28, 2011 5:53 PM
  Click to see the message monospaced in plain text Plain Text   Click to reply to this topic Reply


I've got a problem that I can't figure out for the life of me. I'm trying to fit a Gamma distribution to some raw data which includes a lower threshold parameter, and i'm getting the following error message. Could somebody help here please?

CODE %%%%%%%%%%%%%%%%%

c = min(data)/4
k = mean(data)^2
theta = var(data)/mean(data)^2

x = sort(data);
n = length(x);
pEmp = ((1:n)-0.5)' ./ n;
wgt = 1 ./ sqrt(pEmp.*(1-pEmp));
gammaObj = @(params) sum(wgt.*(gamcdf((x-params(1)),exp(params(2)),exp(params(3))) - pEmp).^2)
paramHat = fminsearch(gammaObj,[c,log(k),log(theta)])
paramHat1 = paramHat(1);
paramHat2 = exp(paramHat(2));
paramHat3 = exp(paramHat(3));

ERROR %%%%%%%%%%%%%%%%%

??? Error using ==> minus
Matrix dimensions must agree.

Error in ==> @(params)sum(wgt.*(gamcdf((x-params(1)),exp(params(2)),exp(params(3)))-pEmp).^2)

Error in ==> fminsearch at 205
fv(:,1) = funfcn(x,varargin{:});

Error in ==> gammaFit at 582
paramHat = fminsearch(gammaObj,[c,log(k),log(theta)])

Thanks a bundle !

Point your RSS reader here for a feed of the latest messages in this topic.

[Privacy Policy] [Terms of Use]

© The Math Forum at NCTM 1994-2018. All Rights Reserved.