# R: T-test giving me strange results. Null hypothesis always rejected

Here is my r code and the output of the t-test. Even if the mean is clearly 0, the t-test still accepts the alternative hypothesis.

> x = c(-2, -2, -1, -1, -1, -1, -1, -1, -1, 1, 1, 1, 1, 1, 1, 1, 2, 2)
> t.test(x, alternative="two.sided")

One Sample t-test

data:  x
t = 0, df = 17, p-value = 1
alternative hypothesis: true mean is not equal to 0
95 percent confidence interval:
-0.6606089  0.6606089
sample estimates:
mean of x
0


Similarly if I run the code on different vector.

> x = c(2, 2, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 2)
> t.test(x, alternative="two.sided")

One Sample t-test

data:  x
t = 12.1214, df = 17, p-value = 8.625e-10
alternative hypothesis: true mean is not equal to 0
95 percent confidence interval:
1.009486 1.434958
sample estimates:
mean of x
1.222222


Here I would be expecting to see: alternative hypothesis: true mean is greater than 0, but it only happens if I put the alternative parameter to "greater".

I feel like this is a very basic misunderstanding of how the t-test works in R.

• Welcome to our site! Thanks for providing your complete code, and so making your example reproducible. It turns out that your issue is really about understanding R output rather than understanding statistical content per se (so some might argue this belongs on Stack Overflow), but since other searchers might look here first to work out what's going on, I think there is a place for it on Cross Validated. – Silverfish Nov 24 '15 at 4:03
• If you'd typed ?t.test (or looked at the help online) you'd see that alternative is "a character string describing the alternative hypothesis" rather than the decision the test comes to. Probably a good idea if you're not sure what's going on. – Silverfish Nov 24 '15 at 4:03
• @Silverfish At the topic of statistics. I am using this t-test to determine if answers to questionnaire (answers are on 5-point Likert scale) are statistically significant towards either "Agree" or "Disagree". n = 18. What is appropriate significance level for my t-test? – Mazvél Nov 24 '15 at 4:12

The line where it says alternative hypothesis: true mean is not equal to 0 is not the result of the test! Instead, it simply restates what the alternative hypothesis is. It is upon you to decide, based on the p-value, whether you reject or fail to reject the null hypothesis.
In your first example, you fail to reject the null (p-value = 1), meaning the true mean of the underlying population you are sampling from is not significantly different from zero.
In your second example your p-value = 8.625e-10 and you reject the null concluding that true mean of the underlying population you are sampling from is significantly different from zero.