test_binomial_proportions tests whether all given proportions come from the same (specified) binomial distribution. The function also detects proportions that do not come from this distribution.
INPUT
- n - m-element vector, containing number of observations for each proportion;
- k - m-element vector, containing number of successes for each proportion;
- p0 - scalar, probability of successes for the assumed binomial distribution;
- alphaValue - significance level (by default alphaValue = 0.05);
- useExactTest - whether exact or approximate test is used for overall testing. Exact test is more effective but also slower (by default useExactTest = false)
OUTPUT
- nullHypothesis - true if all proportions come from the assumed binomial distribution;
- outlierIndex - indices of proportions that do not come from the assumed distribution;
OUTPUT (NOTE)
The test may indicate that the data as a whole does not come from the given distribution (nullHypothesis = 0), but there are no clear outliers (outlierIndex = []). This is the case when success rates for many proportions have moderate deviation from the assumed success rate.
Example 1. Proportions 7/40, 36/60, 33/50 have low probability to be obtained from a binomial distribution with p=0.5, and 7/40 clearly is an outlier:
p0 = 0.5;
alphaValue = 0.05;
k = [7,36,33];
n = [40,60,50];
[nullHypothesis, outlierIndex] = test_binomial_proportions(n, k, p0, alphaValue, true);
% Outcome nullHypothesis = 0, outlierIndex = 1
Example 2. Among proportions 14/40, 36/60, 33/50 there are no clear outliers, but they also have low probability to be obtained from given distribution:
k = [14,36,33];
n = [40,60,50];
[nullHypothesis, outlierIndex] = test_binomial_proportions(n, k, p0, alphaValue, true);
% Outcome nullHypothesis = 0, outlierIndex = Empty matrix: 1-by-0
CITING THE CODE
[1] Krishnamoorthy, K., Thomson, J. and Cai, Y., 2004. An exact method of testing equality of several binomial proportions to a specified standard. Computational statistics & data analysis, 45(4), pp.697-707.
[2] Unakafov, A.M., 2017. An exact test for equality of several binomial proportions to a specified standard, MATLAB Central File Exchange. Retrieved Month Day, Year.
EXAMPLE OF USE
p0 = 0.5; % assumed probability of successes is p0 = 0.5
alphaValue = 0.05;
m = 10; % we will have 10 observation samples
nRun = 10; % repeat the test 10 times
nullHypothesis = zeros(1,nRun);
outlierIndex = cell(1, nRun);
for i = 1:nRun
n = 20 + randi(80, m, 1); % generate observation samples of random size from 20 to 100
k = binornd(n, p0); % for each sample generate probabilities of successes
[nullHypothesis(i), outlierIndex{i}] = test_binomial_proportions(n, k, p0, alphaValue, true);
end
% Since proportions indeed come from binomial random generator with probability of
% successes p0, in most cases nullHypothesis should be 1 and outlierIndex -- empty
引用格式
Anton (2024). An exact test for equality of several binomial proportions to a specified standard (https://www.mathworks.com/matlabcentral/fileexchange/64987-an-exact-test-for-equality-of-several-binomial-proportions-to-a-specified-standard), MATLAB Central File Exchange. 检索来源 .
MATLAB 版本兼容性
平台兼容性
Windows macOS Linux类别
- AI and Statistics > Statistics and Machine Learning Toolbox > Probability Distributions > Discrete Distributions > Binomial Distribution >
标签
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!