Hands-On Exercise 4

Author

Leonard Lee

Published

May 4, 2023

1 Loading Packages

Show me the good stuff
pacman::p_load(ggstatsplot, tidyverse)

2 Importing the Data

Show me the good stuff
exam_data <- read_csv("data/Exam_data.csv")

head(exam_data, 10)
# A tibble: 10 × 7
   ID         CLASS GENDER RACE    ENGLISH MATHS SCIENCE
   <chr>      <chr> <chr>  <chr>     <dbl> <dbl>   <dbl>
 1 Student321 3I    Male   Malay        21     9      15
 2 Student305 3I    Female Malay        24    22      16
 3 Student289 3H    Male   Chinese      26    16      16
 4 Student227 3F    Male   Chinese      27    77      31
 5 Student318 3I    Male   Malay        27    11      25
 6 Student306 3I    Female Malay        31    16      16
 7 Student313 3I    Male   Chinese      31    21      25
 8 Student316 3I    Male   Malay        31    18      27
 9 Student312 3I    Male   Malay        33    19      15
10 Student297 3H    Male   Indian       34    49      37

3 Use gghistostats() - One-Sample Test

Show me the good stuff
set.seed(1234)

gghistostats(
  data = exam_data,
  x = ENGLISH,
  type = "bayes",
  test.value = 60,
  xlab = "English scores") + 
  theme_classic()

4 Use ggbetweenstats()

4.1 Two-Sample Test

Show me the good stuff
ggbetweenstats(
  data = exam_data,
  x = GENDER, 
  y = MATHS,
  type = "np",
  messages = FALSE) +
  theme_classic()

4.2 One-Way ANOVA Test (difference of means)

Show me the good stuff
ggbetweenstats(
  data = exam_data,
  x = RACE, 
  y = ENGLISH,
  type = "p",
  mean.ci = TRUE, 
  pairwise.comparisons = TRUE, 
  pairwise.display = "s",
  p.adjust.method = "fdr",
  messages = FALSE) +
  theme_classic()

5 ggscatterstats - Correlation Test

Show me the good stuff
ggscatterstats(
  data = exam_data,
  x = MATHS,
  y = ENGLISH,
  marginal = FALSE) +
  theme_classic() +
  theme(plot.background = element_rect(fill = "#F8F3E6", color = "#F8F3E6"))

6 ggbarstats() - Association Test of Dependence

Show me the good stuff
exam1 <- exam_data %>% 
  mutate(MATHS_bins = 
           cut(MATHS, 
               breaks = c(0,60,75,85,100))
)

ggbarstats(exam1, 
           x = MATHS_bins, 
           y = GENDER) +
  theme_classic() +
  theme(plot.background = element_rect(fill = "#F8F3E6", color = "#F8F3E6"))