Categories &

Functions List

Function Reference: binotest

statistics: [h, pval, ci, stats] = binotest (pos, N, p0)

statistics: [h, pval, ci, stats] = binotest (pos, N, p0, Name, Value)

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 events less or equally likely than the observed number pos of positive events, equally likely to within a relative 1e-7, as R’s binom.test compares them. 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)% Clopper-Pearson confidence interval for p is returned in ci, one-sided for a one-sided test. stats is a structure with the following fields:

phatthe estimated probability, pos / N.
CohensHCohen’s h, the difference between the arcsine transforms 2 asin (sqrt (phat)) - 2 asin (sqrt (p0)).
CohensHCIits confidence interval, ci under the same transform, which is monotone and so keeps its coverage.

Source Code: binotest

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)
h = 0
p_val = 0.1212
ci =

   0.4437   0.5065

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

flip a coin 100 times, showing 65 heads Alternative: coin shows more heads than tails, i.e. p>1/2

 [h,p_val,ci] = binotest (65,100,0.5,'tail','right','alpha',0.01)
h = 1
p_val = 1.7588e-03
ci =

   0.5298   1.0000

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.53 <= p <= 1 with 99% confidence