# Fitting a Gamma distribution with threshold parameter: error message?

5 ビュー (過去 30 日間)
Paul 2011 年 7 月 29 日

Hey,
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 !

サインインしてコメントする。

### 採用された回答

Nirmal Gunaseelan 2011 年 7 月 29 日
The error points to the MINUS operator. It appears that the variables x and n (and hence pEmp?) have the same dimensions and params(1) is different from this. What are the dimensions of these variables?
##### 3 件のコメント表示非表示 2 件の古いコメント
Paul 2011 年 7 月 29 日
very simple:
real_data was not properly vectorized !
Thanks a lot.

サインインしてコメントする。

### その他の回答 (1 件)

haneen jawa 2019 年 3 月 31 日
(R .* (C.^3)/2) .*(3/K) .*gamma(3/k); WHAT IS THE WRONG

サインインしてコメントする。

### Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!