Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #GAM Generalized Additive (Mixed) Models
- #Week 12 slides
- #in Praat, for each voice portion, file>extract selected sound (time from zero)
- #rename each with the following pattern
- # <participant initials lower case>_<gender>_<native/nonnative>_<t1/t2/t3/t4 (variation)>
- #Select all sound objects (renamed ones only), and convert to pitch objects iusing analayse Periodicity > to pitch...
- #convert > down to pitch tier
- library(rPraat)
- library(reshape2)
- ptFiles <- dir(pattern = "*.PitchTier")
- numFiles <- length(ptFiles)
- numSamples <- 100
- f0Contour <- matrix(numeric(numSamples*numFiles), ncol = numSamples)
- for(fIdx in 1:numFiles) {
- pitchData <- pt.read(ptFiles[fIdx])
- numTimeObs <- length(pitchData$t)
- timeVecInterp <- seq(pitchData$t[1], pitchData$t[numTimeObs], length = numSamples)
- f0Contour[fIdx, ] <- approx(pitchData$t, pitchData$f, timeVecInterp)$y
- }
- id <- as.factor(regmatches(ptFiles, regexpr("[a-z]*(?=\\_)", ptFiles, perl = TRUE)))
- sex <- as.factor(regmatches(ptFiles, regexpr("[a-z]*(?=\\_)", ptFiles, perl = TRUE)))
- native <- as.factor(regmatches(ptFiles, regexpr("[a-z]*(?=\\_)", ptFiles, perl = TRUE)))
- tone <- as.factor(regmatches(ptFiles, regexpr("(?<=\\_)t.", ptFiles, perl = TRUE)))
- dfMaster <- data.frame(id, sex, native, tone, f0Contour)
- dfMelt <- melt(dfMaster, id.vars = c("id", "tone", "type", "tone"))
- library(mgcv)
- dfMelt$time <- as.numeric(dfMelt$variable)
- fit <- bam(value ~ tone +
- s(time, by = tone, bs = "cr"), data = dfMelt, method = "fREML")
- library(itsadug)
- plot_smooth(fit, view= "time" , plot_all = c("tone") , rug = F)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement