I would like to use MATLAB's chi2gof
to perform a chi-square goodness-of-fit test. My problem is that my assumed (i.e., theoretical) distribution is not one of the standard built-in probability distributions in MATLAB. The specific form of my desired distribution is:
p = x^a*exp(-b*x^2)
where a
and b
are constants. There must be a way to use chi2gof
for arbitrary PDFs? I have done an exhaustive Google search, but have come up empty-handed.
You can specify a handle to a function that takes a single argument to chi2gof
this way:
a = ...
b = ...
c = ...
F = @(x)a*exp(-b*x-c*x.^2); % Technically this is an anonymous function
[H,P,STATS] = chi2gof(data,'cdf',F)
Or in special cases:
a = ...
b = ...
c = ...
F = @(x,a,b,c)a*exp(-b*x-c*x.^2);
[H,P,STATS] = chi2gof(data,'cdf',{F,a,b,c})
the last line of which is equivalent to
[H,P,STATS] = chi2gof(data,'cdf',@(x)F(x,a,b,c))
If the parameters a
, b
, and c
are estimated (e.g., using some fitting process), then you should specify the number of estimated parameters to chi2gof
. In this case:
[H,P, STATS] = chi2gof(data,'cdf',F,'nparams',3)
Please read the documentation to learn about the other options.