# 13.6: One Sided Tests

- Page ID
- 4026

When introducing the theory of null hypothesis tests, I mentioned that there are some situations when it’s appropriate to specify a * one-sided* test (see Section 11.4.3). So far, all of the t-tests have been two-sided tests. For instance, when we specified a one sample t-test for the grades in Dr Zeppo’s class, the null hypothesis was that the true mean was 67.5%. The alternative hypothesis was that the true mean was greater than

*less than 67.5%. Suppose we were only interested in finding out if the true mean is greater than 67.5%, and have no interest whatsoever in testing to find out if the true mean is lower than 67.5%. If so, our null hypothesis would be that the true mean is 67.5% or less, and the alternative hypothesis would be that the true mean is greater than 67.5%. The*

*or*`oneSampleTTest()`

function lets you do this, by specifying the `one.sided`

argument. If you set `one.sided="greater"`

, it means that you’re testing to see if the true mean is larger than `mu`

. If you set `one.sided="less"`

, then you’re testing to see if the true mean is smaller than `mu`

. Here’s how it would work for Dr Zeppo’s class:**oneSampleTTest**( x=grades, mu=67.5, one.sided="greater" )

```
##
## One sample t-test
##
## Data variable: grades
##
## Descriptive statistics:
## grades
## mean 72.300
## std dev. 9.521
##
## Hypotheses:
## null: population mean less than or equal to 67.5
## alternative: population mean greater than 67.5
##
## Test results:
## t-statistic: 2.255
## degrees of freedom: 19
## p-value: 0.018
##
## Other information:
## one-sided 95% confidence interval: [68.619, Inf]
## estimated effect size (Cohen's d): 0.504
```

Notice that there are a few changes from the output that we saw last time. Most important is the fact that the null and alternative hypotheses have changed, to reflect the different test. The second thing to note is that, although the t-statistic and degrees of freedom have not changed, the p-value has. This is because the one-sided test has a different rejection region from the two-sided test. If you’ve forgotten why this is and what it means, you may find it helpful to read back over Chapter 11, and Section 11.4.3 in particular. The third thing to note is that the confidence interval is different too: it now reports a “one-sided” confidence interval rather than a two-sided one. In a two-sided confidence interval, we’re trying to find numbers a and b such that we’re 95% confident that the true mean lies * between* a and b. In a one-sided confidence interval, we’re trying to find a single number a such that we’re 95% confident that the true mean is

*a (or less than a if you set*

*greater than*`one.sided="less"`

).So that’s how to do a one-sided one sample t-test. However, all versions of the t-test can be one-sided. For an independent samples t test, you could have a one-sided test if you’re only interestd in testing to see if group A has * higher* scores than group B, but have no interest in finding out if group B has higher scores than group A. Let’s suppose that, for Dr Harpo’s class, you wanted to see if Anastasia’s students had higher grades than Bernadette’s. The

`independentSamplesTTest()`

function lets you do this, again by specifying the `one.sided`

argument. However, this time around you need to specify the name of the group that you’re expecting to have the higher score. In our case, we’d write `one.sided = "Anastasia"`

. So the command would be:**independentSamplesTTest**(
formula = grade ~ tutor,
data = harpo,
one.sided = "Anastasia"
)

```
##
## Welch's independent samples t-test
##
## Outcome variable: grade
## Grouping variable: tutor
##
## Descriptive statistics:
## Anastasia Bernadette
## mean 74.533 69.056
## std dev. 8.999 5.775
##
## Hypotheses:
## null: population means are equal, or smaller for group 'Anastasia'
## alternative: population mean is larger for group 'Anastasia'
##
## Test results:
## t-statistic: 2.034
## degrees of freedom: 23.025
## p-value: 0.027
##
## Other information:
## one-sided 95% confidence interval: [0.863, Inf]
## estimated effect size (Cohen's d): 0.724
```

Again, the output changes in a predictable way. The definition of the null and alternative hypotheses has changed, the p-value has changed, and it now reports a one-sided confidence interval rather than a two-sided one.

What about the paired samples t-test? Suppose we wanted to test the hypothesis that grades go * up* from test 1 to test 2 in Dr Zeppo’s class, and are not prepared to consider the idea that the grades go down. Again, we can use the

`one.sided`

argument to specify the one-sided test, and it works the same way it does for the independent samples t-test. You need to specify the name of the group whose scores are expected to be larger under the alternative hypothesis. If your data are in wide form, as they are in the `chico`

data frame, you’d use this command:**pairedSamplesTTest**(
formula = ~ grade_test2 + grade_test1,
data = chico,
one.sided = "grade_test2"
)

```
##
## Paired samples t-test
##
## Variables: grade_test2 , grade_test1
##
## Descriptive statistics:
## grade_test2 grade_test1 difference
## mean 58.385 56.980 1.405
## std dev. 6.406 6.616 0.970
##
## Hypotheses:
## null: population means are equal, or smaller for measurement 'grade_test2'
## alternative: population mean is larger for measurement 'grade_test2'
##
## Test results:
## t-statistic: 6.475
## degrees of freedom: 19
## p-value: <.001
##
## Other information:
## one-sided 95% confidence interval: [1.03, Inf]
## estimated effect size (Cohen's d): 1.448
```

Yet again, the output changes in a predictable way. The hypotheses have changed, the p-value has changed, and the confidence interval is now one-sided. If your data are in long form, as they are in the `chico2`

data frame, it still works the same way. Either of the following commands would work,

`> `**pairedSamplesTTest**(
formula = grade ~ time,
data = chico2,
id = "id",
one.sided = "test2"
)
> **pairedSamplesTTest**(
formula = grade ~ time + (id),
data = chico2,
one.sided = "test2"
)

and would produce the same answer as the output shown above.