Study #2: Nerdiness Code

Below is the code I used to conduct analysis on Enneagram vs Nerdiness using the Nerdy Personality Attributes Scale from Open Psychometrics. There are undoubtedly more sophisticated ways to go about it, but I’m not a professional coder and my rudimentary methods seemed to do the trick. Feel free to double-check my work! The raw data file is available for download on Google Drive if you’d like to play around with it on your own or rerun my code in RStudio.

# This script contains all the tests performed to assess the dataset for
# relationships between the Enneagram and nerdiness as determined by the 
# Nerdy Personality Attributes Scale (NPAS; openpsychometrics.org/tests/NPAS/).
# Generated and assessed by Danielle F. of The Scientific Enneagram

####SETUP####

# 1. Set working directory to the folder with the raw data file ####

# 2. Load the source file into a dataframe (here called "raw") ####
raw <- read.csv("Enneagram vs. Nerdiness.csv",header=T)

# 3. Put variables in a usable format ####
raw$Score <- as.integer(raw$Score)
raw$Type <- as.factor(raw$Type)
raw$Wing <- as.factor(raw$Wing)
raw$Subtype <- as.factor(raw$Subtype)

# 4. Create ScientificEnneagram Color Palette ####
## Identify @SE colors
SciEn_color <- function(...) {
  SciEn_colors <- c(`1lt`="#A0D1CA",`1dk`="#1D8296",
                    `2lt`="#e5bcd7",`2dk`="#93272C",
                    `3lt`="#f4623a",`3dk`="#93272C",
                    `4lt`="#f8ad6d",`4dk`="#be5500",
                    `5lt`="#98b6e4",`5dk`="#5e8dda",
                    `6lt`="#fed880",`6dk`="#e0a526",
                    `7lt`="#ac9f3d",`7dk`="#8a7b19",
                    `8lt`="#f8ad6d",`8dk`="#be5500",
                    `9lt`="#f8c1b8",`9dk`="#f17f70",
                    `basedark`="#005151",
                    `basemed`="#c39367",
                    `baselight`="#f2e9db")
  cols <- c(...)
  if (is.null(cols))
    return (SciEn_colors)
  SciEn_colors[cols]
}
## Create palettes using @SE colors
SciEn_palette <- function(palette = "darkType", ...) {
  SciEn_palettes <- list(
    `darkType`=SciEn_color("1dk","2dk","3lt","4lt","5dk","6dk","7dk","8dk","9dk"),
    `lightType`=SciEn_color("1lt","2lt","3dk","4lt","5lt","6lt","7lt","8dk","9lt"),
    `base` = SciEn_color("basedark","basemed","baselight"),
    `water` = SciEn_color("1lt","1dk","5lt","5dk","7lt","7dk","basedark"),
    `fire`= SciEn_color("2lt","2dk","3lt","4lt","9dk","4dk","6lt","9lt","6dk"),
    `stoplight` = SciEn_color("3lt","5lt","7dk","baselight"),
    `1Wings` = SciEn_color("2lt","9lt","1dk","1lt"),
    `2Wings` = SciEn_color("3lt","1lt","2lt","2dk"),
    `3Wings` = SciEn_color("4lt","2lt","3dk","3lt"),
    `4Wings` = SciEn_color("5lt","3lt","4lt","4dk"),
    `5Wings` = SciEn_color("6lt","4lt","5dk","5lt"),
    `6Wings` = SciEn_color("7lt","5lt","6dk","6lt"),
    `7Wings` = SciEn_color("8lt","6lt","7dk","7lt"),
    `8Wings` = SciEn_color("9lt","7lt","8dk","8lt"),
    `9Wings` = SciEn_color("1lt","8lt","9dk","9lt")
  )
  SciEn_palettes[[palette]]
}
## Create functions to use @SE palettes in graphs/charts
palette_gen <- function(palette = "darkType", direction = 1) {
  function(n) {
    if (n > length(SciEn_palette(palette)))
      warning("Not enough colors in this palette!")
    else {
      all_colors <- SciEn_palette(palette)
      all_colors <- unname(unlist(all_colors))
      all_colors <- if (direction >= 0) all_colors else rev(all_colors)
      color_list <- all_colors[1:n]}
  }
}
scale_fill_SciEn <- function(palette = "darkType", direction = 1, ...) {
  ggplot2::discrete_scale("fill", "SciEn",  palette_gen(palette, direction),...)
}
scale_color_SciEn <- function(palette = "darkType", direction = 1, ...) {
  ggplot2::scale_color_discrete("SciEn", palette_gen(palette, direction),...)
}

####ANALYSIS####

# 5. Summary tables ####
## By NPAS Score
summary(raw$Score)
## By Type
addmargins(table(raw$Type))
round((prop.table(table(raw$Type))*100),1)
## By Subtype
addmargins(table(raw$Subtype))
round((prop.table(table(raw$Subtype))*100),1)
## By Wing
addmargins(table(raw$Wing))
round((prop.table(table(raw$Wing))*100),1)

# 6. Type 1 Results ####
## Counts
summary(subset(raw$Score,raw$Type=="Type 1"))
table(raw$Type=="Type 1",raw$Wing)
table(raw$Type=="Type 1",raw$Subtype)
## Tests
t.test(Score ~ Wing, data = subset(raw,raw$Type=="Type 1"&raw$Wing!="IDK/NA"))
summary(aov(Score ~ Subtype, data = subset(raw,raw$Type=="Type 1"&raw$Subtype!="IDK")))
## Graphs
wing_1scores <- subset(raw, raw$Wing!=""&raw$Wing!="IDK/NA"&raw$Type=="Type 1") |> 
  group_by(Wing) |> 
  summarize(med = median(Score),
            Q1 = quantile(Score, 0.25),
            Q3 = quantile(Score, 0.75),
            Max = max(Score),
            Min = min(Score))
ggplot(wing_1scores, aes(x = Wing, color = Wing)) +
  geom_pointrange(aes(y = med, ymin = Min, ymax = Max), size=1, show.legend = FALSE) +
  geom_point(aes(y=Q1), size=3, shape=3, show.legend = FALSE) +
  geom_point(aes(y=Q3), size=3, shape=3, show.legend = FALSE) +
  geom_point(aes(y=Min), size=1, show.legend = FALSE) +
  geom_point(aes(y=Max), size=1, show.legend = FALSE) +  
  ylim(30,70) +
  scale_color_manual(values = c("w2" = "#e5bcd7", "w9" = "#f17f70")) +
  labs(x = "", y="") +
  theme_light() +
  theme(panel.grid.major.x = element_blank())
subtype_1scores <- subset(raw, raw$Subtype!=""&raw$Subtype!="IDK"&raw$Type=="Type 1") |> 
  group_by(Subtype) |> 
  summarize(med = median(Score),
            Q1 = quantile(Score, 0.25),
            Q3 = quantile(Score, 0.75),
            Max = max(Score),
            Min = min(Score))
ggplot(subtype_1scores, aes(x = Subtype, color = Subtype)) +
  geom_pointrange(aes(y = med, ymin = Min, ymax = Max), size=1, show.legend = FALSE) +
  geom_point(aes(y=Q1), size=3, shape=3, show.legend = FALSE) +
  geom_point(aes(y=Q3), size=3, shape=3, show.legend = FALSE) +
  geom_point(aes(y=Min), size=1, show.legend = FALSE) +
  geom_point(aes(y=Max), size=1, show.legend = FALSE) +  
  ylim(30,70) +
  scale_color_manual(values = c("SP" = "darkblue", "SX" = "magenta", "SO" = "green")) +
  labs(x = "", y="") +
  theme_light() +
  theme(panel.grid.major.x = element_blank())

# 7. Type 2 Results ####
# Counts
summary(subset(raw$Score,raw$Type=="Type 2"))
table(raw$Type=="Type 2",raw$Wing)
table(raw$Type=="Type 2",raw$Subtype)
# Tests
t.test(Score ~ Wing, data = subset(raw,raw$Type=="Type 2"&raw$Wing!="IDK/NA"))
summary(aov(Score ~ Subtype, data = subset(raw,raw$Type=="Type 2"&raw$Subtype!="IDK")))
TukeyHSD(aov(Score ~ Subtype, data = subset(raw,raw$Type=="Type 2"&raw$Subtype!="IDK")))
# Graphs
wing_2scores <- subset(raw, raw$Wing!=""&raw$Wing!="IDK/NA"&raw$Type=="Type 2") |> 
  group_by(Wing) |> 
  summarize(med = median(Score),
            Q1 = quantile(Score, 0.25),
            Q3 = quantile(Score, 0.75),
            Max = max(Score),
            Min = min(Score))
