Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #<number_id>_<tone>_<rhymetype>_<trialNumber>
- setwd("~/Desktop/Falam Recordings/PitchTier")
- #this removes thigns frm rg\ightside thingy
- rm(list=ls())
- library(rPraat)
- library(reshape2)
- library(dplyr)
- library(dygraphs)
- library(tuneR)
- 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("^\\d*(?=\\_)", ptFiles, perl = TRUE)))
- wordType <- as.factor(regmatches(ptFiles, regexpr("[A-Za-z]+(?=_[012].PitchTier$)", ptFiles, perl = TRUE)))
- tone <- as.factor(regmatches(ptFiles, regexpr("(?<=\\d\\_)(rising|falling|high|low)", ptFiles, perl = TRUE)))
- trialNum <- as.factor(regmatches(ptFiles, regexpr("[0123].PitchTier$", ptFiles, perl = TRUE)))
- dfMaster <- data.frame(id, wordType, trialNum, tone, f0Contour)
- dfMelt <- melt(dfMaster, id.vars = c("id", "wordType", "trialNum", "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