英文:
How to get one-sided 95% CI for each column in R?
问题
我尝试获取下侧的单边95%置信区间如下所示:
set.seed(123)
dd=data.frame(a = rnorm(100, mean = 24, sd = 5),
b = rnorm(100, mean = 7, sd = 2),
c = rnorm(100, mean = 59, sd = 10))
sapply(dd, t.test, alternative = "less")
但结果的估计仅返回每列的均值。
此外,我可以为每列生成双边95%置信区间如下所示:
library(Rmisc)
sapply(dd, CI)
是否有一种类似的方法可以获取每列的上侧或下侧单边95%置信区间,而不是双边的?
英文:
I tried to get the lower one-sided 95% CI as below:
set.seed(123)
dd=data.frame(a = rnorm(100, mean = 24, sd = 5),
b = rnorm(100, mean = 7, sd = 2),
c = rnorm(100, mean = 59, sd = 10))
sapply(dd, t.test, alternative = "less")
But the estimate of the result only return the mean for each column.
Besides, I could generate two-sided 95% CI for each column as below:
library(Rmisc)
sapply(dd, CI)
Is there a similar way to get upper or lower one-sided 95% CI for each column instead of two-sided?
答案1
得分: 2
t.test()
将返回与指定的备择假设相适应的均值的置信区间。您可以使用 $conf.int
提取它。
sapply(dd, \(x) t.test(x, alternative = "less")$conf.int)
# a b c
# [1,] -Inf -Inf -Inf
# [2,] 25.20985 7.106022 61.78182
sapply(dd, \(x) t.test(x, alternative = "greater")$conf.int)
# a b c
# [1,] 23.69421 6.463791 58.62748
# [2,] Inf Inf Inf
英文:
t.test()
will return a confidence interval for the mean appropriate to the specified alternative hypothesis. You can use $conf.int
to extract it.
sapply(dd, \(x) t.test(x, alternative = "less")$conf.int)
# a b c
# [1,] -Inf -Inf -Inf
# [2,] 25.20985 7.106022 61.78182
sapply(dd, \(x) t.test(x, alternative = "greater")$conf.int)
# a b c
# [1,] 23.69421 6.463791 58.62748
# [2,] Inf Inf Inf
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论