ggplot(wing_2scores, aes(x = Wing, color = Wing)) +
  geom_pointrange(aes(y = med, ymin = Min, ymax = Max), size=1, show.legend = FALSE) +
  geom_point(aes(y=Q1), size=3, shape=3, show.legend = FALSE) +
  geom_point(aes(y=Q3), size=3, shape=3, show.legend = FALSE) +
  geom_point(aes(y=Min), size=1, show.legend = FALSE) +
  geom_point(aes(y=Max), size=1, show.legend = FALSE) +  
  ylim(30,70) +
  scale_color_manual(values = c("w1" = "#1D8296", "w3" = "#f4623a")) +
  labs(x = "", y="") +
  theme_light() +
  theme(panel.grid.major.x = element_blank())
subtype_2scores <- subset(raw, raw$Subtype!=""&raw$Subtype!="IDK"&raw$Type=="Type 2") |> 
  group_by(Subtype) |> 
  summarize(med = median(Score),
            Q1 = quantile(Score, 0.25),
            Q3 = quantile(Score, 0.75),
            Max = max(Score),
            Min = min(Score))
ggplot(subtype_2scores, aes(x = Subtype, color = Subtype)) +
  geom_pointrange(aes(y = med, ymin = Min, ymax = Max), size=1, show.legend = FALSE) +
  geom_point(aes(y=Q1), size=3, shape=3, show.legend = FALSE) +
  geom_point(aes(y=Q3), size=3, shape=3, show.legend = FALSE) +
  geom_point(aes(y=Min), size=1, show.legend = FALSE) +
  geom_point(aes(y=Max), size=1, show.legend = FALSE) +  
  ylim(30,70) +
  scale_color_manual(values = c("SP" = "darkblue", "SX" = "magenta", "SO" = "green")) +
  labs(x = "", y="") +
  theme_light() +
  theme(panel.grid.major.x = element_blank())

# 8. Type 3 Results ####
# Counts
summary(subset(raw$Score,raw$Type=="Type 3"))
table(raw$Type=="Type 3",raw$Wing)
table(raw$Type=="Type 3",raw$Subtype)
# Tests
t.test(Score ~ Wing, data = subset(raw,raw$Type=="Type 3"&raw$Wing!="IDK/NA"))
summary(aov(Score ~ Subtype, data = subset(raw,raw$Type=="Type 3"&raw$Subtype!="IDK")))
# Graphs
wing_3scores <- subset(raw, raw$Wing!=""&raw$Wing!="IDK/NA"&raw$Type=="Type 3") |> 
  group_by(Wing) |> 
  summarize(med = median(Score),
            Q1 = quantile(Score, 0.25),
            Q3 = quantile(Score, 0.75),
            Max = max(Score),
            Min = min(Score))
ggplot(wing_3scores, aes(x = Wing, color = Wing)) +
  geom_pointrange(aes(y = med, ymin = Min, ymax = Max), size=1, show.legend = FALSE) +
  geom_point(aes(y=Q1), size=3, shape=3, show.legend = FALSE) +
  geom_point(aes(y=Q3), size=3, shape=3, show.legend = FALSE) +
  geom_point(aes(y=Min), size=1, show.legend = FALSE) +
  geom_point(aes(y=Max), size=1, show.legend = FALSE) +  
  ylim(30,70) +
  scale_color_manual(values = c("w2" = "#e5bcd7", "w4" = "#f8ad6d")) +
  labs(x = "", y="") +
  theme_light() +
  theme(panel.grid.major.x = element_blank())
subtype_3scores <- subset(raw, raw$Subtype!=""&raw$Subtype!="IDK"&raw$Type=="Type 3") |> 
  group_by(Subtype) |> 
  summarize(med = median(Score),
            Q1 = quantile(Score, 0.25),
            Q3 = quantile(Score, 0.75),
            Max = max(Score),
            Min = min(Score))
ggplot(subtype_3scores, aes(x = Subtype, color = Subtype)) +
  geom_pointrange(aes(y = med, ymin = Min, ymax = Max), size=1, show.legend = FALSE) +
  geom_point(aes(y=Q1), size=3, shape=3, show.legend = FALSE) +
  geom_point(aes(y=Q3), size=3, shape=3, show.legend = FALSE) +
  geom_point(aes(y=Min), size=1, show.legend = FALSE) +
  geom_point(aes(y=Max), size=1, show.legend = FALSE) +  
  ylim(30,70) +
  scale_color_manual(values = c("SP" = "darkblue", "SX" = "magenta", "SO" = "green")) +
  labs(x = "", y="") +
  theme_light() +
  theme(panel.grid.major.x = element_blank())

# 9. Type 4 Results ####
# Counts
summary(subset(raw$Score,raw$Type=="Type 4"))
table(raw$Type=="Type 4",raw$Wing)
table(raw$Type=="Type 4",raw$Subtype)
# Tests
t.test(Score ~ Wing, data = subset(raw,raw$Type=="Type 4"&raw$Wing!="IDK/NA"&raw$Wing!="w2"))
summary(aov(Score ~ Subtype, data = subset(raw,raw$Type=="Type 4"&raw$Subtype!="IDK")))
# Charts
wing_4scores <- subset(raw, raw$Wing!="w2"&raw$Wing!="IDK/NA"&raw$Type=="Type 4") |> 
  group_by(Wing) |> 
  summarize(med = median(Score),
            Q1 = quantile(Score, 0.25),
            Q3 = quantile(Score, 0.75),
            Max = max(Score),
            Min = min(Score))
ggplot(wing_4scores, aes(x = Wing, color = Wing)) +
  geom_pointrange(aes(y = med, ymin = Min, ymax = Max), size=1, show.legend = FALSE) +
  geom_point(aes(y=Q1), size=3, shape=3, show.legend = FALSE) +
  geom_point(aes(y=Q3), size=3, shape=3, show.legend = FALSE) +
  geom_point(aes(y=Min), size=1, show.legend = FALSE) +
  geom_point(aes(y=Max), size=1, show.legend = FALSE) +  
  ylim(30,70) +
  scale_color_manual(values = c("w3" = "#f4623a", "w5" = "#98b6e4")) +
  labs(x = "", y="") +
  theme_light() +
  theme(panel.grid.major.x = element_blank())
subtype_4scores <- subset(raw, raw$Subtype!=""&raw$Subtype!="IDK"&raw$Type=="Type 4") |> 
  group_by(Subtype) |> 
  summarize(med = median(Score),
            Q1 = quantile(Score, 0.25),
            Q3 = quantile(Score, 0.75),
            Max = max(Score),
            Min = min(Score))
ggplot(subtype_4scores, aes(x = Subtype, color = Subtype)) +
  geom_pointrange(aes(y = med, ymin = Min, ymax = Max), size=1, show.legend = FALSE) +
  geom_point(aes(y=Q1), size=3, shape=3, show.legend = FALSE) +
  geom_point(aes(y=Q3), size=3, shape=3, show.legend = FALSE) +
  geom_point(aes(y=Min), size=1, show.legend = FALSE) +
  geom_point(aes(y=Max), size=1, show.legend = FALSE) +  
  ylim(30,70) +
  scale_color_manual(values = c("SP" = "darkblue", "SX" = "magenta", "SO" = "green")) +
  labs(x = "", y="") +
  theme_light() +
  theme(panel.grid.major.x = element_blank())

# 10. Type 5 Results ####
# Counts
summary(subset(raw$Score,raw$Type=="Type 5"))
table(raw$Type=="Type 5",raw$Wing)
table(raw$Type=="Type 5",raw$Subtype)
# Tests
t.test(Score ~ Wing, data = subset(raw,raw$Wing!="w7"&raw$Wing!="w8"&raw$Type=="Type 5"&raw$Wing!="IDK/NA"))
summary(aov(Score ~ Subtype, data = subset(raw,raw$Type=="Type 5"&raw$Subtype!="IDK")))
# Charts
wing_5scores <- subset(raw, raw$Wing!="w7"&raw$Wing!="w8"&raw$Wing!="IDK/NA"&raw$Type=="Type 5") |> 
  group_by(Wing) |> 
  summarize(med = median(Score),
            Q1 = quantile(Score, 0.25),
            Q3 = quantile(Score, 0.75),
            Max = max(Score),
            Min = min(Score))
ggplot(wing_5scores, aes(x = Wing, color = Wing)) +
  geom_pointrange(aes(y = med, ymin = Min, ymax = Max), size=1, show.legend = FALSE) +
  geom_point(aes(y=Q1), size=3, shape=3, show.legend = FALSE) +
  geom_point(aes(y=Q3), size=3, shape=3, show.legend = FALSE) +
  geom_point(aes(y=Min), size=1, show.legend = FALSE) +
  geom_point(aes(y=Max), size=1, show.legend = FALSE) +  
  ylim(30,70) +
  scale_color_manual(values = c("w4" = "#f8ad6d", "w6" = "#fed880")) +
  labs(x = "", y="") +
  theme_light() +
  theme(panel.grid.major.x = element_blank())
subtype_5scores <- subset(raw, raw$Subtype!=""&raw$Subtype!="IDK"&raw$Type=="Type 5") |> 
  group_by(Subtype) |> 
  summarize(med = median(Score),
            Q1 = quantile(Score, 0.25),
            Q3 = quantile(Score, 0.75),
            Max = max(Score),
            Min = min(Score))
ggplot(subtype_5scores, aes(x = Subtype, color = Subtype)) +
  geom_pointrange(aes(y = med, ymin = Min, ymax = Max), size=1, show.legend = FALSE) +
  geom_point(aes(y=Q1), size=3, shape=3, show.legend = FALSE) +
  geom_point(aes(y=Q3), size=3, shape=3, show.legend = FALSE) +
  geom_point(aes(y=Min), size=1, show.legend = FALSE) +
  geom_point(aes(y=Max), size=1, show.legend = FALSE) +  
  ylim(30,70) +
  scale_color_manual(values = c("SP" = "darkblue", "SX" = "magenta", "SO" = "green")) +
  labs(x = "", y="") +
  theme_light() +
  theme(panel.grid.major.x = element_blank())

# 11. Type 6 Results ####
# Counts
summary(subset(raw$Score,raw$Type=="Type 6"))
table(raw$Type=="Type 6",raw$Wing)
table(raw$Type=="Type 6",raw$Subtype)
# Tests 
t.test(Score ~ Wing, data = subset(raw,raw$Type=="Type 6"&raw$Wing!="IDK/NA"))
summary(aov(Score ~ Subtype, data = subset(raw,raw$Type=="Type 6"&raw$Subtype!="IDK")))
# Charts
wing_6scores <- subset(raw, raw$Wing!="IDK/NA"&raw$Type=="Type 6") |> 
  group_by(Wing) |> 
  summarize(med = median(Score),
            Q1 = quantile(Score, 0.25),
            Q3 = quantile(Score, 0.75),
            Max = max(Score),
            Min = min(Score))
ggplot(wing_6scores, aes(x = Wing, color = Wing)) +
  geom_pointrange(aes(y = med, ymin = Min, ymax = Max), size=1, show.legend = FALSE) +
  geom_point(aes(y=Q1), size=3, shape=3, show.legend = FALSE) +
  geom_point(aes(y=Q3), size=3, shape=3, show.legend = FALSE) +
  geom_point(aes(y=Min), size=1, show.legend = FALSE) +
  geom_point(aes(y=Max), size=1, show.legend = FALSE) +  
  ylim(30,70) +
  scale_color_manual(values = c("w5" = "#98b6e4", "w7" = "#8a7b19")) +
  labs(x = "", y="") +
  theme_light() +
  theme(panel.grid.major.x = element_blank())
subtype_6scores <- subset(raw, raw$Subtype!=""&raw$Subtype!="IDK"&raw$Type=="Type 6") |> 
  group_by(Subtype) |> 
  summarize(med = median(Score),
            Q1 = quantile(Score, 0.25),
            Q3 = quantile(Score, 0.75),
            Max = max(Score),
            Min = min(Score))
ggplot(subtype_6scores, aes(x = Subtype, color = Subtype)) +
  geom_pointrange(aes(y = med, ymin = Min, ymax = Max), size=1, show.legend = FALSE) +
  geom_point(aes(y=Q1), size=3, shape=3, show.legend = FALSE) +
  geom_point(aes(y=Q3), size=3, shape=3, show.legend = FALSE) +
  geom_point(aes(y=Min), size=1, show.legend = FALSE) +
  geom_point(aes(y=Max), size=1, show.legend = FALSE) +  
  ylim(30,70) +
  scale_color_manual(values = c("SP" = "darkblue", "SX" = "magenta", "SO" = "green")) +
  labs(x = "", y="") +
  theme_light() +
  theme(panel.grid.major.x = element_blank())

# 12. Type 7 Results ####
# Counts
summary(subset(raw$Score,raw$Type=="Type 7"))
table(raw$Type=="Type 7",raw$Wing)
table(raw$Type=="Type 7",raw$Subtype)
# Tests
t.test(Score ~ Wing, data = subset(raw,raw$Type=="Type 7"&raw$Wing!="IDK/NA"))
summary(aov(Score ~ Subtype, data = subset(raw,raw$Type=="Type 7"&raw$Subtype!="IDK")))
# Charts
wing_7scores <- subset(raw, raw$Wing!="IDK/NA"&raw$Type=="Type 7") |> 
  group_by(Wing) |> 
  summarize(med = median(Score),
            Q1 = quantile(Score, 0.25),
            Q3 = quantile(Score, 0.75),
            Max = max(Score),
            Min = min(Score))
ggplot(wing_7scores, aes(x = Wing, color = Wing)) +
  geom_pointrange(aes(y = med, ymin = Min, ymax = Max), size=1, show.legend = FALSE) +
  geom_point(aes(y=Q1), size=3, shape=3, show.legend = FALSE) +
  geom_point(aes(y=Q3), size=3, shape=3, show.legend = FALSE) +
  geom_point(aes(y=Min), size=1, show.legend = FALSE) +
  geom_point(aes(y=Max), size=1, show.legend = FALSE) +  
  ylim(30,70) +
  scale_color_manual(values = c("w6" = "#e0a526", "w8" = "#be5500")) +
  labs(x = "", y="") +
  theme_light() +
  theme(panel.grid.major.x = element_blank())
subtype_7scores <- subset(raw, raw$Subtype!=""&raw$Subtype!="IDK"&raw$Type=="Type 7") |> 
  group_by(Subtype) |> 
  summarize(med = median(Score),
            Q1 = quantile(Score, 0.25),
            Q3 = quantile(Score, 0.75),
            Max = max(Score),
            Min = min(Score))
ggplot(subtype_7scores, aes(x = Subtype, color = Subtype)) +
  geom_pointrange(aes(y = med, ymin = Min, ymax = Max), size=1, show.legend = FALSE) +
  geom_point(aes(y=Q1), size=3, shape=3, show.legend = FALSE) +
  geom_point(aes(y=Q3), size=3, shape=3, show.legend = FALSE) +
  geom_point(aes(y=Min), size=1, show.legend = FALSE) +
  geom_point(aes(y=Max), size=1, show.legend = FALSE) +  
  ylim(30,70) +
  scale_color_manual(values = c("SP" = "darkblue", "SX" = "magenta", "SO" = "green")) +
  labs(x = "", y="") +
  theme_light() +
  theme(panel.grid.major.x = element_blank())

# 13. Type 8 Results ####
summary(subset(raw$Score,raw$Type=="Type 8"))
table(raw$Type=="Type 8",raw$Wing)
table(raw$Type=="Type 8",raw$Subtype)
# Tests
t.test(Score ~ Wing, data = subset(raw,raw$Type=="Type 8"&raw$Wing!="IDK/NA"))
summary(aov(Score ~ Subtype, data = subset(raw,raw$Type=="Type 8"&raw$Subtype!="IDK")))
# Charts
wing_8scores <- subset(raw, raw$Wing!="IDK/NA"&raw$Type=="Type 8") |> 
  group_by(Wing) |> 
  summarize(med = median(Score),
            Q1 = quantile(Score, 0.25),
            Q3 = quantile(Score, 0.75),
            Max = max(Score),
            Min = min(Score))
ggplot(wing_8scores, aes(x = Wing, color = Wing)) +
  geom_pointrange(aes(y = med, ymin = Min, ymax = Max), size=1, show.legend = FALSE) +
  geom_point(aes(y=Q1), size=3, shape=3, show.legend = FALSE) +
  geom_point(aes(y=Q3), size=3, shape=3, show.legend = FALSE) +
  geom_point(aes(y=Min), size=1, show.legend = FALSE) +
  geom_point(aes(y=Max), size=1, show.legend = FALSE) +  
  ylim(30,70) +
  scale_color_manual(values = c("w7" = "#8a7b19", "w9" = "#f8c1b8")) +
  labs(x = "", y="") +
  theme_light() +
  theme(panel.grid.major.x = element_blank())
subtype_8scores <- subset(raw, raw$Subtype!=""&raw$Subtype!="IDK"&raw$Type=="Type 8") |> 
  group_by(Subtype) |> 
  summarize(med = median(Score),
            Q1 = quantile(Score, 0.25),
            Q3 = quantile(Score, 0.75),
            Max = max(Score),
            Min = min(Score))
