import numpy as np
from scipy import stats
def bartlett_test(*groups):
"""
Perform Bartlett's Test for Homogeneity of Variances.
Parameters:
*groups: One or more data arrays representing different groups.
Returns:
stat: The test statistic.
p_value: The p-value for the test.
"""
stat, p_value = stats.bartlett(*groups)
return stat, p_value
# Example data (groups of samples)
group1 = [23, 21, 19, 24, 20, 18] # Sample data for group 1
group2 = [12, 14, 15, 10, 13, 12] # Sample data for group 2
group3 = [30, 31, 29, 32, 30, 29] # Sample data for group 3
# Perform Bartlett's Test
stat, p_value = bartlett_test(group1, group2, group3)
# Output the results
print(f"Bartlett's Test Statistic: {stat}")
print(f"P-value: {p_value}")
# Decision based on p-value
alpha = 0.05
if p_value < alpha:
print("Reject the null hypothesis: Variances are not homogeneous.")
else:
print("Fail to reject the null hypothesis: Variances are homogeneous.")