Blow Your Nose Horn (One Sample Variance Test)

Imagine you work at an electric car manufacturing company. The horn is an important tool. If it is too loud, people may get annoyed. If the horn sounds too small, people may think that someone is blowing his/her nose instead of thinking that is a car horn sound. So, you want to ensure that the variance of the sound levels of car horns produced should not exceed \sigma_0^2 decibels.

Suppose we want to test if the variance of the weight of horns produced by a machine is equal to a specified value. We will use a one-sample variance test to determine if there is a significant difference.

Step 1: State the Hypotheses

The null hypothesis H_0 and the alternative hypothesis H_A can be stated as follows:
H_0: \sigma^2 = \sigma_0^2 \quad \text{(the variance of the weight is equal to the specified value)}
H_A: \sigma^2 \neq \sigma_0^2 \quad \text{(the variance of the weight is not equal to the specified value)}
where \sigma^2 is the true variance of the weight and \sigma_0^2 is the specified variance.

Step 2: Collect Data

Suppose we randomly sample 20 nose horns produced by the machine and measure their weights (in grams). We find the following weights:

x = [12.3, 11.7, 12.5, 12.1, 12.4, 11.8, 12.2, 12.3, 11.9, 12.0, 12.2, 12.3, 12.1, 11.8, 12.4, 12.2, 12.3, 11.9, 12.1, 12.2]

Step 3: Calculate the Test Statistic

First, we calculate the sample variance s^2:
s^2 = \frac{1}{n-1} \sum_{i=1}^n (x_i - \bar{x})^2
where \bar{x} is the sample mean.

Next, we calculate the test statistic \chi^2:
\chi^2 = \frac{(n-1) s^2}{\sigma_0^2}
where n is the sample size and \sigma_0^2 is the specified variance.

Step 4: Determine the Critical Value

Using the chi-squared distribution, we find the critical value for a two-tailed test at the \alpha = 0.05 significance level with n-1 degrees of freedom.

Step 5: Make a Decision

Compare the calculated \chi^2 statistic to the critical value from the chi-squared distribution table. If the \chi^2 statistic is greater than the critical value or less than the lower critical value, we reject the null hypothesis.

Conclusion

Based on the comparison of the \chi^2 statistic and the critical value, we determine whether there is enough evidence to conclude that the variance of the weight of nose horns is different from the specified value.

implementation

Python

import numpy as np
from scipy.stats import chi2

# Data
weights = np.array([12.3, 11.7, 12.5, 12.1, 12.4, 11.8, 12.2, 12.3, 11.9, 12.0,
                    12.2, 12.3, 12.1, 11.8, 12.4, 12.2, 12.3, 11.9, 12.1, 12.2])
n = len(weights)
sigma0_squared = 0.1  # specified variance

# Calculate sample variance
sample_variance = np.var(weights, ddof=1)

# Calculate test statistic
chi_squared_statistic = (n - 1) * sample_variance / sigma0_squared

# Degrees of freedom
df = n - 1

# Calculate p-value
p_value = 2 * (1 - chi2.cdf(np.abs(chi_squared_statistic), df))

# Critical value for two-tailed test at alpha = 0.05
alpha = 0.05
critical_value_lower = chi2.ppf(alpha / 2, df)
critical_value_upper = chi2.ppf(1 - alpha / 2, df)

# Print results
print(f"Sample Variance: {sample_variance}")
print(f"Chi-Squared Statistic: {chi_squared_statistic}")
print(f"Degrees of Freedom: {df}")
print(f"P-Value: {p_value}")
print(f"Critical Value (lower): {critical_value_lower}")
print(f"Critical Value (upper): {critical_value_upper}")

# Conclusion
if chi_squared_statistic < critical_value_lower or chi_squared_statistic > critical_value_upper:
    print("Reject the null hypothesis.")
else:
    print("Fail to reject the null hypothesis.")

R

# Data
weights <- c(12.3, 11.7, 12.5, 12.1, 12.4, 11.8, 12.2, 12.3, 11.9, 12.0,
             12.2, 12.3, 12.1, 11.8, 12.4, 12.2, 12.3, 11.9, 12.1, 12.2)
n <- length(weights)
sigma0_squared <- 0.1  # specified variance

# Calculate sample variance
sample_variance <- var(weights)

# Calculate test statistic
chi_squared_statistic <- (n - 1) * sample_variance / sigma0_squared

# Degrees of freedom
df <- n - 1

# Calculate p-value
p_value <- 2 * (1 - pchisq(abs(chi_squared_statistic), df))

# Critical value for two-tailed test at alpha = 0.05
alpha <- 0.05
critical_value_lower <- qchisq(alpha / 2, df)
critical_value_upper <- qchisq(1 - alpha / 2, df)

# Print results
cat("Sample Variance:", sample_variance, "\n")
cat("Chi-Squared Statistic:", chi_squared_statistic, "\n")
cat("Degrees of Freedom:", df, "\n")
cat("P-Value:", p_value, "\n")
cat("Critical Value (lower):", critical_value_lower, "\n")
cat("Critical Value (upper):", critical_value_upper, "\n")

# Conclusion
if (chi_squared_statistic < critical_value_lower || chi_squared_statistic > critical_value_upper) {
    cat("Reject the null hypothesis.\n")
} else {
    cat("Fail to reject the null hypothesis.\n")
}

Discover more from Science Comics

Subscribe to get the latest posts sent to your email.

Leave a Reply

error: Content is protected !!