这是我称为本机的数据集。该数据集有500行数据,但是这里我只显示了9行数据。我想确定从未怀孕的妇女和怀孕的妇女之间的bmi(体重)是否存在差异。
bmi ever.pregnant
28.5 yes
33.3 yes
23.4 yes
26.6 yes
34.1 yes
24 yes
26.4 yes
45.6 yes
25.3 yes
我想通过自举计算此假设。所以我这样设定我的假设:
H0: : There is no relation between bmi and ever.pregnant.
H1 : There is a relation between bmi and ever.pregnant.
我尝试过的代码:
aggregate(bmi ~ ever.pregnant, native, mean)$bmi
bw = diff(aggregate(bmi ~ ever.pregnant, native, mean)$bmi)
bw0 = replicate(1000, {
pregnant.sim = sample(native$ever.pregnant)
diff(aggregate(bmi ~ pregnant.sim, native, mean)$bim)
})
hist(bw0)
pVal = mean(bw0 > bw)
我想要的输出: 1)直方图 2)一个p值
但是我遇到错误,无法获得输出。请提出建议!