#################################################################################### #This is a file with executable R code for chapter 10 of Natalia Levshina's (2015) #How to Do Linguistics with R. Amsterdam/Philadelphia: John Benjamins. #################################################################################### ###Section 10.2 ##Main text install.packages(c("ggplot2", "corrgram") #if you haven't installed these packages yet library(Rling); library(ggplot2); library(corrgram) data(ditr) head(ditr) a <- ditr$Freq_VC b <- ditr$Freq_V - a c <- 667 - a d <- 104162 - (a + b + c) head(c) aExp <- (a + b)*(a + c)/(a + b + c + d) head(aExp) Attr <- 100*a/(a + c) Rel <- 100*a/(a + b) names(Attr) <- rownames(ditr) head(Attr) sort(Attr, decreasing = TRUE)[1:5] names(Rel) <- rownames(ditr) sort(Rel, decreasing = TRUE)[1:5] plot(Attr, Rel, type = "n", main = "Attraction and Reliance scores of verbs in Russian Ditransitive Cx") text(Attr, Rel, rownames(ditr), cex = 0.7) plot(sort(Attr, decreasing = TRUE), type = "l", main = "Attraction", ylab = "Attraction, in %") plot(sort(Rel, decreasing = TRUE), type = "l", main = "Reliance", ylab = "Reliance, in %") dP.cueVerb <- a/(a + b) - c/(c + d) dP.cueCx <- a/(a + c) - b/(b + d) pvF <- pv.Fisher.collostr(a, b, c, d) round(head(pvF), 3) logpvF <- ifelse(a < aExp, log10(pvF), -log10(pvF)) round(head(logpvF), 3) -log10(0.05) LL <- LL.collostr(a, b, c, d) LL1 <- ifelse(a < aExp, -LL, LL) random <- sample(0:100, length(a), replace = TRUE) head(random) assoc <- cbind(Attr, Rel, dP.cueCx, dP.cueVerb, logpvF, LL1, random) assoc.cor <- cor(assoc) round(assoc.cor, 3) corrgram(assoc, order = TRUE, lower.panel = panel.shade, upper.panel = panel.pie) corrgram(assoc, order = TRUE, lower.panel = panel.ellipse, upper.panel = panel.pts) assoc.cor1 <- cor(assoc, method = "kendall") round(assoc.cor1, 3) ##Boxes with additional information ggplot(data.frame(Attr, Rel), aes(x = Attr, y = Rel)) + geom_text(label = names(Attr), size = 3)