#################################################################################### #This is a file with executable R code for chapter 14 of Natalia Levshina's (2015) #How to Do Linguistics with R. Amsterdam/Philadelphia: John Benjamins. #################################################################################### ###Section 14.2 ##Main text install.packages("party") library(Rling); library(party) data(caus) mhc <- caus[caus$Cx == "make_V"|caus$Cx == "have_V"|caus$Cx == "cause_toV", ] summary(mhc) mhc$Cx <- factor(mhc$Cx) summary(mhc$Cx) levels(mhc$Cx) <- c("cause", "have", "make") summary(mhc$Cx) set.seed(129) mhc.ctree <- ctree(Cx ~ CrSem + CeSem + CdEv + Neg + Coref + Poss, data = mhc) plot(mhc.ctree) table(predict(mhc.ctree), mhc$Cx) (35 + 42 + 24)/150 set.seed(35) mhc.rf <- cforest(Cx ~ CrSem + CeSem + CdEv + Neg + Coref + Poss, data = mhc, controls = cforest_unbiased(ntree = 1000, mtry = 2)) mhc.varimp <- varimp(mhc.rf, conditional = TRUE) round(mhc.varimp, 3) dotchart(sort(mhc.varimp), main = "Conditional importance of variables") table(predict(mhc.rf), mhc$Cx) (39 + 48 + 13)/150 ##Boxes with additional information mhc.ctree1 <- ctree(Cx ~ CrSem + CeSem + CdEv + Neg + Coref + Poss, data = mhc, controls = ctree_control(testtype = "MonteCarlo", mincriterion = 0.99, minbucket = 15))