Estimating with uncertainty (Part 2)

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

Course Announcements

  • Please take the survey (link sent via announcement earlier today)
  • Reading Assignment for Monday - W&S, Chapter 5 (QUIZ)
  • Lab #3 videos and slides on QUBES!!!

Online Tutorials - Estimating with Uncertainty

Chalk talk - Sampling distributions and 95% confidence intervals

Error bars

How to do these in R?

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 ...

Error bars

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)

Error bars

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)

Error bars

Draw the strip chart and then add the error bars.

\[ \bar{Y} \pm SE_{\bar{Y}} \]

plot of chunk unnamed-chunk-3

Error bars can mean different things!!!

plot of chunk unnamed-chunk-4

Different error bars!!! \[ \bar{Y} \pm sd \\ \bar{Y} \pm SE_{\bar{Y}} \\ \bar{Y} \pm 2\times SE_{\bar{Y}} \]