ggplot(subtype_8scores, aes(x = Subtype, color = Subtype)) +
  geom_pointrange(aes(y = med, ymin = Min, ymax = Max), size=1, show.legend = FALSE) +
  geom_point(aes(y=Q1), size=3, shape=3, show.legend = FALSE) +
  geom_point(aes(y=Q3), size=3, shape=3, show.legend = FALSE) +
  geom_point(aes(y=Min), size=1, show.legend = FALSE) +
  geom_point(aes(y=Max), size=1, show.legend = FALSE) +  
  ylim(30,70) +
  scale_color_manual(values = c("SP" = "darkblue", "SX" = "magenta", "SO" = "green")) +
  labs(x = "", y="") +
  theme_light() +
  theme(panel.grid.major.x = element_blank())

# 14. Type 9 Results ####
# Counts
summary(subset(raw$Score,raw$Type=="Type 9"))
table(raw$Type=="Type 9",raw$Wing)
table(raw$Type=="Type 9",raw$Subtype)
# Tests
t.test(Score ~ Wing, data = subset(raw,raw$Type=="Type 9"&raw$Wing!="IDK/NA"))
summary(aov(Score ~ Subtype, data = subset(raw,raw$Type=="Type 9"&raw$Subtype!="IDK")))
# Charts
wing_9scores <- subset(raw, raw$Wing!="IDK/NA"&raw$Type=="Type 9") |> 
  group_by(Wing) |> 
  summarize(med = median(Score),
            Q1 = quantile(Score, 0.25),
            Q3 = quantile(Score, 0.75),
            Max = max(Score),
            Min = min(Score))
ggplot(wing_9scores, aes(x = Wing, color = Wing)) +
  geom_pointrange(aes(y = med, ymin = Min, ymax = Max), size=1, show.legend = FALSE) +
  geom_point(aes(y=Q1), size=3, shape=3, show.legend = FALSE) +
  geom_point(aes(y=Q3), size=3, shape=3, show.legend = FALSE) +
  geom_point(aes(y=Min), size=1, show.legend = FALSE) +
  geom_point(aes(y=Max), size=1, show.legend = FALSE) +  
  ylim(30,70) +
  scale_color_manual(values = c("w1" = "#A0D1CA", "w8" = "#f8ad6d")) +
  labs(x = "", y="") +
  theme_light() +
  theme(panel.grid.major.x = element_blank())
subtype_9scores <- subset(raw, raw$Subtype!=""&raw$Subtype!="IDK"&raw$Type=="Type 9") |> 
  group_by(Subtype) |> 
  summarize(med = median(Score),
            Q1 = quantile(Score, 0.25),
            Q3 = quantile(Score, 0.75),
            Max = max(Score),
            Min = min(Score))
ggplot(subtype_9scores, aes(x = Subtype, color = Subtype)) +
  geom_pointrange(aes(y = med, ymin = Min, ymax = Max), size=1, show.legend = FALSE) +
  geom_point(aes(y=Q1), size=3, shape=3, show.legend = FALSE) +
  geom_point(aes(y=Q3), size=3, shape=3, show.legend = FALSE) +
  geom_point(aes(y=Min), size=1, show.legend = FALSE) +
  geom_point(aes(y=Max), size=1, show.legend = FALSE) +  
  ylim(30,70) +
  scale_color_manual(values = c("SP" = "darkblue", "SX" = "magenta", "SO" = "green")) +
  labs(x = "", y="") +
  theme_light() +
  theme(panel.grid.major.x = element_blank())

# 15. Overall analysis
## ANOVA
aov_Type <- aov(Score ~ Type, data = subset(raw,!is.na(raw$Type)))
summary(aov_Type)
aov_Subtype <- aov(Score ~ Subtype, data = raw)
summary(aov_Subtype)
aov_Wing <- aov(Score ~ Wing, data = raw)
summary(aov_Wing)
## Posthoc tests
TukeyHSD(aov_Type)
TukeyHSD(aov_Wing)

# 16: Check assumptions
## Normality
shapiro.test(raw$Score)
library(ggplot2)
ggplot(raw, aes(x = Score)) +
  geom_bar()
## Homogeneity of variances
library(car)
leveneTest(Score ~ Type, data = raw)
Next
Next

Study #1: Initial Setup Code