I have two samples d1
and d2
:
d1 <- c(18,21,16,22,19,24,17,21,23,18,14,16,16,19,18,20,12,22,15,17)
d2 <- c(22,25,17,24,16,29,20,23,19,20,15,15,18,26,18,24,18,25,19,16)+5
d <- d2-d1
In order to perform a paired two-tail t-test I use the following code on the differences d
:
standard_error <- function(vals){
return(sd(vals) / sqrt(length(vals)))
}
t_test <- function(d){
t <- mean(d) / standard_error(d)
return(2*pt(abs(t), length(d)-1, lower=F))
}
This gives me that the p-value is 9.37919e-10
, so quite a significant result. As an alternative I tried using t.test
-function in R:
t.test(d1, d2, paired=T)
This gives me the same as above, so everything is OK here.
However, now I want to perform a one-tailed t-test for if the mean of d2
is larger than that of d1
. Is it correct that I can achieve this by simply returning pt(abs(t)
in the t_test
-function above, i.e., divide it by 2?