Suppose I have two cookie recipes, Recipe A and Recipe B, and I want to determine which one produces better cookies. To do this, I can use a paired samples t-test since the same group of people will taste both cookies, providing related observations. Here is how I set up the hypothesis test and perform the analysis.
Step 1: State the Hypotheses
The null hypothesis and the alternative hypothesis
can be stated as follows:
where is the mean difference in taste scores between the two recipes.
Step 2: Collect Data
Suppose we have 10 participants who rate the cookies on a scale from 1 to 10. Each participant tastes both Recipe A and Recipe B, and we record their ratings. The data might look like this:

Step 3: Calculate the Test Statistic
First, we calculate the mean and standard deviation of the differences:
Next, we calculate the test statistic:
Step 4: Determine the Degrees of Freedom
The degrees of freedom for the paired samples t-test is :
Step 5: Compare the Test Statistic to the Critical Value
Using a t-table or calculator, find the critical t-value for a two-tailed test with and
. The critical t-value is approximately
.
Since is less than
, we fail to reject the null hypothesis.
Conclusion
At the significance level, we do not have enough evidence to conclude that there is a difference in taste between Recipe A and Recipe B. Therefore, we fail to reject the null hypothesis that there is no difference in taste between the two cookie recipes.
Implementation
python
import numpy as np
from scipy import stats
# Data
recipe_a = [7, 9, 6, 8, 7, 9, 6, 8, 7, 9]
recipe_b = [8, 7, 6, 9, 8, 9, 7, 6, 8, 7]
# Calculate differences
differences = np.array(recipe_a) - np.array(recipe_b)
# Calculate mean and standard deviation of differences
mean_diff = np.mean(differences)
std_diff = np.std(differences, ddof=1)
# Number of pairs
n = len(differences)
# Perform paired t-test
t_statistic, p_value = stats.ttest_rel(recipe_a, recipe_b)
# Print results
print(f"Mean Difference: {mean_diff}")
print(f"Standard Deviation of Differences: {std_diff}")
print(f"t-Statistic: {t_statistic}")
print(f"p-Value: {p_value}")
# Degrees of freedom
df = n - 1
print(f"Degrees of Freedom: {df}")
R
# Data
recipe_a <- c(7, 9, 6, 8, 7, 9, 6, 8, 7, 9)
recipe_b <- c(8, 7, 6, 9, 8, 9, 7, 6, 8, 7)
# Calculate differences
differences <- recipe_a - recipe_b
# Calculate mean and standard deviation of differences
mean_diff <- mean(differences)
std_diff <- sd(differences)
# Perform paired t-test
t_test_result <- t.test(recipe_a, recipe_b, paired = TRUE)
# Print results
cat("Mean Difference:", mean_diff, "\n")
cat("Standard Deviation of Differences:", std_diff, "\n")
cat("t-Statistic:", t_test_result$statistic, "\n")
cat("p-Value:", t_test_result$p.value, "\n")
cat("Degrees of Freedom:", t_test_result$parameter, "\n")
Discover more from Science Comics
Subscribe to get the latest posts sent to your email.