Advertisement
Guest User

Untitled

a guest
Nov 13th, 2019
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.59 KB | None | 0 0
  1. #GAM Generalized Additive (Mixed) Models
  2. #Week 12 slides
  3.  
  4. #in Praat, for each voice portion, file>extract selected sound (time from zero)
  5. #rename each with the following pattern
  6. # <participant initials lower case>_<gender>_<native/nonnative>_<t1/t2/t3/t4 (variation)>
  7. #Select all sound objects (renamed ones only), and convert to pitch objects iusing analayse Periodicity > to pitch...
  8. #convert > down to pitch tier
  9.  
  10.  
  11. library(rPraat)
  12. library(reshape2)
  13. ptFiles <- dir(pattern = "*.PitchTier")
  14. numFiles <- length(ptFiles)
  15. numSamples <- 100
  16.  
  17. f0Contour <- matrix(numeric(numSamples*numFiles), ncol = numSamples)
  18.  
  19. for(fIdx in 1:numFiles) {
  20.  
  21. pitchData <- pt.read(ptFiles[fIdx])
  22. numTimeObs <- length(pitchData$t)
  23. timeVecInterp <- seq(pitchData$t[1], pitchData$t[numTimeObs], length = numSamples)
  24. f0Contour[fIdx, ] <- approx(pitchData$t, pitchData$f, timeVecInterp)$y
  25. }
  26.  
  27. id <- as.factor(regmatches(ptFiles, regexpr("[a-z]*(?=\\_)", ptFiles, perl = TRUE)))
  28. sex <- as.factor(regmatches(ptFiles, regexpr("[a-z]*(?=\\_)", ptFiles, perl = TRUE)))
  29. native <- as.factor(regmatches(ptFiles, regexpr("[a-z]*(?=\\_)", ptFiles, perl = TRUE)))
  30. tone <- as.factor(regmatches(ptFiles, regexpr("(?<=\\_)t.", ptFiles, perl = TRUE)))
  31.  
  32.  
  33. dfMaster <- data.frame(id, sex, native, tone, f0Contour)
  34. dfMelt <- melt(dfMaster, id.vars = c("id", "tone", "type", "tone"))
  35.  
  36. library(mgcv)
  37. dfMelt$time <- as.numeric(dfMelt$variable)
  38. fit <- bam(value ~ tone +
  39. s(time, by = tone, bs = "cr"), data = dfMelt, method = "fREML")
  40. library(itsadug)
  41. plot_smooth(fit, view= "time" , plot_all = c("tone") , rug = F)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement