# NOT RUN {
data(beans)
# fit tree based on pairwise comparisons with variety B
pairB <- data.frame(Winner = ifelse(beans$var_b == "Worse",
"Local", beans$variety_b),
Loser = ifelse(beans$var_b == "Worse",
beans$variety_b, "Local"),
stringsAsFactors = FALSE, row.names = NULL)
beans$G <- as.rankings(pairB, input = "orderings",
index = rep(seq(nrow(beans)), 1))
mod <- pltree(G ~ ., data = beans[c("G", "maxTN")])
coef(mod, node = 3)
AIC(mod)
# treat first row from each year as new data
newdata <- beans[!duplicated(beans$year),]
## fitted probabilities
predict(mod, newdata)
## fitted log-abilities, with Local as reference
predict(mod, newdata, log = TRUE, ref = "Local")
## variety ranks
predict(mod, newdata, type = "rank")
## top ranked variety
predict(mod, newdata, type = "best")
## node the trial belongs to
predict(mod, newdata, type = "node")
# }
Run the code above in your browser using DataCamp Workspace