Back to Homepage

Differences between two independent samples

Tutorial objectives

The objectives of this tutorial are to:

  • Learn what difference tests measure
  • Revisit important statistical terms
    • p values
    • effect sizes
  • Continue to build proficiency with creating (and interpreting) data visualizations
    • density plots
    • box plots
    • violin plots (new to this tutorial)
  • Learn the assumptions of an independent samples t-test
  • Learn how to test the assumptions of an independent samples t-test
  • Learn how to interpret the output of an independent samples t-test (p values)
  • Learn how to calculate and interpret the effect size for an independent samples t-test
  • Learn how to determine whether differences exist between two independent groups when some of the assumptions of an independent t-test are not met.

Measuring differences between two independent samples (t-test, Wilcoxon test)

In research, we often want to know whether groups differ with regard to a particular characteristic. For example, in Tutorial 2 we looked at how particular classes of vehicles differed with regard to highway fuel efficiency. In the dataset that is visualized below, we can see (for example) that there doesn’t seem to be much of a difference in highway fuel efficiency between compact and midsize vehicles. There does, however, seem to be a reasonably large difference in highway fuel efficiency between midsize vehicles and pickups.

library(ggplot2) #import ggplot2
## Warning: replacing previous import 'lifecycle::last_warnings' by
## 'rlang::last_warnings' when loading 'pillar'
library(viridis) #color-friendly palettes
## Loading required package: viridisLite
g1 <- ggplot(data = mpg) + # create plot using the mpg data frame
  geom_boxplot(mapping = aes(x = class, y = hwy, fill=class)) + #create boxplots for each vehicle class based on highway fuel efficiency
  scale_fill_viridis(discrete = TRUE)

#print(g1)