One-Way ANOVA with R
Welcome to our hands-on tutorial on performing one-way ANOVA (Analysis of Variance) with R. In this guide, we'll walk through a practical example analyzing how customer engagement varies across three marketing channels: TV, Social Media, and Print advertising. New to ANOVA? Start with our comprehensive ANOVA guide for a solid theoretical foundation before diving into the implementation.
Sample Data and Assumptions
Note on Assumptions:
For this tutorial, we assume the following ANOVA assumptions are satisfied:
- The observations are independent
- The data within each group is normally distributed
- The groups have homogeneous variances
Dataset:
1Channel, Customer Engagement
2TV, 85
3TV, 90
4TV, 88
5TV, 84
6TV, 87
7Social Media, 88
8Social Media, 92
9Social Media, 89
10Social Media, 85
11Social Media, 91
12Print, 78
13Print, 80
14Print, 82
15Print, 79
16Print, 81
Try it yourself:
Want to analyze this data without coding? Copy the data above and paste it into our One-Way ANOVA Calculator to get instant results.
Implementation with R
R Implementation:
1# Load required packages
2library(tidyverse)
3library(effectsize)
4
5# Step 1: Create the dataset
6data <- tibble(
7 Channel = rep(c("TV", "Social Media", "Print"), each = 5),
8 Customer_Engagement = c(85, 90, 88, 84, 87, # TV
9 88, 92, 89, 85, 91, # Social Media
10 78, 80, 82, 79, 81) # Print
11)
12
13# Step 2: Calculate descriptive statistics
14desc_stats <- data %>%
15 group_by(Channel) %>%
16 summarise(
17 mean = mean(Customer_Engagement),
18 std = sd(Customer_Engagement),
19 n = n(),
20 )
21
22print("Descriptive Statistics:")
23print(desc_stats)
24
25# Step 3: Perform one-way ANOVA
26anova_model <- aov(Customer_Engagement ~ Channel, data = data)
27anova_results <- summary(anova_model)
28
29print("One-way ANOVA Results:")
30print(anova_results)
31
32# Step 4: Calculate Effect Size (Eta-squared)
33eta_squared <- eta_squared(anova_model)
34print("Effect Size:")
35print(eta_squared)
Results:
Descriptive Statistics:
Channel | Mean | Std | N |
---|---|---|---|
80.0 | 1.58 | 5 | |
Social Media | 89.0 | 2.74 | 5 |
TV | 86.8 | 2.39 | 5 |
F-statistic: F(2, 12) = 21.0318
p-value: p = 0.0001
Effect Size: η² = 0.7780
Interpreting the Results:
The one-way ANOVA results show a significant difference in customer engagement across the three marketing channels (TV, Social Media, Print). The F-statistic of 21.0318 and p-value of 0.0001 indicate that the mean customer engagement levels are not equal across the groups. The effect size (η²) of 0.778 suggests that 77.8% of the variance in customer engagement can be explained by the marketing channel.
Post-hoc Analysis:
Conducting post-hoc tests such as Tukey HSD, Bonferroni, Scheffe's test, or Fisher's LSD can help identify which specific groups differ significantly from each other. This is important when the ANOVA results are significant. You can use our Tukey HSD calculator to perform this analysis.
Help us improve
Found an error or have a suggestion? Let us know!