CoCalc Public FilesANOVA Practice Problem / ANOVA Practice Script-Arin.ipynbOpen with one click!
Author: Akbar Maulana
Views : 65
License: GNU General Public License v3.0
Compute Environment: Ubuntu 18.04 (Deprecated)
In [1]:
library(xlsx) # library to import excel spreadsheets as data to analyze
Warning message: “package ‘xlsx’ was built under R version 3.6.3”
In [ ]:
In [7]:
# Importing the dataset df.data <- read.xlsx("ANOVA Practice Data File.xlsx", sheetName = 1)
In [ ]:
In [10]:
# Checking whether the data frame imported correctly df.data
A data.frame: 18 × 4
IDExperience.LevelBlurriness.LevelThroughput
<dbl><fct><fct><dbl>
1No Experience Not Blurred 1.314
2No Experience Not Blurred 1.219
3Moderate Experience Not Blurred 4.413
4Moderate Experience Not Blurred 4.612
5Extensive ExperienceNot Blurred 4.752
6Extensive ExperienceNot Blurred 4.432
7No Experience Moderately Blurred 1.114
8No Experience Moderately Blurred 1.119
9Moderate Experience Moderately Blurred 2.113
10Moderate Experience Moderately Blurred 2.235
11Extensive ExperienceModerately Blurred 4.443
12Extensive ExperienceModerately Blurred 4.512
13No Experience Extensively Blurred0.295
14No Experience Extensively Blurred0.113
15Moderate Experience Extensively Blurred0.443
16Moderate Experience Extensively Blurred0.452
17Extensive ExperienceExtensively Blurred2.113
18Extensive ExperienceExtensively Blurred2.211
In [6]:
# Checking the import results.'data.frame': 18 obs. of 4 variables: str(df.data)
'data.frame': 18 obs. of 4 variables: $ ID : num 1 2 3 4 5 6 7 8 9 10 ... $ Experience.Level: Factor w/ 3 levels "Extensive Experience",..: 3 3 2 2 1 1 3 3 2 2 ... $ Blurriness.Level: Factor w/ 3 levels "Extensively Blurred",..: 3 3 3 3 3 3 2 2 2 2 ... $ Throughput : Factor w/ 17 levels "0.113","0.295",..: 8 7 12 16 17 13 5 6 9 11 ...
In [9]:
# Throughput was recorded as a factor variable; In reality, it should be a numeric variable. # Hence, its data type needs to be changed to reflect this fact. df.data$Throughput <- as.numeric(as.character (df.data$Throughput))
In [ ]:
In [11]:
# Import the ggplot2 library to create graphs library(ggplot2)
Warning message: “package ‘ggplot2’ was built under R version 3.6.3”
In [12]:
# Plot the difference of means between experience levels ggplot(df.data, aes(x = Experience.Level, y = Throughput)) + geom_point()
In [13]:
# Plot the difference of means between experience levels ggplot(df.data, aes(x = Blurriness.Level, y = Throughput)) + geom_point()
In [ ]:
In [16]:
# First ANOVA, testing all factors and all interaction effects # There are three hypotheses we wish to test. # 1. Does experience affect one's annotation throughput? # 2. Does blurriness of the image being annotated affect one's annotation throughput? # 3. Does one's experience mitigate the effect of blurriness (i.e. are skilled annotators less slowed down by blurriness?) result <- aov(Throughput ~ Experience.Level + Blurriness.Level + Experience.Level*Blurriness.Level, data = df.data)
In [18]:
result2 <- aov(Throughput ~ Experience.Level + Blurriness.Level + Experience.Level*Blurriness.Level, data = df.data)
In [ ]:
In [15]:
# Check the results. What do you see? summary(result)
Df Sum Sq Mean Sq F value Pr(>F) Experience.Level 2 24.932 12.466 1051.0 2.16e-11 *** Blurriness.Level 2 19.653 9.826 828.4 6.26e-11 *** Experience.Level:Blurriness.Level 4 5.838 1.460 123.1 7.55e-08 *** Residuals 9 0.107 0.012 --- Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
In [19]:
# Check the results for the new ANOVA. What do you see? summary(result2)
Df Sum Sq Mean Sq F value Pr(>F) Experience.Level 2 24.932 12.466 1051.0 2.16e-11 *** Blurriness.Level 2 19.653 9.826 828.4 6.26e-11 *** Experience.Level:Blurriness.Level 4 5.838 1.460 123.1 7.55e-08 *** Residuals 9 0.107 0.012 --- Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
In [20]:
# Remember that ANOVA by itself doesn't give information about which classes have higher or lower means # To gain that information, an additional test (Tukey's ) TukeyHSD(result2)
Tukey multiple comparisons of means 95% family-wise confidence level Fit: aov(formula = Throughput ~ Experience.Level + Blurriness.Level + Experience.Level * Blurriness.Level, data = df.data) $Experience.Level diff lwr upr p adj Moderate Experience-Extensive Experience -1.365833 -1.541392 -1.190274 0 No Experience-Extensive Experience -2.881500 -3.057059 -2.705941 0 No Experience-Moderate Experience -1.515667 -1.691226 -1.340108 0 $Blurriness.Level diff lwr upr p adj Moderately Blurred-Extensively Blurred 1.6515000 1.4759409 1.827059 0e+00 Not Blurred-Extensively Blurred 2.5191667 2.3436075 2.694726 0e+00 Not Blurred-Moderately Blurred 0.8676667 0.6921075 1.043226 6e-07 $`Experience.Level:Blurriness.Level` diff Moderate Experience:Extensively Blurred-Extensive Experience:Extensively Blurred -1.7145 No Experience:Extensively Blurred-Extensive Experience:Extensively Blurred -1.9580 Extensive Experience:Moderately Blurred-Extensive Experience:Extensively Blurred 2.3155 Moderate Experience:Moderately Blurred-Extensive Experience:Extensively Blurred 0.0120 No Experience:Moderately Blurred-Extensive Experience:Extensively Blurred -1.0455 Extensive Experience:Not Blurred-Extensive Experience:Extensively Blurred 2.4300 Moderate Experience:Not Blurred-Extensive Experience:Extensively Blurred 2.3505 No Experience:Not Blurred-Extensive Experience:Extensively Blurred -0.8955 No Experience:Extensively Blurred-Moderate Experience:Extensively Blurred -0.2435 Extensive Experience:Moderately Blurred-Moderate Experience:Extensively Blurred 4.0300 Moderate Experience:Moderately Blurred-Moderate Experience:Extensively Blurred 1.7265 No Experience:Moderately Blurred-Moderate Experience:Extensively Blurred 0.6690 Extensive Experience:Not Blurred-Moderate Experience:Extensively Blurred 4.1445 Moderate Experience:Not Blurred-Moderate Experience:Extensively Blurred 4.0650 No Experience:Not Blurred-Moderate Experience:Extensively Blurred 0.8190 Extensive Experience:Moderately Blurred-No Experience:Extensively Blurred 4.2735 Moderate Experience:Moderately Blurred-No Experience:Extensively Blurred 1.9700 No Experience:Moderately Blurred-No Experience:Extensively Blurred 0.9125 Extensive Experience:Not Blurred-No Experience:Extensively Blurred 4.3880 Moderate Experience:Not Blurred-No Experience:Extensively Blurred 4.3085 No Experience:Not Blurred-No Experience:Extensively Blurred 1.0625 Moderate Experience:Moderately Blurred-Extensive Experience:Moderately Blurred -2.3035 No Experience:Moderately Blurred-Extensive Experience:Moderately Blurred -3.3610 Extensive Experience:Not Blurred-Extensive Experience:Moderately Blurred 0.1145 Moderate Experience:Not Blurred-Extensive Experience:Moderately Blurred 0.0350 No Experience:Not Blurred-Extensive Experience:Moderately Blurred -3.2110 No Experience:Moderately Blurred-Moderate Experience:Moderately Blurred -1.0575 Extensive Experience:Not Blurred-Moderate Experience:Moderately Blurred 2.4180 Moderate Experience:Not Blurred-Moderate Experience:Moderately Blurred 2.3385 No Experience:Not Blurred-Moderate Experience:Moderately Blurred -0.9075 Extensive Experience:Not Blurred-No Experience:Moderately Blurred 3.4755 Moderate Experience:Not Blurred-No Experience:Moderately Blurred 3.3960 No Experience:Not Blurred-No Experience:Moderately Blurred 0.1500 Moderate Experience:Not Blurred-Extensive Experience:Not Blurred -0.0795 No Experience:Not Blurred-Extensive Experience:Not Blurred -3.3255 No Experience:Not Blurred-Moderate Experience:Not Blurred -3.2460 lwr Moderate Experience:Extensively Blurred-Extensive Experience:Extensively Blurred -2.1453544 No Experience:Extensively Blurred-Extensive Experience:Extensively Blurred -2.3888544 Extensive Experience:Moderately Blurred-Extensive Experience:Extensively Blurred 1.8846456 Moderate Experience:Moderately Blurred-Extensive Experience:Extensively Blurred -0.4188544 No Experience:Moderately Blurred-Extensive Experience:Extensively Blurred -1.4763544 Extensive Experience:Not Blurred-Extensive Experience:Extensively Blurred 1.9991456 Moderate Experience:Not Blurred-Extensive Experience:Extensively Blurred 1.9196456 No Experience:Not Blurred-Extensive Experience:Extensively Blurred -1.3263544 No Experience:Extensively Blurred-Moderate Experience:Extensively Blurred -0.6743544 Extensive Experience:Moderately Blurred-Moderate Experience:Extensively Blurred 3.5991456 Moderate Experience:Moderately Blurred-Moderate Experience:Extensively Blurred 1.2956456 No Experience:Moderately Blurred-Moderate Experience:Extensively Blurred 0.2381456 Extensive Experience:Not Blurred-Moderate Experience:Extensively Blurred 3.7136456 Moderate Experience:Not Blurred-Moderate Experience:Extensively Blurred 3.6341456 No Experience:Not Blurred-Moderate Experience:Extensively Blurred 0.3881456 Extensive Experience:Moderately Blurred-No Experience:Extensively Blurred 3.8426456 Moderate Experience:Moderately Blurred-No Experience:Extensively Blurred 1.5391456 No Experience:Moderately Blurred-No Experience:Extensively Blurred 0.4816456 Extensive Experience:Not Blurred-No Experience:Extensively Blurred 3.9571456 Moderate Experience:Not Blurred-No Experience:Extensively Blurred 3.8776456 No Experience:Not Blurred-No Experience:Extensively Blurred 0.6316456 Moderate Experience:Moderately Blurred-Extensive Experience:Moderately Blurred -2.7343544 No Experience:Moderately Blurred-Extensive Experience:Moderately Blurred -3.7918544 Extensive Experience:Not Blurred-Extensive Experience:Moderately Blurred -0.3163544 Moderate Experience:Not Blurred-Extensive Experience:Moderately Blurred -0.3958544 No Experience:Not Blurred-Extensive Experience:Moderately Blurred -3.6418544 No Experience:Moderately Blurred-Moderate Experience:Moderately Blurred -1.4883544 Extensive Experience:Not Blurred-Moderate Experience:Moderately Blurred 1.9871456 Moderate Experience:Not Blurred-Moderate Experience:Moderately Blurred 1.9076456 No Experience:Not Blurred-Moderate Experience:Moderately Blurred -1.3383544 Extensive Experience:Not Blurred-No Experience:Moderately Blurred 3.0446456 Moderate Experience:Not Blurred-No Experience:Moderately Blurred 2.9651456 No Experience:Not Blurred-No Experience:Moderately Blurred -0.2808544 Moderate Experience:Not Blurred-Extensive Experience:Not Blurred -0.5103544 No Experience:Not Blurred-Extensive Experience:Not Blurred -3.7563544 No Experience:Not Blurred-Moderate Experience:Not Blurred -3.6768544 upr Moderate Experience:Extensively Blurred-Extensive Experience:Extensively Blurred -1.2836456 No Experience:Extensively Blurred-Extensive Experience:Extensively Blurred -1.5271456 Extensive Experience:Moderately Blurred-Extensive Experience:Extensively Blurred 2.7463544 Moderate Experience:Moderately Blurred-Extensive Experience:Extensively Blurred 0.4428544 No Experience:Moderately Blurred-Extensive Experience:Extensively Blurred -0.6146456 Extensive Experience:Not Blurred-Extensive Experience:Extensively Blurred 2.8608544 Moderate Experience:Not Blurred-Extensive Experience:Extensively Blurred 2.7813544 No Experience:Not Blurred-Extensive Experience:Extensively Blurred -0.4646456 No Experience:Extensively Blurred-Moderate Experience:Extensively Blurred 0.1873544 Extensive Experience:Moderately Blurred-Moderate Experience:Extensively Blurred 4.4608544 Moderate Experience:Moderately Blurred-Moderate Experience:Extensively Blurred 2.1573544 No Experience:Moderately Blurred-Moderate Experience:Extensively Blurred 1.0998544 Extensive Experience:Not Blurred-Moderate Experience:Extensively Blurred 4.5753544 Moderate Experience:Not Blurred-Moderate Experience:Extensively Blurred 4.4958544 No Experience:Not Blurred-Moderate Experience:Extensively Blurred 1.2498544 Extensive Experience:Moderately Blurred-No Experience:Extensively Blurred 4.7043544 Moderate Experience:Moderately Blurred-No Experience:Extensively Blurred 2.4008544 No Experience:Moderately Blurred-No Experience:Extensively Blurred 1.3433544 Extensive Experience:Not Blurred-No Experience:Extensively Blurred 4.8188544 Moderate Experience:Not Blurred-No Experience:Extensively Blurred 4.7393544 No Experience:Not Blurred-No Experience:Extensively Blurred 1.4933544 Moderate Experience:Moderately Blurred-Extensive Experience:Moderately Blurred -1.8726456 No Experience:Moderately Blurred-Extensive Experience:Moderately Blurred -2.9301456 Extensive Experience:Not Blurred-Extensive Experience:Moderately Blurred 0.5453544 Moderate Experience:Not Blurred-Extensive Experience:Moderately Blurred 0.4658544 No Experience:Not Blurred-Extensive Experience:Moderately Blurred -2.7801456 No Experience:Moderately Blurred-Moderate Experience:Moderately Blurred -0.6266456 Extensive Experience:Not Blurred-Moderate Experience:Moderately Blurred 2.8488544 Moderate Experience:Not Blurred-Moderate Experience:Moderately Blurred 2.7693544 No Experience:Not Blurred-Moderate Experience:Moderately Blurred -0.4766456 Extensive Experience:Not Blurred-No Experience:Moderately Blurred 3.9063544 Moderate Experience:Not Blurred-No Experience:Moderately Blurred 3.8268544 No Experience:Not Blurred-No Experience:Moderately Blurred 0.5808544 Moderate Experience:Not Blurred-Extensive Experience:Not Blurred 0.3513544 No Experience:Not Blurred-Extensive Experience:Not Blurred -2.8946456 No Experience:Not Blurred-Moderate Experience:Not Blurred -2.8151456 p adj Moderate Experience:Extensively Blurred-Extensive Experience:Extensively Blurred 0.0000016 No Experience:Extensively Blurred-Extensive Experience:Extensively Blurred 0.0000005 Extensive Experience:Moderately Blurred-Extensive Experience:Extensively Blurred 0.0000001 Moderate Experience:Moderately Blurred-Extensive Experience:Extensively Blurred 1.0000000 No Experience:Moderately Blurred-Extensive Experience:Extensively Blurred 0.0001005 Extensive Experience:Not Blurred-Extensive Experience:Extensively Blurred 0.0000001 Moderate Experience:Not Blurred-Extensive Experience:Extensively Blurred 0.0000001 No Experience:Not Blurred-Extensive Experience:Extensively Blurred 0.0003473 No Experience:Extensively Blurred-Moderate Experience:Extensively Blurred 0.4557486 Extensive Experience:Moderately Blurred-Moderate Experience:Extensively Blurred 0.0000000 Moderate Experience:Moderately Blurred-Moderate Experience:Extensively Blurred 0.0000015 No Experience:Moderately Blurred-Moderate Experience:Extensively Blurred 0.0031144 Extensive Experience:Not Blurred-Moderate Experience:Extensively Blurred 0.0000000 Moderate Experience:Not Blurred-Moderate Experience:Extensively Blurred 0.0000000 No Experience:Not Blurred-Moderate Experience:Extensively Blurred 0.0006952 Extensive Experience:Moderately Blurred-No Experience:Extensively Blurred 0.0000000 Moderate Experience:Moderately Blurred-No Experience:Extensively Blurred 0.0000005 No Experience:Moderately Blurred-No Experience:Extensively Blurred 0.0002994 Extensive Experience:Not Blurred-No Experience:Extensively Blurred 0.0000000 Moderate Experience:Not Blurred-No Experience:Extensively Blurred 0.0000000 No Experience:Not Blurred-No Experience:Extensively Blurred 0.0000881 Moderate Experience:Moderately Blurred-Extensive Experience:Moderately Blurred 0.0000001 No Experience:Moderately Blurred-Extensive Experience:Moderately Blurred 0.0000000 Extensive Experience:Not Blurred-Extensive Experience:Moderately Blurred 0.9686083 Moderate Experience:Not Blurred-Extensive Experience:Moderately Blurred 0.9999912 No Experience:Not Blurred-Extensive Experience:Moderately Blurred 0.0000000 No Experience:Moderately Blurred-Moderate Experience:Moderately Blurred 0.0000915 Extensive Experience:Not Blurred-Moderate Experience:Moderately Blurred 0.0000001 Moderate Experience:Not Blurred-Moderate Experience:Moderately Blurred 0.0000001 No Experience:Not Blurred-Moderate Experience:Moderately Blurred 0.0003127 Extensive Experience:Not Blurred-No Experience:Moderately Blurred 0.0000000 Moderate Experience:Not Blurred-No Experience:Moderately Blurred 0.0000000 No Experience:Not Blurred-No Experience:Moderately Blurred 0.8815911 Moderate Experience:Not Blurred-Extensive Experience:Not Blurred 0.9965769 No Experience:Not Blurred-Extensive Experience:Not Blurred 0.0000000 No Experience:Not Blurred-Moderate Experience:Not Blurred 0.0000000
In [21]:
# Extracting residuals from the ANOVA results df.data$residuals2 <- result2$residuals
In [22]:
# Performing a normality test on the residuals shapiro.test(df.data$residuals2)
Shapiro-Wilk normality test data: df.data$residuals2 W = 0.99231, p-value = 0.9998
In [24]:
# Performing a homoscedasticity test on the residuals for blurriness level library(car) leveneTest(residuals2 ~ Experience.Level, data = df.data)
Warning message: “package ‘car’ was built under R version 3.6.3”Loading required package: carData
A anova: 2 × 3
DfF valuePr(>F)
<int><dbl><dbl>
group 20.80236090.4666029
15 NA NA
In [25]:
#Performing a homoscedasticity test on the residuals for blurriness level leveneTest(residuals2 ~ Blurriness.Level, data = df.data)
A anova: 2 × 3
DfF valuePr(>F)
<int><dbl><dbl>
group 25.1030150.02038925
15 NA NA
In [ ]: