# NOT RUN {
data(finalDevoicing)
library(rpart)
# ---- CART tree
finalDevoicing.rp = rpart(Voice ~ ., data = finalDevoicing[ , -1])
plotcp(finalDevoicing.rp)
finalDevoicing.pruned = prune(finalDevoicing.rp, cp = 0.021)
plot(finalDevoicing.pruned, margin = 0.1, compress = TRUE)
text(finalDevoicing.pruned, use.n = TRUE, pretty = 0, cex=0.8)
# ---- logistic regression
library(rms)
finalDevoicing.dd = datadist(finalDevoicing)
options(datadist='finalDevoicing.dd')
finalDevoicing.lrm = lrm(Voice ~ VowelType + ConsonantType + Obstruent +
Nsyll + Stress + Onset1Type + Onset2Type, data = finalDevoicing)
anova(finalDevoicing.lrm)
# ---- model simplification
fastbw(finalDevoicing.lrm)
finalDevoicing.lrm = lrm(Voice ~ VowelType + ConsonantType +
Obstruent + Nsyll, data = finalDevoicing, x = TRUE, y = TRUE)
plot(Predict(finalDevoicing.lrm))
# ---- model validation
validate(finalDevoicing.lrm, B = 200)
# }
Run the code above in your browser using DataLab