Section 7.1 (continued)

Example 2: Matched Pairs t Procedure

The following commands correspond to the problems on the in-class handout.

Question 1

Part a)

Load the data:

moon<-read.file("/home/emesekennedy/Data/Ch7/mooneffect.txt")
## Reading data with read.table()

Part b)

Create a histogram, a boxplot, and a stemplot for the variable aggdiff:

histogram(~aggdiff, data=moon)

bwplot(~aggdiff, data=moon)

stem(moon$aggdiff)
## 
##   The decimal point is at the |
## 
##   -0 | 0
##    0 | 11
##    1 | 6
##    2 | 1347
##    3 | 11167
##    4 | 44

c) and d)

It appears that there are no extreme outliers and the data is not strongly skewed.

Question 2

Part a)

The null hypothesis is \(H_0=\mu=0\) and the alternative is \(H_a: \mu\ne0\).

Part b)

Find the mean \(\bar{x}\) and standard deviation \(s\) of the difference in behaviors for this the sample.

mean(~aggdiff, data=moon)
## [1] 2.432667
sd(~aggdiff, data=moon)
## [1] 1.46032

Part c)

Find the value of the t statistic:

2.43/(1.46/sqrt(15))
## [1] 6.44613

So \(t=6.45\)

Part d)

Find the P-value:

2*xpt(-6.45, df=14)

## [1] 1.522658e-05

So \(P=.000015\).

Part e)

The P-value is really small (less than .001), so we can reject the null hypothesis. This means that the data provides strong evidence at the .1% significance level to conclude that there is a difference in behaviors on moon days versus other days.

Question 3

Part a)

Find the standard error for \(\bar{x}\):

1.46/sqrt(15)
## [1] 0.3769704

Part b)

Find \(t^*\) for the 95% confidence interval:

xqt(.975, df=14)

## [1] 2.144787

So \(t^*=2.14\).

Part c)

Find the margin of error:

2.14*1.46/sqrt(15)
## [1] 0.8067166

Part d)

2.43+.81
## [1] 3.24
2.43-.81
## [1] 1.62

The 95% confidence interval for the mean difference in aggressive behaviors is \((1.62, 3.24)\).

We can use t.test to confirm our results:

t.test(~aggdiff, data=moon, mu=0, alternative="greater")
## 
##  One Sample t-test
## 
## data:  data$aggdiff
## t = 6.4518, df = 14, p-value = 7.591e-06
## alternative hypothesis: true mean is greater than 0
## 95 percent confidence interval:
##  1.768559      Inf
## sample estimates:
## mean of x 
##  2.432667

Note, to get the correct confidence interval we have to use the default two-sided alterative:

t.test(~aggdiff, data=moon, mu=0)
## 
##  One Sample t-test
## 
## data:  data$aggdiff
## t = 6.4518, df = 14, p-value = 1.518e-05
## alternative hypothesis: true mean is not equal to 0
## 95 percent confidence interval:
##  1.623968 3.241365
## sample estimates:
## mean of x 
##  2.432667