Description Usage Author(s) Examples
Some variables, like occupations have natural hirarchical structure.
Function plotHTree() allows to plot the performance against this structure.
1 |
Przemyslaw Biecek
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 | library(PISA2009lite)
# two and one digits out of parent occupation
father <- substr(as.character(student2009$ST13Q01),1,2)
mother <- substr(as.character(student2009$ST09Q01),1,2)
father1 <- substr(as.character(student2009$ST13Q01),1,1)
mother1 <- substr(as.character(student2009$ST09Q01),1,1)
# names of groups
groups <- sort(na.omit(unique(c(father, mother))))
groups1 <- sort(na.omit(unique(c(father1, mother1))))
# sizes of two digits groups
sizes <- unclass(by(cbind(father, mother, student2009[,c("PV1MATH", "W_FSTUWT")]),
student2009$CNT,
function(x) {
prop.table(sapply(groups, function(group) {
sum(x[which(x[,1] == group | x[,2] == group),4], na.rm=TRUE)
}))
}))
# performance in two digits groups
perfMATH <- unclass(by(cbind(father, mother, student2009[,c("PV1MATH", "W_FSTUWT")]),
student2009$CNT, function(x) {
sapply(groups, function(group) {
inds <- which(x[,1] == group | x[,2] == group)
weighted.mean(x[inds, 3], x[inds, 4], na.rm=TRUE)
}) }))
# performance in one digit groups
perfMATH1 <- unclass(by(cbind(father1, mother1, student2009[,c("PV1MATH", "W_FSTUWT")]),
student2009$CNT, function(x) {
sapply(groups1, function(group) {
inds <- which(x[,1] == group | x[,2] == group)
weighted.mean(x[inds, 3], x[inds, 4], na.rm=TRUE)
}) }))
plotHTree(level2 = perfMATH[["Poland"]],
level1 = perfMATH1[["Poland"]],
sizes = sizes[["Poland"]] * 10,
labels = ISCO88[paste(groups, "00", sep="")])
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.