Day 7 notes

in-class
Author

Josef Fruehwald

Published

September 18, 2024

library(tidyverse)
library(palmerpenguins)
data("pb52", package = "phonTools")
remotes::install_github("jvcasillas/untidydata")
Error: Failed to install 'untidydata' from GitHub:
  HTTP error 401.
  Bad credentials

  Rate limit remaining: 38/60
  Rate limit reset at: 2024-09-20 15:57:42 UTC

  
pb52_wide <- read_csv("https://lin611-2024.github.io/notes/meetings/data/pb52_wide.csv")
pb52 |>
  summarise(
    .by = c(vowel,repetition),
    f1 = mean(f1)
  )
tibble(
  segment  = c("P", "T", "D", "G", "G", "K")
) |> 
  mutate(
    voicing = case_when(
      segment %in% c("P", "T", "K") ~ "voiceless",
      segment %in% c("B", "D", "G") ~ "voiced"
    ),
    #place = 
  )

Untidy data

pb52_wide <- read_csv("https://lin611-2024.github.io/notes/meetings/data/pb52_wide.csv")
pb52_wide |> 
  select(
    ends_with("_f1")
  )
pb52_wide |>
  pivot_longer(
    cols = matches("_f"),
    names_to = "vowel_formant",
    values_to = "hz"
  ) |>
  separate_wider_delim(
    vowel_formant,
    delim = "_",
    names = c("vowel", "formant")
  ) |>
  pivot_wider(
    names_from = formant,
    values_from = hz
  )

Practical

pb52 |> 
  filter(
    speaker == 1
  ) -> 
  sp1
mean(
  log(
    c(
      sp1$f1,
      sp1$f2,
      sp1$f3
    )
  )
)
[1] 7.045615
pb52 |>
  pivot_longer(
    cols = f1:f3,
    names_to = "formant",
    values_to = "value"
  ) |> 
  mutate(
    .by = speaker,
    value = log(value) - mean(log(value))
  ) |>
  pivot_wider(
    names_from = formant,
    values_from = value
  ) ->
  pb_normed
pb_normed |> 
  ggplot(
    aes(f2, f1)
  )+
    geom_point()+
    scale_x_reverse()+
    scale_y_reverse()+
    facet_wrap(~type)+
    coord_fixed()

babynames |> 
  filter(
    year == 1997
  )->
  baby_1997

baby_1997 |> 
  select(-prop) |> 
  pivot_wider(
    names_from = sex,
    values_from = n
  ) |>
  mutate(
    total = F + M,
    ratio = F/M
  ) |> 
  filter(
    between(ratio, 0.98, 1.02)
  ) |> 
  arrange(
    desc(total)
  )

Reuse

CC-BY 4.0

Citation

BibTeX citation:
@online{fruehwald2024,
  author = {Fruehwald, Josef},
  title = {Day 7 Notes},
  date = {2024-09-18},
  url = {https://lin611-2024.github.io/notes/in-class/2024-09-18_day7.html},
  langid = {en}
}
For attribution, please cite this work as:
Fruehwald, Josef. 2024. “Day 7 Notes.” September 18, 2024. https://lin611-2024.github.io/notes/in-class/2024-09-18_day7.html.