统计学 P 值计算
用于科研数据分析的统计程序,支持快速计算和输出实验数据的 P 值。
⬇️ 下载原始 Jupyter Notebook (.ipynb) 文件
🚀 在线运行 (Google Colab)💻 核心源代码
import numpy as np
from scipy import stats
# Example data for two independent samples (mean, std dev, sample size)
mean1 = 102.2072
std1 = 18.089
nobs1 = 5
mean2 = 133.8234
std2 = 9.78
nobs2 = 5
# Perform independent samples t-test using stats
t_stat, p_value = stats.ttest_ind_from_stats(mean1=mean1, std1=std1, nobs1=nobs1,
mean2=mean2, std2=std2, nobs2=nobs2)
# Determine significance stars
stars = ''
if p_value < 0.001:
stars = '***'
elif p_value < 0.01:
stars = '**'
elif p_value < 0.05:
stars = '*'
print(f"t统计量: {t_stat}")
print(f"P值: {p_value}{stars}")