2024-03-17

Introduction

  • For a given data set flowers, one may conclude during exploratory analysis that there is some fundamental difference in height caused by nitrogen levels as shown by a bar graph below:
flower <- read.csv("flower.csv")
ggplot(data = flower, aes(x = nitrogen, y = height, fill = nitrogen)) + 
  geom_bar(stat = "summary", 
           fun = "mean", 
           width = 0.4) +
  labs(title = "Comparison of Average Height Values Versus Nitrogen Level",
       xlab = "Nitrogen Level", 
       ylab = "Average Height (cm)",
       fill = "Nitrogen Level")

  • However, it is inaccurate to state this definitively without further investigation. We can settle this matter definitively by performing an ANOVA on the data set.

What is ANOVA?

  • ANOVA, or Analysis of Variance, is a statistical method that is used to determine whether or not the average values of 3 or more groups are statistically significant compared to each other (in other words, do the data support the null hypothesis that the differences are not statistically significant?) [1].

  • In this test, the independent variable is discrete and is used to distinguish values of each group, while the values themselves (the dependent variable) may be continuous.

  • This deck will make use of the flower.csv data set to complete a one-way ANOVA and determine if there is a statistically significant difference in average height of flowers grown in soil with low, medium, or high nitrogen levels.

Assumptions

  1. Observations are random and independent [1]

  2. The data set is normally distributed [1]

  3. The variances of each group are equal [1]

Verifying Assumptions

Visualizing Distribution of the Height Values:

flower$nitrogen <- factor(flower$nitrogen, levels = c("low", "medium", "high"))

ggplot(data = flower, aes(sample = height, color = nitrogen)) + stat_qq() +
  stat_qq_line() +
  labs(title= "Quantile-Quantile Plot of Height Values", 
       x = "Theoretical Distribution",
       y = "Sample Distribution", 
       color = "Nitrogen Level")

  • The Quantile-Quantile Plot compares the actual quantiles to theoretical quantiles of a given data set. Since the values are largely close to the trend lines, let us assume that the data are normally distributed for this exercise [2].

Quantifying Distribution

shapiro.test(flower$height[flower$nitrogen =="low"])
## 
##  Shapiro-Wilk normality test
## 
## data:  flower$height[flower$nitrogen == "low"]
## W = 0.946, p-value = 0.1109
shapiro.test(flower$height[flower$nitrogen =="medium"])
## 
##  Shapiro-Wilk normality test
## 
## data:  flower$height[flower$nitrogen == "medium"]
## W = 0.9519, p-value = 0.1631
shapiro.test(flower$height[flower$nitrogen =="high"])
## 
##  Shapiro-Wilk normality test
## 
## data:  flower$height[flower$nitrogen == "high"]
## W = 0.97333, p-value = 0.5958
  • Normality can be confirmed using Shapiro-Wilk’s Test, which directly compares a set of data points to a normal distribution and quantifies how close they are to normal distribution via a p-value. P > 0.05 indicates that they are normally distributed, which is the case for all three groups [3].

Evaluating Variance

bartlett.test(height~nitrogen, data = flower)
## 
##  Bartlett test of homogeneity of variances
## 
## data:  height by nitrogen
## Bartlett's K-squared = 1.4345, df = 2, p-value = 0.4881

Bartlett’s test determines whether or not statistically significant differences exist between the variances of different groups [4]. Since P = 0.4881 > 0.05, the null hypothesis cannot be rejected and the variances have no statistically significant difference.

Mathematical Steps of ANOVA [5]

Calculating Group Means and Overall Mean

Given the data sets: low, medium, and high:

The group mean for each will be calculated as \(X_i = \frac{x_1+x_2+x_3,...+x_n}{n}\), and the overall mean will be calculated using the group means: \[\bar{X} = \frac{X_{low}+X_{medium} + X_{high}}{3} = \frac{5.85 + 7.01 + 7.65}{3} = 6.84\]

Calculating SSR and SSE

  • SSR: Sum of Squares Regression: \(n*\Sigma(X_{group} - \bar{X})^2\)

\[\text{SSR} = 32*[(5.85-6.84)^2+(7.01-6.84)^2+(7.65-6.84)^2] = 53.28\]

  • SSE: Sum of Squares Error: \(\Sigma(x-X_{group})^2\), with the final value being pooled from all groups. Computed in a similar manner, with the SSE of flower heights being: \(\text{SSE} = 247.9996875 + 279.995 + 376.1396875 = 904.134375\)

ANOVA Values

Source Sum of Squares Degrees of Freedom Mean Squares F-statistic
Regression 53.28 3-1=2 53.28/2 = 26.64 26.64/9.72 = 2.74
Error 904.13 96-3 = 93 904.13/93 = 9.72
  • Our obtained F-statistic is 2.77, and based on the Fisher table(next slide) we know that the F critical value is between 3.15 and 3.07. Since 2.77 < F critical, the null hypothesis cannot be rejected.

Fisher Table

Table was obtained from Statology.org [6]

Confirming our Results

oneway.test(height~nitrogen, data = flower, var.equal = T)
## 
##  One-way analysis of means
## 
## data:  height and nitrogen
## F = 2.74, num df = 2, denom df = 93, p-value = 0.06979
  • The null hypothesis is supported since the p-value is greater than 0.05. There is no proof that the differences between the averages are statistically significant.

Visualizing ANOVA

plot_ly(data = flower,
        x = flower$nitrogen,
        y = flower$height,
        type = "box",
        color = flower$nitrogen) %>% 
  layout(xaxis = list(title = "Nitrogen Level"), 
         yaxis = list(title = "Height (cm)"))
  • The Box Plot indicates that the spread of the “low” and “high” data points are fairly similar around their medial values. Furthermore, we can see that the range of the “low” and “medium” data points are fairly similar. All of this seems to indicate that there are no radical differences between the groups, which is confirmed by the ANOVA performed in the previous slides.

Citations

The data set used in this presentation was provided by Professor Sabiha Mahzabeen, ASU School of Mathematical and Statistical Sciences, Course: DAT 301.

  1. One-Way ANOVA Test in R - Easy Guides - Wiki - STHDA. (n.d.). http://www.sthda.com/english/wiki/one-way-anova-test-in-r

  2. Ford, C. 2015. “Understanding QQ Plots” UVA Library StatLab. https://library.virginia.edu/data/articles/understanding-robust-standard-errors/ (accessed February 1, 2023).

  3. King, A. P., & Eckersley, R. J. (2019). Inferential Statistics IV: choosing a hypothesis test. In Elsevier eBooks (pp. 147–171). https://doi.org/10.1016/b978-0-08-102939-8.00016-5

  4. Tim. (2023, May 18). Bartlett’s Test: Definition and Examples - Statistics How to. Statistics How To. https://www.statisticshowto.com/bartletts-test/

  5. Soetewey, A. (2023, August 30). How to: one-way ANOVA by hand. Stats and R. Retrieved March 17, 2024, from https://statsandr.com/blog/how-to-one-way-anova-by-hand/

  6. Zach. (2018, December 20). F Distribution Table. Statology. https://www.statology.org/f-distribution-table/