An investigator believes that caffeine facilitates performance on a simple spelling test. Two groups of subjects are given either 200 mg of caffeine or a placebo. The data are:
Placebo Drug 24 24 25 29 27 26 26 23 26 25 22 28 21 27 22 24 23 27 25 28 25 27 25 26
To describe the differences between these two groups, we can use basic descriptive statistics (means and standard deviations), and graph the results. To see how likely a difference of this magnitude would happen by chance if, in fact, the two groups were sampled from the same population, we can do a t-test.
The next few lines show how this is done in R.
source("http://personality-project.org/r/useful.r") #load in some useful additions to R
#now, copy the data into the clipboard and then read it into R
experiment.1 <- read.clipboard() #a very short function, tested on Macs, believed to work on PCs
experiment.1 #show the data, to make sure we got it
attach(experiment.1) #allows us to use the names of the items with experiment.1
summary(experiment.1) #basic descriptive statistics
#now some simple descriptive graphics
boxplot(experiment.1,main="Effect of Caffeine on a spelling test",ylab="Spelling Performance") #show some basic descriptive graphics
stripchart(experiment.1,method="jitter",jitter=.05,vertical=T,add=T) #show the raw data as well added to the boxplot
multi.hist(experiment.1) #show the histograms if we want
test <- t.test(placebo,drug,equal.var=TRUE) #the t-test
The code above produces this output:
> source("http://personality-project.org/r/useful.r") #load in some useful additions to R
> #now, copy the data into the clipboard and then read it into R
> experiment.1 <- read.clipboard() #a very short function, tested on Macs, believed to work on PCs
>
> experiment.1 #show the data, to make sure we got it
Placebo Drug
1 24 24
2 25 29
3 27 26
4 26 23
5 26 25
6 22 28
7 21 27
8 22 24
9 23 27
10 25 28
11 25 27
12 25 26
>
> attach(experiment.1) #allows us to use the names of the items with experiment.1
>
> summary(experiment.1) #basic descriptive statistics
Placebo Drug
Min. :21.00 Min. :23.00
1st Qu.:22.75 1st Qu.:24.75
Median :25.00 Median :26.50
Mean :24.25 Mean :26.17
3rd Qu.:25.25 3rd Qu.:27.25
Max. :27.00 Max. :29.00
>
> #now some simple descriptive graphics
> boxplot(experiment.1,main="Effect of Caffeine on a spelling test",ylab="Spelling Performance") #show some basic descriptive graphics
> stripchart(experiment.1,method="jitter",jitter=.05,vertical=T,add=T) #show the raw data as well added to the boxplot
>
> multi.hist(experiment.1) #show the histograms if we want
> test <- t.test(placebo,drug,equal.var=TRUE) #the t-test
> test
Welch Two Sample t-test
data: placebo and drug
t = -2.5273, df = 21.999, p-value = 0.01918
alternative hypothesis: true difference in means is not equal to 0
95 percent confidence interval:
-3.4894368 -0.3438965
sample estimates:
mean of x mean of y
24.25000 26.16667
and produces the following two graphs: