0
$\begingroup$

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?

$\endgroup$
3
  • 1
    $\begingroup$ @user2974951 As a general rule it can't be correct, because that would never give a p-value above 0.5 $\endgroup$
    – Glen_b
    Commented Sep 27, 2018 at 16:07
  • $\begingroup$ @Glen_b That is a good point. What is the correct (i.e., most general way) to do it? $\endgroup$
    – N08
    Commented Sep 27, 2018 at 16:48
  • $\begingroup$ What happens when there's a one-tailed hypothesis test and the results are in the other tail? ... the answer there seems to cover your question so this may in effect be a duplicate $\endgroup$
    – Glen_b
    Commented Sep 29, 2018 at 6:28

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.