# 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
Run the code above in your browser using DataLab