A Two-Class Table of Counts
You count 47 animals and find that 29 of them are males and 18 are females. Are these data sufficiently male-biased to reject the null hypothesis of an even sex ratio? With an even sex ratio the expected number of males and females is 47/2 = 23.5. The simplest test is Pearson's chi-squared in which we calculate
Substituting our observed and expected values, we get
This is less than the critical value for chi-squared with 1 degree of freedom (3.841), so we conclude that the sex ratio is not significantly different from 50:50. There is a built-in function for this
observed<-c(29,18) chisq.test(observed) Chi-squared test for given probabilities data: observed x-squared = 2.5745, df = 1, p-value = 0.1086
which indicates that a sex ratio of this size or more extreme than this would arise by chance alone about 10% of the time (p = 0.1086). Alternatively, you could carry out a binomial test:
binom.test(observed)
Exact binomial test data: observed number of successes = 29, number of trials = 47, p-value = 0.1439 alternative hypothesis: true probability of success is not equal to 0.5 95 percent confidence interval: 0.4637994 0.7549318 sample estimates: probability of success 0.6170213
You can see that the 95% confidence interval for the proportion of males ...
Get The R Book now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.