I'm running the example of the R-intro manual:
A = c(79.98, 80.04, 80.02, 80.04, 80.03, 80.03, 80.04, 79.97, 80.05, 80.03, 80.02, 80.00, 80.02)
B = c(80.02, 79.94, 79.98, 79.97, 79.97, 80.03, 79.95, 79.97)
t.test(A, B)
Which produces the following result:
Welch Two Sample t-test
data: A and B
t = 3.2499, df = 12.027, p-value = 0.006939
alternative hypothesis: true difference in means is not equal to 0
95 percent confidence interval:
0.01385526 0.07018320
sample estimates:
mean of x mean of y
80.02077 79.97875
The question is: if the difference of means is contained within the confidence interval (80.02077-79.97875=0.04202 and 0.01385526<0.04202<0.07018320) why does it conclude that the alternative hypothesis is true and not that the null hypothesis is true?
I think this is a language/interpretation problem. You are interpreting
alternative hypothesis: true difference in means is not equal to 0
as
The alternative hypothesis is true. The difference in means is not equal to 0
rather than (as intended)
The alternative hypothesis is: "the true difference in means is not equal to 0"
(According to strict frequentist logic we would never conclude "the alternative hypothesis is true", only that we can reject the null hypothesis.)
In order to evaluate the conclusions of the test, you should look at the 95% confidence interval (0.01385526, 0.07018320) and/or the p-value (0.0069). The procedure implemented in R does not follow a "Neyman-Pearson" style where you pre-specify an alpha level and dichotomize the result into "reject null hypothesis" or "fail to reject null hypothesis". If you want to do this, you can either just look at the p-value or, if you want R to do it for you,
alpha <- 0.05 ## or whatever your preferred cutoff is
t_result <- t.test(A,B)
t_result$p.value<alpha ## TRUE (reject null hypothesis)
Furthermore, your interpretation of the confidence interval is wrong. You should look to see whether the confidence interval includes zero; it will always be centred on the observed difference (so the observed difference will always be included in the 95% CI).