one-sided t-test for two groups

I have two groups and a variable of interest

I know how to do a two sided t-test to test if the means are different.
t.test(data$pv1~data$IND)

How do I have to code a one sided t-test if I have the hypothesis that the mean of one group is bigger?

The t.test function has an argument named alternative which can be set to two.sided, less, or greater. You can read about the complete options by running

?t.test

Here is an example with some invented data.

x = rnorm(n = 100, mean = 1, sd = 0.1)
y = rnorm(n = 100, mean = 1.3, sd = 0.1)
t.test(x= x, y = y, alternative = "greater")
#> 
#>  Welch Two Sample t-test
#> 
#> data:  x and y
#> t = -22.147, df = 195.32, p-value = 1
#> alternative hypothesis: true difference in means is greater than 0
#> 95 percent confidence interval:
#>  -0.3142285        Inf
#> sample estimates:
#> mean of x mean of y 
#>  1.017068  1.309476
t.test(x= x, y = y, alternative = "less")
#> 
#>  Welch Two Sample t-test
#> 
#> data:  x and y
#> t = -22.147, df = 195.32, p-value < 2.2e-16
#> alternative hypothesis: true difference in means is less than 0
#> 95 percent confidence interval:
#>        -Inf -0.2705878
#> sample estimates:
#> mean of x mean of y 
#>  1.017068  1.309476

Created on 2020-08-20 by the reprex package (v0.3.0)

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.