Department of Statistics, Virginia Tech

A taxi company manager is trying to decide whether the use of radial tires instead of regular belted tires is the same. Twelve cars were equipped with radial tires and driven over a prescribed test course. Without changing drivers, the same cars were then equipped with regular belted tires and driven once again over the test course.

The gasoline consumption, in kilometers per liter, is recorded as follows

```
kpl <- data.frame(
radial=c(4.2, 4.7, 6.6, 7.0, 6.7, 4.5, 5.7, 6.0, 7.4, 4.9, 6.1, 5.2),
belted=c(4.1, 4.9, 6.2, 6.9, 6.8, 4.4, 5.7, 5.8, 6.9, 4.7, 6.0, 4.9))
```

The hypotheses of interest are \(\mathcal{H}_0: \mathbb{P}(+) = \mathbb{P}(-)\), versus \(\mathcal{H}_1: \mathbb{P}(+) \ne \mathbb{P}(-)\).

First we calculate the observed \(t\) statistic, which (taking \(Y\) to be `radial`

and \(X\) to be `belted`

) is the count of the number of times `radial`

is bigger than `belted`

. Then we calculate \(n\) which which is the count of times that `belted`

is not equal to `radial`

.

```
t <- sum(kpl$belted < kpl$radial)
n <- sum(kpl$belted != kpl$radial)
c(t, n)
```

`## [1] 9 11`

So we have the following null distribution: \(T \sim \mathrm{Bin}(11, p=1/2)\). Now, we have a number of options for testing the hypotheses, depending on whether we want to do it by hand or using a library.

**By hand**, using code for two-tailed tests.

```
pstar <- 0.5
c(t, pstar*n)
```

`## [1] 9.0 5.5`

The observed test statistic, 9, is above the null mean which is 5.5, so we have to calculate \(t^L\),

- the number values on the left hand side of the mean have mass less than or equal to \(t\).
- This is the mirror image of our binomial example from earlier.

```
lhs <- seq(0, floor(pstar*n))
eps <- sqrt(.Machine$double.eps) ## numerical wiggle room
tL <- sum(dbinom(lhs, n, pstar) <= dbinom(t, n, pstar) * (1 + eps))
pbinom(tL - 1, n, pstar) + pbinom(t - 1, n, pstar, lower.tail=FALSE)
```

`## [1] 0.06542969`

- Alternatively, via approximation.

`2 * pbinom(t-1, n, pstar, lower.tail=FALSE)`

`## [1] 0.06542969`

**Library** method using `binom.test`

:

`binom.test(t, n, pstar)`

```
##
## Exact binomial test
##
## data: t and n
## number of successes = 9, number of trials = 11, p-value = 0.06543
## alternative hypothesis: true probability of success is not equal to 0.5
## 95 percent confidence interval:
## 0.4822441 0.9771688
## sample estimates:
## probability of success
## 0.8181818
```

- agrees with our first calculation.

Since in all three cases our \(p\)-value of \(0.06 > 0.05\), a typical significance level, we fail to reject the null hypothesis and conclude that there is no difference between radial and belted tires.

A study was conducted to determine whether the systolic blood pressure of runners was the same before and after running. Data was collected on the systolic pressure of 25 runners before and after an 8km run. It was found that in this study 23 runners had higher systolic pressure after the run, and no runners had the same systolic pressure before and after the run.

We have

```
t <- 23
n <- 25
n*pstar
```

`## [1] 12.5`

and the null distribution \(T \sim \mathrm{Bin}(25, 1/2)\). Again, \(t\) is above the null mean so a two-tailed test (\(\mathcal{H}_0: \mathbb{P}(+) = \mathbb{P}(-)\), versus \(\mathcal{H}_1: \mathbb{P}(+) \ne \mathbb{P}(-)\)) follows the same code as above (all lumped together this time).

```
lhs <- seq(0, floor(pstar*n))
tL <- sum(dbinom(lhs, n, pstar) <= dbinom(t, n, pstar) * (1 + eps))
pbinom(tL - 1, n, pstar) + pbinom(t - 1, n, pstar, lower.tail=FALSE)
```

