Expected input number 2, edges, to be one of these types
조회 수: 10 (최근 30일)
이전 댓글 표시
Hello all,
Here I am doing a Chi-Square calculation
main
data = randi([0,10],1,20);
% dummy variable
% 10, 0.05, 'unif', 1.5, 2.9
n = 10;
alpha = 0.05;
dist = 'unif';
a1 = 1.5;
a2 = 2.9;
a3 = 3.0;
%Call to the function
[chi2, critical] = chi2test (data, n, alpha, dist, a1, a2);
The function is straigth forward, however the part I am have a issue is the prod, and the invcdf anonymous function. I do not have the tool kit for the cdf, so I did it by sprintf, using the histcounts. Here is where the issue lays, is there a way to get around this error?
function [chi2, critical] = chi2test (data, n, alpha, dist, a1, a2)
prob = @(a,b) sprintf('cdf(''%s'', b, %10.10g, %10.10g) - cdf(''%s'', a, %10.10g, %10.10g)', dist, a1, a2, dist, a1, a2);
invcdf = @(x) sprintf('icdf(''%s'', x, %10.10g, %10.10g)', dist, a1, a2);
pi = (1/n) .* (0:n);
intvls = invcdf(pi);
% The error is thrown here
o_freq = histcounts(data, intvls);
end
I recevie the following error
Error using histcounts
Expected input number 2, edges, to be one of these types:
double, single, uint8, uint16, uint32, uint64, int8, int16, int32, int64, logical
Thank you all for any help
댓글 수: 0
채택된 답변
Steven Lord
2021년 2월 1일
function [chi2, critical] = chi2test (data, n, alpha, dist, a1, a2)
prob = @(a,b) sprintf('cdf(''%s'', b, %10.10g, %10.10g) - cdf(''%s'', a, %10.10g, %10.10g)', dist, a1, a2, dist, a1, a2);
invcdf = @(x) sprintf('icdf(''%s'', x, %10.10g, %10.10g)', dist, a1, a2);
This anonymous function does not call icdf on its inputs. It create a string that contains the icdf call that you would execute to compute the icdf. [The same holds for prob and cdf.] Don't use sprintf.
invcdf = @(x) icdf(dist, x, a1, a2);
If you really need the %10.10g behavior, use round on a1 and a2.
추가 답변 (1개)
dpb
2021년 2월 3일
W/O the Statistics TB, you'll have to resort to some other way to compute the wanted distribution quantities -- a quick look at File Exchange located <generalized-chi-square-distribution> that purports to do what you want. There may be others there.
댓글 수: 2
dpb
2021년 2월 3일
Answers is totally volunteer; there are a number like Steven who are TMW employees who contribute, but I am just a retired geezer... :)
참고 항목
카테고리
Help Center 및 File Exchange에서 Hypothesis Tests에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!