I have two vector samples $x,y$:
x = c(107.32362, 89.15552, 90.75148, 109.51189, 98.43394, 97.25716 ,115.39168,
95.68554, 93.60000, 103.00000 ,112.70000, 138.40000, 93.30000 , 87.70000,
83.30000, 105.00000 ,103.40000 ,105.70000, 107.80000, 96.10000, 102.00000,
105.40000, 123.90000 ,141.10000)
y = c(100.1, 82.0, 39.0, 18.0, 83.8 ,109.1 ,114.0 , 95.4, 93.1, 116.8 ,56.9 , 56.6, 86.3
,62.0, 38.9, 85.2 ,124.4, 124.3, 139.2, 105.6, 117.4 ,125.2, 111.5, 131.7)
I want to calculate the t.test for equality of means (or the differences).I am assuming the values are paired.
Because the samples are paired (matched) we must use the differences between the paired values as : $$D = X_{1i} - X_{2i}$$ The point estimate for the paired difference population mean $\mu_{D}=\mu_{x} - \mu_{y}=0$ is denoted as $\bar{D} = \frac{\sum_{i=1}^{n}D_{i}}{n}$ and the standard deviation of the differences $$S_{D} = \sqrt{ \frac{\sum_{i=1}^{n}(D_{i}-\bar{D})^2 }{n-1}}$$ The test statistic for the equality of means is :
$$t =\frac{\bar{D}-\mu_{D}}{ \frac{S_D}{\sqrt{n}}} = 1.835492$$
d = x-y
t = (mean(d)-0)/ (sd(d)/sqrt(length(d)));t
[1] 1.835492
For a two-tail test with a given level of significance $\alpha$, we reject the null hypothesis if the calculated test statistic is greater than the upper-tail critical value $t_{n-1}$ from the $t$ distribution, or if the calculated test statistic is less than the lower-tail critical value $-t_{n-1}$ from the $t$ distribution. That is, the decision rule is: Reject $H_{0}$ if $t > t_{n-1}$ or if $t< -t_{n-1}$ otherwise, do not reject $H_{0}$. The degrees of freedom in our example and $24-1=23$ and for $\alpha =0.10$ the inverse cumulative distribution for $1-\alpha =0.90$ with 23 degrees of freedom of $t$ distribution is $1.31946$
Therefore $t>t_{n-1}$ or $1.83>1.31$ and I reject the null hypothesis.
t>qt(0.9,23)
[1] TRUE
But when I run the t.test()
function in R it reports me a p.value greater than 0.05 (0.0794) and I must not reject the null hypothesis.
> t.test(x,y,
paired = TRUE,
alternative = "two.sided",
conf.level = 0.90)
Paired t-test
data: x and y
t = 1.8355, df = 23, p-value = 0.0794
alternative hypothesis: true difference in means is not equal to 0
90 percent confidence interval:
0.7990197 23.3185494
sample estimates:
mean of the differences
12.05878
What is wrong here ?
conf.level
option only influences the confidence interval, which does not include $0$ and is thus consistent with your decision based on the critical $t$ value. $\endgroup$