#################################################################################### #This is a file with executable R code for chapter 11 of Natalia Levshina's (2015) #How to Do Linguistics with R. Amsterdam/Philadelphia: John Benjamins. #################################################################################### ###Section 11.2 ##Main text library(Rling) data(quite_Br) data(quite_Am) head(quite_Br) nrow(quite_Br) nrow(quite_Am) sum(quite_Br\$BrE) sum(quite_Am\$AmE) quite <- merge(quite_Br, quite_Am, by = "Adj", all = TRUE) head(quite) quite[is.na(quite)] <- 0 a <- quite\$BrE b <- quite\$AmE c <- sum(quite\$BrE) - quite\$BrE d <- sum(quite\$AmE) - quite\$AmE aExp <- (a + b)*(a + c)/(a + b + c + d) pvF <- pv.Fisher.collostr(a, b, c, d) logpvF <- ifelse(a < aExp, log10(pvF), -log10(pvF)) quite\$logp <- logpvF quite <- quite[order(-quite\$logp),] quite[1:20,] quite <- quite[order(quite\$logp),] quite[1:20,] nrow(quite[quite\$logp > 1.3,]) nrow(quite[quite\$logp < (-1.3),]) ###Section 11.3 ##Main text data(quite_Ca) quite1 <- merge(quite[, -4], quite_Ca, by = "Adj", all = TRUE) quite1[is.na(quite1)] <- 0 str(quite1) a <- quite1\$CE b <- quite1\$BrE + quite1\$AmE c <- sum(a) - a d <- sum(b) - b aExp <-(a + b)*(a + c)/(a + b + c + d) pvF <- pv.Fisher.collostr(a, b, c, d) logpvF <- ifelse(a < aExp, log10(pvF), -log10(pvF)) quite1\$logpCE <- logpvF quite1 <- quite1[order(-quite1\$logpCE),] quite1[1:20,] quite1 <- quite1[order(quite1\$logpCE),] quite1[1:20,]