计算两个均值的差异及其置信区间

Calculating difference of two means and its confidence interval

我有使用或不使用药物“X”的患者的蛋白质“F”的数据。 我有 3 位联合创始人(年龄、BMI、性别)需要调整。

我使用以下代码成功计算了药物组和非药物组的蛋白质含量均值:

> F <- data$f
> by(F, drugnodrug, summary)
> summ(F, by=drugnodrug)

现在,我想计算绝对均值差(95% 置信区间)。

我如何在 R(dplyr 包)中执行此操作?我可以使用多元线性回归进行此计算吗?如何使用?

这可以用基数 R 完成,因为 t.test 还报告了均值差的置信区间:

> res <- t.test(iris$Sepal.Length[iris$Species=="setosa"],
+               iris$Sepal.Length[iris$Species=="virginica"])
> res$conf.int
[1] -1.78676 -1.37724
attr(,"conf.level")
[1] 0.95

平均值存储在条目estimate中,您可以使用

计算平均值的差异
> res$estimate[1] - res$estimate[2]
mean of x 
   -1.582

或等效

> sum(res$estimate * c(1,-1))
[1] -1.582