比例差异的置信区间

机器算法验证 r 置信区间
2022-02-03 13:51:43

我想知道是否有人可以让我知道我是否正确计算了两个比例之间差异的置信区间。

样本量为 34 人,其中女性 19 人,男性 15 人。因此,比例差异为 0.1176471。

我计算了介于 -0.1183872 和 0.3536814 之间的差异的 95% 置信区间。当置信区间通过零时,差异在统计上不显着。

以下是我在 R 中的工作,结果作为评论:

f <- 19/34
# 0.5588235

m <- 15/34
# 0.4411765

n <- 34
# 34

difference <- f-m
# 0.1176471

lower <- difference-1.96*sqrt((f*(1-f))/n+(m*(1-m))/n)
# -0.1183872

upper <- difference+1.96*sqrt((f*(1-f))/n+(m*(1-m))/n)
# 0.3536814
3个回答

OP 接受的我的原始答案假设有两个样本设置。OP 的问题涉及一个样本设置。因此,@Robert Lew 的答案在这种情况下是正确的。

原始答案

你的公式和计算是正确的。R比较比例的内部函数产生相同的结果(尽管没有连续性校正):

prop.test(x=c(19,15), n=c(34,34), correct=FALSE)

    2-sample test for equality of proportions without continuity correction

data:  c(19, 15) out of c(34, 34)
X-squared = 0.9412, df = 1, p-value = 0.332
alternative hypothesis: two.sided
95 percent confidence interval:
 -0.1183829  0.3536770
sample estimates:
   prop 1    prop 2 
0.5588235 0.4411765

在这种情况下,您必须使用单样本测试,因为这是单样本。您的问题归结为男性(或女性)是否是二分之一。下面是使用 prop.test() 的方法:

prop.test(x=19, n=34, p=0.5, correct=FALSE)

    1-sample proportions test without continuity correction

data:  19 out of 34, null probability 0.5
X-squared = 0.47059, df = 1, p-value = 0.4927
alternative hypothesis: true p is not equal to 0.5
95 percent confidence interval:
 0.3945390 0.7111652
sample estimates:
    p 
0.5588235 

考虑到小样本量,可以使用以下公式计算精确的 CI ExactCIdiff::BinomCI

library(ExactCIdiff)
BinomCI(34,34,19,15)
$conf.level
[1] 0.95

$CItype
[1] "Two.sided"

$estimate
[1] 0.1176

$ExactCI
[1] -0.1107  0.3393