ci_from_p {neatStats} | R Documentation |
CI from p value
Description
Calculates approximate confidence interval (CI) for any given difference, based on the difference value and p value, according to Altman & Bland (2011).
Usage
ci_from_p(diff, p_value, ci = 0.95)
Arguments
diff |
Difference (number) around which the CI is to be calculated. |
p_value |
The p value for CI calculation. |
ci |
Numeric; confidence level for the returned CIs ( |
Value
CI limits as named numeric vector with two elements.
Note
Check the Altman & Bland (2011) paper for details! (The calculation for proportions is not implemented here.)
References
Altman, D. G., & Bland, J. M. (2011). How to obtain the confidence interval from a P value. Bmj, 343(d2090). doi:10.1136/bmj.d2090
Examples
# Example 1
# calculate proportion difference test
proptest_stat = prop.test(x = c(49, 40), n = c(50, 50))
# calculate proportion difference
my_diff = 49/50-40/50
# calculate approximate CI
ci_from_p(my_diff, proptest_stat$p.value)
# returned CI should be very similar to the actual CI
proptest_stat$conf.int
# Example 2
# generate random data
v1 = stats::rnorm(190, 40, 60)
v2 = stats::rnorm(170, 50, 45)
# calculate t-test
ttest_stat = stats::t.test(v1, v2)
# calculate mean difference
my_diff = mean(v1) - mean(v2)
# calculate approximate CI
ci_from_p(my_diff, ttest_stat$p.value)
# returned CI should be similar to the actual CI
ttest_stat$conf.int
[Package neatStats version 1.13.3 Index]