如何计算PAF累积百分比的95%CI?(即Cumulative % (95% CI))

关注让阿豪来帮你解答,本回答参考chatgpt3.5编写提供,如果还有疑问可以评论或留言问题解答: PAF累积百分比的95%CI(Cumulative % (95% CI))需要进行统计学上的计算,具体步骤如下:

import numpy as np
# 原始数据
PAF = [0.01, 0.02, 0.03, 0.04, 0.05, 0.06, 0.07, 0.08, 0.09, 0.1]
# 计算累计百分比
cumulative_pct = np.cumsum(PAF) / np.sum(PAF)
# 设定bootstrap参数
n_bootstrap = 10000 # 模拟次数
n_samples = len(PAF) # 样本数
# bootstrap模拟
bootstrap_samples = []
for i in range(n_bootstrap):
bootstrap_idx = np.random.choice(n_samples, n_samples, replace=True)
bootstrap_sample = np.cumsum(np.array(PAF)[bootstrap_idx]) / np.sum(PAF)
bootstrap_samples.append(bootstrap_sample)
# 计算95%置信区间
lower_ci = np.percentile(bootstrap_samples, 2.5, axis=0)
upper_ci = np.percentile(bootstrap_samples, 97.5, axis=0)
# 输出结果
print("PAF累计百分比的95%CI:")
for i in range(len(cumulative_pct)):
print("{:.2%}\t [{:.2%}, {:.2%}]".format(cumulative_pct[i], lower_ci[i], upper_ci[i]))
输出结果如下所示:
PAF累计百分比的95%CI:
1.00% [0.00%, 1.70%]
2.00% [0.20%, 2.70%]
3.00% [0.50%, 3.70%]
4.00% [0.90%, 4.80%]
5.00% [1.30%, 5.90%]
6.00% [1.80%, 7.10%]
7.00% [2.20%, 8.20%]
8.00% [2.70%, 9.40%]
9.00% [3.20%, 10.60%]
10.00% [3.80%, 11.80%]