Test for probability p of a binomial sample
Perform a test of the null hypothesis p == p0 for a sample of size N with pos positive results
Name-Value pair arguments can be used to set various options.
"alpha"
can be used to specify the significance level
of the test (the default value is 0.05). The option "tail"
,
can be used to select the desired alternative hypotheses. If the
value is "both"
(default) the null is tested against the two-sided
alternative p != p0
. The value of pval is
determined by adding the probabilities of all event less or equally
likely than the observed number pos of positive events.
If the value of "tail"
is "right"
the one-sided alternative p > p0
is considered.
Similarly for "left"
, the one-sided alternative
p < p0
is considered.
If h is 0 the null hypothesis is accepted, if it is 1 the null hypothesis is rejected. The p-value of the test is returned in pval. A 100(1-alpha)% confidence interval is returned in ci.
The following code
% flip a coin 1000 times, showing 475 heads % Hypothesis: coin is fair, i.e. p=1/2 [h,p_val,ci] = binotest(475,1000,0.5) % Result: h = 0 : null hypothesis not rejected, coin could be fair % P value 0.12, i.e. hypothesis not rejected for alpha up to 12% % 0.444 <= p <= 0.506 with 95% confidence
Produces the following output
h = 0 p_val = 0.1212 ci = 0.4437 0.5065
The following code
% flip a coin 100 times, showing 65 heads % Hypothesis: coin shows less than 50% heads, i.e. p<=1/2 [h,p_val,ci] = binotest(65,100,0.5,'tail','left','alpha',0.01) % Result: h = 1 : null hypothesis is rejected, i.e. coin shows more heads than tails % P value 0.0018, i.e. hypothesis not rejected for alpha up to 0.18% % 0 <= p <= 0.76 with 99% confidence
Produces the following output
h = 1 p_val = 1.7588e-03 ci = 0 0.7580
Package: statistics