`## [1] 1.943111e-05`

`2 * pbinom(t-1, n, pstar, lower.tail=FALSE)`

`## [1] 1.943111e-05`

`binom.test(t, n, pstar)`

```
##
## Exact binomial test
##
## data: t and n
## number of successes = 23, number of trials = 25, p-value =
## 1.943e-05
## alternative hypothesis: true probability of success is not equal to 0.5
## 95 percent confidence interval:
## 0.7396942 0.9901604
## sample estimates:
## probability of success
## 0.92
```

- A clear reject of \(\mathcal{H}_0\) at the \(\alpha = 0.05\) level. We conclude that indeed running effects systolic blood pressure.

The following data presents the weights of five people, in kilograms, before they stopped smoking and five weeks after they stopped smoking.

```
weight <- data.frame(
before=c(66, 80, 69, 52, 75),
after=c(71, 82, 68, 56, 73))
```

How could we test whether a person’s weight increases after they quit smoking?

- Upper or lower tailed test?
- That depends on how we define \(X\) and \(Y\).

Let \(Y\) be “weight after” and \(X\) be “weight before”. Then

- a bigger \(t\), counting \(x_i < y_i\), would support the alternative hypothesis \(\mathcal{H}_1: \mathbb{P}(+) > \mathbb{P}(-)\), which is that weight increases after smoking.

- So we are doing an
*upper-tailed*test.

In R:

```
t <- sum(weight$before < weight$after)
n <- sum(weight$before != weight$after)
c(t,n)
```

`## [1] 3 5`

and we have the null distribution \(T \sim \mathrm{Bin}(5, 1/2)\). The \(p\)-value calculation is \(\mathbb{P}(T \geq t)\). I.e.,

`pbinom(t-1, n, pstar, lower.tail=FALSE)`

`## [1] 0.5`

or using the library

`binom.test(t, n, pstar, alternative="greater")`

```
##
## Exact binomial test
##
## data: t and n
## number of successes = 3, number of trials = 5, p-value = 0.5
## alternative hypothesis: true probability of success is greater than 0.5
## 95 percent confidence interval:
## 0.1892554 1.0000000
## sample estimates:
## probability of success
## 0.6
```

- So there is not enough evidence to reject the null hypothesis, and we conclude that a person’s weight does not increase after they quit smoking.

In what was perhaps the first published report of a nonparametric test, Arbuthnott (1710) examined the available London birth records spanning 83 years and for each year compared the number of males born with the number of females born. If for each year we denote the event “more males than females were born” by “+” and the the opposite event by “-” (there were no ties), we may consider the hypotheses to be \(\mathcal{H}_0: \mathbb{P}(+) = \mathbb{P}(-)\) and \(\mathcal{H}_1: \mathbb{P}(+) \ne \mathbb{P}(-)\).

In fact, in every single year of the 82 years there were more boys born than girls. So we have

`t <- n <- 82`

Since clearly the observed number is greater than the null mean, we are again in exactly the same situation as above for the two-tailed \(p\)-value calculation. Cutting-and-pasting gives:

```
lhs <- seq(0, floor(pstar*n))
tL <- sum(dbinom(lhs, n, pstar) <= dbinom(t, n, pstar) * (1 + eps))
pbinom(tL - 1, n, pstar) + pbinom(t - 1, n, pstar, lower.tail=FALSE)
```

`## [1] 4.135903e-25`

`2 * pbinom(t-1, n, pstar, lower.tail=FALSE)`

`## [1] 4.135903e-25`

`binom.test(t, n, pstar)`

```
##
## Exact binomial test
##
## data: t and n
## number of successes = 82, number of trials = 82, p-value < 2.2e-16
## alternative hypothesis: true probability of success is not equal to 0.5
## 95 percent confidence interval:
## 0.9560105 1.0000000
## sample estimates:
## probability of success
## 1
```

- A resounding rejection of the null hypothesis for any (numerically distinguishable) value of \(\alpha\). We conclude that the sex ratios in London births are not equal: consistently, more boys are born each year than girls.