This page was last updated on October 04, 2019.
Load the tigerstats
library:
Set the seed with number 12, and roll a fair, six-sided die 12 times. Consider a success to be rolling a number 2.
Set the seed with number 12, and roll a fair, six-sided die 12 times. Consider a success to be rolling a number 2.
## [1] 5
How many times should you expect to roll a 2?
(12 * 1/6) = 2
In your simulation, how many times did you roll a 2?
5 times.
dbinom
function to calculate the probability of rolling three “2”s when rolling a fair six-sided die 20 times.Use the dbinom
function to calculate the probability of rolling three “2”s when rolling a fair six-sided die 20 times:
## [1] 0.2378866
Produce a graph of a discrete probability distribution for this scenario: p = 1/4, and n = 12.
num.trials <- 12
act.2.probs <- dbinom(x = 0:num.trials, size = num.trials, prob = 1/4)
barplot(act.2.probs,
names.arg = 0:num.trials,
xlab = "Number of successes (X)",
ylab = "Probability",
las = 1)
Figure 4. Probability of obtaining X successes out of 12 random trials, with probability of success = 1/4.
In the Hypothesis testing tutorial, Activity 1 asked you to conduct all the steps of a hypothesis test for Example 6.2 in the text book (concerning handedness in toads) using a simulation approach: you were to simulate data to construct a null distribution, with which a P-value could be calculated.
Using the present tutorial as a guide, repeat this activity, but this time use a binomial test to calculate an exact probability (as shown above) on Example 6.2 in the text book (concerning handedness in toads). Be sure to include all the steps of a hypothesis test.
H0: Left- and right-handed toads are equally frequent in the population; p = 0.5.
HA: Left- and right-handed toads are not equally frequent in the population; p \(\ne\) 0.5.
Use an \(\alpha\) level of 0.05.
Use a two-tailed test.
The test statistic is the number of toads with right-handedness. If the null hypothesis were correct, we should expect to see equally frequent left- and right-handed toads, or 9 of each out of the 18 toads sampled. Instead, 14 right-handed toads were sampled; 14 is the test statistic.
We assume that the toads tested were independent of each other.
We can now use the binomial test to test the null hypothesis. Use binom.test
from the tigerstats
package for this test.
toad.binom.result <- binom.test(x = 14,
n = 18,
p = 0.5,
alternative = "two.sided",
ci.method = 'Agresti-Coull' # Use the Agresti-Coull method
)
toad.binom.result
##
## Exact binomial test (Agresti-Coull CI)
##
## data: 14 out of 18
## number of successes = 14, number of trials = 18, p-value = 0.03088
## alternative hypothesis: true probability of success is not equal to 0.5
## 95 percent confidence interval:
## 0.5425015 0.9153434
## sample estimates:
## probability of success
## 0.7777778
And if you wish to round the C.L. values to 3 decimal places:
toad.low <- round(toad.binom.result$conf.int[1], 3)
toad.high <- round(toad.binom.result$conf.int[2], 3)
c(toad.low, toad.high)
## [1] 0.543 0.915
Concluding statement:
We found a significantly higher proportion of right-handed compared to left-handed toads (n = 18; observed proportion of right-handed toads = 0.78; Binomial test: P-value: 0.031; Agresti-Coull 95% confidence interval: 0.543 \(\le\) P \(\le\) 0.915)