import numpy as np
import scipy.stats as stats

# 假设数据
# 老龄化程度较高的群体数据
high_aging_data = {
    '老龄化给社会带来的主要问题': np.array([75.47, 85.85, 84.91, 53.77, 83.96]),
    '政府应该采取哪些措施': np.array([62.26, 16.04, 91.51, 88.68, 51.89,0.94]),
    'life_expectancy': np.array([75, 76, 74, 77, 75]),
    # 其他可能的因素...
}

# 老龄化程度较低的群体数据
low_aging_data = {
    '老龄化给社会带来的主要问题': np.array([84.62, 69.23, 69.23, 15.38, 84.62]),
    '政府应该采取哪些措施': np.array([46.15, 7.69, 69.23, 76.92, 30.77,7.69]),
    'life_expectancy': np.array([70, 71, 69, 72, 70]),
    # 其他可能的因素...
}

# 进行t检验并分析结果
factors = ['老龄化给社会带来的主要问题', '政府应该采取哪些措施', 'life_expectancy']
system_evaluation = {}

for factor in factors:
    high_group = high_aging_data[factor]
    low_group = low_aging_data[factor]
    t_stat, p_value = stats.ttest_ind(high_group, low_group)
    system_evaluation[factor] = {
        't_statistic': t_stat,
        'p_value': p_value,
        'effect_size': np.abs(t_stat) * np.sqrt((len(high_group) + len(low_group)) / (len(high_group) * len(low_group)))
    }
    print(f"{factor}的t统计量: {t_stat}, P值: {p_value}")
    if p_value < 0.05:
        print(f"{factor}在两个群体之间存在显著差异。\n")
    else:
        print(f"{factor}在两个群体之间没有显著差异。\n")

# 打印系统评价
print("系统评价：")
for factor, evaluation in system_evaluation.items():
    print(f"{factor}: t统计量={evaluation['t_statistic']}, P值={evaluation['p_value']}, 影响大小={evaluation['effect_size']}")
