I was trying t-test in r to compare mean difference between yes-no but the t-test shows the result for no-yes. A contains continous variables while B cotains factor variable Yes and No.
I used the following code
t.test(A~b, data=df, var.equal=TRUE, conf.level=0.86)
The output was
Two Sample t-test
data: A by B
t = -0.87491, df = 13, p-value = 0.3975
alternative hypothesis: true difference in means between group No and group Yes is not equal to 0
86 percent confidence interval:
-2094.6341 596.6341
sample estimates:
mean in group No mean in group Yes
1757.2 2506.2
But i wanted to check for alternative true difference in means between group Yes and group No is not equal to 0 and find the confidence interval and compare it with the results i obtained from bootstrapping by simulation.
suppose my dataframe looks like this | A | B | |----|-----| | 1 | yes | | 2 | yes | | 3 | yes | | 4 | yes | | 2 | no | | 3 | no | | 4 | no | | 5 | no |
yes = c(1,2,3,4)
no = c(2,3,4,5)
bootstrap = replicate(1000,{
yes.samp = sample(yes, replace=TRUE)
no.samp = sample(no, replace=TRUE)
mean(yes.samp) - mean(no.samp)
})