ANOVA

We collect data from 26 students in our math class: the student’s major, favorite flavor, and score on a diagnostic math test. We want to know if this data provides statistically significant evidence that a student’s major and/or favorite flavor has a predictive effect on how such a student will, on average, score on that diagnostic math test.

The following short tutorial PDF explains how to do a two-way ANOVA using the statistics package R and how to report your results.

The tutorial requires the following .csv data file (containing the data on the 26 students). You can open this file in any spreadsheet (e.g., Microsoft Excel) or text editor.

The tutorial requires the following R script called ANOVASoTL. It is a .txt file. You can open it in R (or any text editor).

You can download the statistics package R for free from:
https://www.r-project.org

OPTIONAL MATERIAL
You can also run R scripts online. Here is how…

 Rextester has an online R compiler. You can use to run R scripts online. The only problem is you can’t export your data to online R compilers (in an easy way). So, the online R compilers are of limited use for data analysis. Also they run slow and they do not have good debugging routines.

However, if you’d like to run the ANOVA R script online, I’ve created a version of that script that contains the data inside the script itself (below, in gray). No need for data export.

Below (in gray) is a version of the R script for the ANOVA that includes the data inside the script itself. The benefit of including the data in the script itself is that this allows you to just copy and paste the script (with the data) into an online R compiler like Rextester and run it. You don’t have to worry about importing the data.

Unfortunately, it is not easy to import data into the online R compilers. So if you want to use R to analyze your data, you will need to install R on your computer. You can download R for free from: https://www.r-project

# ANOVASoTL.R with Step 1 modified for use with online R compilers
# ANOVA for SoTL
# ------------------------------------------------------
# Data (Step 1)
studentData =
structure(list(Major = structure(c(1L, 1L, 2L, 1L, 1L, 1L, 1L,
2L, 2L, 1L, 1L, 1L, 1L, 2L, 2L, 2L, 1L, 3L, 3L, 3L, 3L, 3L, 3L,
3L, 3L, 3L), .Label = c("Business", "LiberalArts", "STEM"), class = "factor"),
Flavor = structure(c(2L, 1L, 1L, 2L, 2L, 1L, 2L, 2L, 2L,
2L, 2L, 2L, 1L, 2L, 2L, 2L, 2L, 2L, 2L, 1L, 1L, 2L, 1L, 1L,
1L, 1L), .Label = c("chocolate", "vanilla"), class = "factor"),
Test = c(77, 77.3, 75.7, 81.7, 79.7, 77.7, 82.6, 80.6, 73.9,
76.5, 78.8, 82.5, 76.5, 78.3, 78.3, 85.2, 76.3, 81.6, 83.9,
77.8, 89.3, 85.3, 91.5, 90.2, 93, 91.1)), class = "data.frame", row.names = c(NA,
-26L));
df = studentData;
"Student Data";
df;
# ------------------------------------------------------
# Boxplots of Data (Step 2)
boxplot(df$Test ~ df$Major,col = "cyan",
main = "Boxplots of students' test scores by major.");
boxplot(df$Test ~ df$Flavor,col = c("brown", "yellow"),
main = "Boxplots of students' test scores by favorite flavor.");
boxplot(df$Test ~ df$Flavor*df$Major,col = "green",
main = "Boxplots of students' test scores by major x favorite flavor.");
# ------------------------------------------------------
# Perform the ANOVA (Step 3)
dfANOVA <- aov(Test ~ Major * Flavor, data = df);
" ";
summary(dfANOVA);
# you should see the ANOVA table in the R console.
# -------------------------------------------------------
# Make a table with means and standard deviations sd (Step 4)
# for main effects
agMajor = aggregate(Test~Major, df, function(x) c(mean = mean(x), sd = sd(x),n = length(x)));
" ";
agMajor;
agFlavor = aggregate(Test~Flavor, df, function(x) c(mean = mean(x), sd = sd(x), n = length(x)));
" ";
agFlavor ;
# for interaction effects
agMajorFlavor = aggregate(Test~Major*Flavor, df, function(x) c(mean = mean(x), sd = sd(x),n = length(x)));
" ";
agMajorFlavor;
# -------------------------------------------------------
# End of script

The above R code can be run in: https://rextester.com/l/r_online_compiler
by copy and pasting.