M. Drew LaMar
February 3, 2017
“Absolute certainty is a privilege of uneducated minds and fanatics. It is, for scientific folk, an unattainable ideal.”
- Cassius J. Keyser
Read and inspect the data.
locustData <- read.csv("/Users/mdlama/Dropbox/Work/Teaching/College of William and Mary/Spring 2017/Datasets/chapter02/chap02f1_2locustSerotonin.csv")
head(locustData)
serotoninLevel treatmentTime
1 5.3 0
2 4.6 0
3 4.5 0
4 4.3 0
5 4.2 0
6 3.6 0
str(locustData)
'data.frame': 30 obs. of 2 variables:
$ serotoninLevel: num 5.3 4.6 4.5 4.3 4.2 3.6 3.7 3.3 12.1 18 ...
$ treatmentTime : int 0 0 0 0 0 0 0 0 0 0 ...
First, calculate the statistics by group needed for the error bars: the mean and standard error. Here, tapply
is used to obtain each quantity by treatment group.
meanSerotonin <- tapply(locustData$serotoninLevel,
locustData$treatmentTime,
mean)
sdSerotonin <- tapply(locustData$serotoninLevel,
locustData$treatmentTime,
sd)
nSerotonin <- tapply(locustData$serotoninLevel,
locustData$treatmentTime,
length)
seSerotonin <- sdSerotonin / sqrt(nSerotonin)
Draw the strip chart and then add the error bars.
\[ \bar{Y} \pm SE_{\bar{Y}} \]
offsetAmount <- 0.2
stripchart(serotoninLevel ~ treatmentTime,
data = locustData,
method = "jitter",
vertical = TRUE)
segments(1:3 + offsetAmount,
meanSerotonin - seSerotonin,
1:3 + offsetAmount,
meanSerotonin + seSerotonin)
points(meanSerotonin ~ c(c(1,2,3) + offsetAmount),
pch = 16,
cex = 1.2)
Draw the strip chart and then add the error bars.
\[ \bar{Y} \pm SE_{\bar{Y}} \]
Different error bars!!! \[ \bar{Y} \pm sd \\ \bar{Y} \pm SE_{\bar{Y}} \\ \bar{Y} \pm 2\times SE_{\bar{Y}} \]