paired samples t-test: Better Cookie Recipe

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 H_0 and the alternative hypothesis H_A can be stated as follows:
H_0: \mu_D = 0 \quad \text{(no difference in taste between Recipe A and Recipe B)}
H_A: \mu_D \neq 0 \quad \text{(there is a difference in taste between Recipe A and Recipe B)}
where \mu_D 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:
\bar{D} = \frac{\sum_{i=1}^n D_i}{n} = \frac{-1 + 2 + 0 - 1 - 1 + 0 - 1 + 2 - 1 + 2}{10} = 0.1
s_D = \sqrt{\frac{\sum_{i=1}^n (D_i - \bar{D})^2}{n-1}} = \sqrt{\frac{(-1-0.1)^2 + (2-0.1)^2 + (0-0.1)^2 + (-1-0.1)^2 + (-1-0.1)^2 + (0-0.1)^2 + (-1-0.1)^2 + (2-0.1)^2 + (-1-0.1)^2 + (2-0.1)^2}{9}} \approx 1.197

Next, we calculate the test statistic:
t = \frac{\bar{D}}{s_D / \sqrt{n}} = \frac{0.1}{1.197 / \sqrt{10}} \approx 0.264

Step 4: Determine the Degrees of Freedom

The degrees of freedom for the paired samples t-test is n - 1:
df = 10 - 1 = 9

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 \alpha = 0.05 and df = 9. The critical t-value is approximately \pm 2.262.

Since t = 0.264 is less than 2.262, we fail to reject the null hypothesis.

Conclusion

At the \alpha = 0.05 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.

Leave a Reply

error: Content is protected !!