🔧
tool
相关软件(R代码)
```r # 手动计算置信区间 hemoglobin_change <- c(2.5, 3.1, 1.8, 2.9, 3.5, 2.2, 2.7, 3.0, 2.4, 2.8, 3.2, 2.6, 2.1, 3.3, 2.0, 2.5, 2.9, 3.1, 2.3, 2.7) n <- length(hemoglobin_change) x_bar <...
📖 定义
# 手动计算置信区间
hemoglobin_change <- c(2.5, 3.1, 1.8, 2.9, 3.5, 2.2, 2.7, 3.0, 2.4, 2.8,
3.2, 2.6, 2.1, 3.3, 2.0, 2.5, 2.9, 3.1, 2.3, 2.7)
n <- length(hemoglobin_change)
x_bar <- mean(hemoglobin_change)
s <- sd(hemoglobin_change)
se <- s / sqrt(n)
# 95% 置信区间(t分布)
t_crit <- qt(0.975, df = n - 1)
ci_lower <- x_bar - t_crit * se
ci_upper <- x_bar + t_crit * se
cat("95% 置信区间: (", round(ci_lower, 3), ", ", round(ci_upper, 3), ")\n")
# 使用R内置函数(更简洁)
t.test(hemoglobin_change, conf.level = 0.95)$conf.int
# 不同置信水平的比较
cat("90% CI:", t.test(hemoglobin_change, conf.level = 0.90)$conf.int, "\n")
cat("99% CI:", t.test(hemoglobin_change, conf.level = 0.99)$conf.int, "\n")