A an example of doing “inference by eye” using R.A. Fischer’s cat data. A good summary of this idea is Cummings et al. 2007. Error bars in experimental biology. http://jcb.rupress.org/content/177/1/7.short

Load the data

library(MASS)
data(cats)

Look at the data

dim(cats)
summary(cats)

Summarize the body weight (Bwt) data old-school using summaryBy()

A more modern way would be to use dplyr()

library(doBy)

#get the mean and SD
cat.df1 <- summaryBy(Bwt ~ Sex, data = cats, FUN = c(mean,sd))

#get the sample size using length()
cat.df2 <- summaryBy(Bwt ~ Sex, data = cats, FUN = c(length))

#make a combined dataframe
cat.df3 <- merge(cat.df1,cat.df2)

#calculate the standard error SE by hand

cat.df3$SE <- cat.df3$Bwt.sd/sqrt(cat.df3$Bwt.length)

Look at the results

cat.df3

Plot the data

Visualize the raw data

par(mfrow = c(1,1),mar = c(3,3.5,1,1))

boxplot(Bwt ~ Sex, data = cats)

Plot the means with error bars

This uses the errbar() function. A modern contemporary way would use ggplot2 and possibly its extension using ggpubr.

The real data

This is the actual data. The 95% confidence intervals do not overlap, which indicates that the p-value for the t-test will be less than 0.05.

library(Hmisc)
par(mfrow = c(1,2),mar = c(3,3.5,1,1))

y.lim <- c(2.295,3)
errbar(1:2,
       y = cat.df3$Bwt.mean,
       yplus =cat.df3$Bwt.mean + cat.df3$SE,
       yminus = cat.df3$Bwt.mean-cat.df3$SE,
       xlab = "",
       ylab = "",
       xlim=c(0.5,2.5),
       ylim = y.lim,
       xaxt="n",cex =1)
axis(side=1,at=1:2,labels=cat.df3$Sex)
mtext("Sex", side = 1, line = 2, cex = 2)
mtext("Mass (g)", side = 2, line = 2.1, cex = 1.3)

errbar(1:2,
       y = cat.df3$Bwt.mean,
       yplus =cat.df3$Bwt.mean + 1.96*cat.df3$SE,
       yminus = cat.df3$Bwt.mean-1.96*cat.df3$SE,
       xlab = "",
       ylab = "",
       xlim=c(0.5,2.5),
       ylim = y.lim,
       xaxt="n",cex =1)
axis(side=1,at=1:2,labels=cat.df3$Sex)
mtext("Sex", side = 1, line = 2, cex = 2)
mtext("Mass (g)", side = 2, line = 2.1, cex = 1.3)

Modified data with a non-significant different

Make an alternative version of the data where there isn’t a difference between the male and female cats

cat.df3.mod <- cat.df3
cat.df3.mod$Bwt.mean[1] <- cat.df3$Bwt.mean[2]-cat.df3$Bwt.mean[2]*0.0425

The overlap of the error bars here is greater than 1/2 the length of the bar; therefore the p-value for a t-test will be > 0.05.

y.lim <- c(2.6975,3)
par(mar = c(3,3.5,1,1))
errbar(1:2,
       y = cat.df3.mod$Bwt.mean,
       yplus =cat.df3.mod$Bwt.mean + cat.df3.mod$SE,
       yminus = cat.df3.mod$Bwt.mean-cat.df3.mod$SE,
       xlab = "",
       ylab = "",
       xlim=c(0.5,2.5),
       ylim = y.lim,
       xaxt="n",cex =1)
axis(side=1,at=1:2,labels=cat.df3.mod$Sex)
mtext("Sex", side = 1, line = 2, cex = 2)
mtext("Mass (g)", side = 2, line = 2.1, cex = 1.3)

errbar(1:2,
       y = cat.df3.mod$Bwt.mean,
       yplus =cat.df3.mod$Bwt.mean + 1.96*cat.df3.mod$SE,
       yminus = cat.df3.mod$Bwt.mean-1.96*cat.df3.mod$SE,
       xlab = "",
       ylab = "",
       xlim=c(0.5,2.5),
       ylim = y.lim,
       xaxt="n",cex =1)
axis(side=1,at=1:2,labels=cat.df3.mod$Sex)
mtext("Sex", side = 1, line = 2, cex = 2)
mtext("Mass (g)", side = 2, line = 2.1, cex = 1.3)

T-test

A t-test for the differenec between female and male cats.

t.test(Bwt ~ Sex, data = cats)
summary(lm(Bwt ~ -1+Sex, data = cats))