The Mad Hatter’s Guide to Data Viz and Stats in R
  1. Data Viz and Stats
  2. Case Studies
  3. Hearing Loss in Children
  • Data Viz and Stats
    • Tools
      • Introduction to R and RStudio
    • Studio Flow and Data Kits
      • 12-Day Studio Index
      • Healthcare Data Kits
    • Visualization
      • Data
      • Inspect Data
      • Graphs
      • Summaries
      • Counts
      • Quantities
      • Groups
      • Distributions
      • Groups and Distributions
      • Change
      • Proportions
      • Hierarchy
      • Evolution and Flow
      • Ratings and Rankings
      • Surveys
      • Time
      • Space
        • Introduction to Maps
        • What is Vector Data?
        • The Grammar of Maps
        • Interactive Maps with leaflet
      • Networks
      • Miscellaneous Graphing Tools, and References
    • Inference
      • Basics
      • 🎲 Samples
      • Randomization
      • One Mean
      • Two Independent Means
      • Two Paired Means
      • Multiple Means (ANOVA)
      • Correlation
      • One Proportion
      • Two Proportions
    • Modelling
      • Linear Regression
      • Logistic Regression
      • 🕔 Time Series
    • Workflow
      • Facing the Abyss
      • I Publish, therefore I Am
      • Data Carpentry
    • Arts
      • Colours
      • Fonts for Charts
      • Font Effects in Charts
      • Branding and Typography
      • Annotations
      • More Annotations
      • Highlighting
      • Scales
    • AI Tools
      • Using gander and ellmer
      • Using Github Copilot and other AI tools to generate R code
      • Using LLMs to Explain Stat models
    • Case Studies
      • Demo:Product Packaging and Elderly People
      • Ikea Furniture
      • Movie Profits
      • Gender at the Work Place
      • Heptathlon
      • School Scores
      • Children's Games
      • Valentine’s Day Spending
      • Women Live Longer?
      • Hearing Loss in Children
      • California Transit Payments
      • Seaweed Nutrients
      • Coffee Flavours
      • Legionnaire’s Disease in the USA
      • Antarctic Sea ice
      • William Farr's Observations on Cholera in London
    • Projects
      • No Free Hunch

On this page

  • 1 Setting up R Packages
    • 1.1 Plot Fonts and Theme
  • 2 Introduction
  • 3 Read the Data
  • 4 Data Dictionary
  • 5 Research Question
  • 6 Analyse/Transform the Data
  • 7 Plot the Data
  • 8 Task and Discussion
  1. Data Viz and Stats
  2. Case Studies
  3. Hearing Loss in Children

Hearing Loss in Children

1 Setting up R Packages

library(tidyverse)
library(mosaic)
library(skimr)
library(ggformula)
library(ggprism)

1.1 Plot Fonts and Theme

Use _setup.qmd to set these up.

2 Introduction

Children are monitored for OME (Otitis Media with Effusion, i.e. fluid in the middle ear) over time. It is believed that they later ( i.e. during aduldhood) suffer from “binaural hearing loss” (detecting sound amplitude and direction) after past episodes of OME during their childhood. The hearing-test is conducted multiple times, with a Test Signal embedded in noise played over audio loudspeakers. One loudspeaker has only Noise, and the other loudspeaker has the Test Signal in Noise. There are also two types of Test Signals: one is like noise itself and the other is distinct. In any test round, children are expected to orient themselves towards the appropriate loudspeaker and detect the presence of the Test Signal at varying levels of volume, with a passing success rate of 75% over multiple tests.

This dataset is available on Vincent Arel-Bundock’s dataset repository and is a part of the R package MASS.

3 Read the Data

ome <- read_csv("https://vincentarelbundock.github.io/Rdatasets/csv/MASS/OME.csv")
glimpse(ome)
Rows: 1,097
Columns: 8
$ rownames <dbl> 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18…
$ ID       <dbl> 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 3…
$ Age      <dbl> 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 60, 60, 60, 60, 60, 6…
$ OME      <chr> "low", "low", "low", "low", "low", "low", "low", "low", "low"…
$ Loud     <dbl> 35, 35, 40, 40, 45, 45, 50, 50, 55, 55, 35, 35, 40, 40, 45, 4…
$ Noise    <chr> "coherent", "incoherent", "coherent", "incoherent", "coherent…
$ Correct  <dbl> 1, 4, 0, 1, 2, 2, 3, 4, 3, 2, 2, 3, 1, 1, 1, 5, 4, 2, 3, 4, 4…
$ Trials   <dbl> 4, 5, 3, 1, 4, 2, 3, 4, 3, 2, 4, 4, 4, 1, 2, 5, 4, 2, 3, 4, 6…
ome

4 Data Dictionary

NoteQuantitative Variables

Write in.

NoteQualitative Variables

Write in.

NoteObservations

Write in.

5 Research Question

Note

In hearing tests on people with varying levels of OME infection in their childhood, what is the effect of using distinct types of Test Signal on successful (face) orientation ?

6 Analyse/Transform the Data

```{r}
#| label: data-preprocessing
#
# Write in your code here
# to prepare this data as shown below
# to generate the plot that follows
# Rename Variables if needed
# Change data to factors etc.
# Set up Counts, histograms etc
```
Show the Code
ome %>%
  mutate(success_rate = Correct / Trials) %>%
  mutate(
    ID = as_factor(ID),
    Age = as_factor(Age),
    OME = base::factor(OME, levels = c("low", "high", "NA"), ordered = TRUE),
    Noise = base::factor(Noise, labels = c("Test Signal is Noise-like", "Test Signal is Distinct"), levels = c("coherent", "incoherent")),
    Loud = as_factor(Loud)
  ) -> ome_modified

ome_modified

7 Plot the Data

Show the Code
ome_modified %>%
  gf_boxplot(success_rate ~ OME, fill = ~OME, alpha = 0.5) %>%
  gf_facet_grid(~Noise) %>%
  gf_hline(yintercept = 0.75, linewidth = 1, linetype = "dotted", colour = ~"grey") %>%
  gf_labs(
    title = "Hearing Test for Children with (OME) Disease", ,
    subtitle = "Test = Detection of  Test Signal in Noise\nPassing Score = 0.75",
    x = "Incidence of OME Disease over Childhood",
    y = "Successful Detection Score\n(over multiple trials)",
    caption = "Dataset from R package MASS by Venables and Ripley"
  ) %>%
  gf_refine(
    scale_fill_brewer(palette = "Set1", na.value = "grey90"),
    scale_x_discrete(guide = "prism_bracket")
  )

8 Task and Discussion

  • Complete the Data Dictionary.
  • Select and Transform the variables as shown.
  • Create the graphs shown and discuss the following questions:
    • Identify the type of charts
    • Identify the variables used for various geometrical aspects (x, y, fill…). Name the variables appropriately.
    • What research activity might have been carried out to obtain the data graphed here? Provide some details.
    • What pre-processing of the data was required to create the chart?
    • Write a 2-line story based on the chart, describing your inference/surprise. Is there something counter-intuitive (to a lay person) in the chart?
Back to top
Women Live Longer?
California Transit Payments

License: CC BY-SA 2.0

Website made with ❤️ and Quarto, by Arvind V.

Hosted by Netlify .