How to perform T-Test in R including hypothesis I would like to do a t-test in R. Unfortunately, statistics has never been my best subject, so I'm wondering what the output of t.test in R exactly mean.
For testing purpose I performed a t-test on two normal distributed vectors with equal parameters. Since both distributions have the same parameters, the difference of the variance is 0:
t.test(rnorm(1e7,mean=0,sd=1),rnorm(1e7,mean=0,sd=1),mu=0)

Welch Two Sample t-test

data:  rnorm(1e+07, mean = 0, sd = 1) and rnorm(1e+07, mean = 0, sd = 1) 
t = 0.5014, df = 2e+07, p-value = 0.6161
alternative hypothesis: true difference in means is not equal to 0 
95 percent confidence interval:
 -0.000652202  0.001100571 
sample estimates:
mean of x    mean of y 
2.836860e-04 5.950136e-05 

This obviously gives me the t of the t-test. In order to do something useful with it, I have to formulate a hypothesis which should be tested.


*

*How / where (in terms of R) do I formulate a hypothesis?

*How do I know if my hypothesis is significant?


My idea was:
An interesting hypothesis on two data vectors might be: 
$$
H_{0}: \mu_{X}-\mu_{Y} = w
$$
vs.
$$
H_{1}: \mu_{X}-\mu_{Y} \neq w
$$
Where $\mu_{X}, \mu_{Y}$ are mean values of the underlying deviation of $X,Y$.
Since these might be different from the mean of the given data vectors, I have to use t in order to accept or refuse $H_{0}$ ($H_{1}$) (so far correct?).
Looking at wikipedia, $H_{0}$ is refused if $|t| > t(1-\frac{1}{2}\alpha, m+n-2)$ where $\alpha = 0.05$ (standard paramter of t.test in R) and $df=m+n-2$. In this case t(..,..) is some giant table where I can look up the corresponding value.  


*

*Where do I get this value in R and at which point did is specify $w$
for $H_{0}, H_{1}$?

 A: *

*You have to formulate the hypothesis before you do any tests. The
hypothesis follows from your research question. In the case of the $t$-test, one possible two-sided hypothesis is the one you have given, i.e. that the difference between the two means equals some number. In most cases, $w=0$ and the $t$-test tests the null hypothesis that the two means are equal vs. that the two means are different. In the function t.test you can specify $w$ with the option mu. In the example that you provided, you've set $w=0$ so the null hypothesis is that the two means are equal. The output from t.test even states the alternative hypothesis: alternative hypothesis: true difference in means is not equal to 0. To specify a one-sided alternative hypothesis, use the alternative option of t.test. This may be "two.sided" for a two-sided alternative: the difference of means could be smaller or greater), "greater": the difference between the means is greater than the value that you specified with mu, "smaller" for the one-sided hypothesis that the difference of the means is smaller.

*The significance test is given by the output of t.test in R. It provides the $t$-value , the degrees of freedom and the corresponding $p$-value. In your case, it is not surprising that the $p$-value is not significant ($p>0.05$) because you generated both samples from a normal distribution with equal mean.

*The output of t.test provides all necessary information but if you want to get the critical $t$-value manually, you can use the qt function in R. In your example this would be ($\alpha=0.05, df=2\cdot 10^{7}$): qt(1-0.5*0.05, df=2e7). This gives the critical $t$-value of $1.96$. The $t$-value from your test is much lower and thus, you have not enough evidence to reject the null hypothesis that the two means are equal. To get the $p$-value for a two-sided hypothesis in R, you could type: 2*pt(-abs(t),df=n-1). In your case $t=0.5014$ and thus: 2*pt(-abs(0.5014), df=2e7) which yields $0.616$.

