The following commands correspond to the problems on the in-class handout.
Load the data:
moon<-read.file("/home/emesekennedy/Data/Ch7/mooneffect.txt")
## Reading data with read.table()
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
It appears that there are no extreme outliers and the data is not strongly skewed.
The null hypothesis is \(H_0=\mu=0\) and the alternative is \(H_a: \mu\ne0\).
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
Find the value of the t statistic:
2.43/(1.46/sqrt(15))
## [1] 6.44613
So \(t=6.45\)
Find the P-value:
2*xpt(-6.45, df=14)
## [1] 1.522658e-05
So \(P=.000015\).
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.
Find the standard error for \(\bar{x}\):
1.46/sqrt(15)
## [1] 0.3769704
Find \(t^*\) for the 95% confidence interval:
xqt(.975, df=14)
## [1] 2.144787
So \(t^*=2.14\).
Find the margin of error:
2.14*1.46/sqrt(15)
## [1] 0.8067166
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