Skip to content

Instantly share code, notes, and snippets.

@mikelove
Created September 22, 2017 14:59
Show Gist options
  • Save mikelove/9c4245496a54d9cd7a675990e3b06752 to your computer and use it in GitHub Desktop.
Save mikelove/9c4245496a54d9cd7a675990e3b06752 to your computer and use it in GitHub Desktop.
Code to group students to balance across skill sets
x <- read.csv("bios784proj-report.csv")
y <- x[,3:6]
colnames(y) <- c("r","b","s","h")
y$h <- 4 - y$h # convert HW difficulty => comfort
y[10,1] <- 2 # student didn't answer
head(y)
cor(y)
set.seed(1)
grps <- sample(rep(1:9,3))
skill <- sapply(1:9, function(i) colSums(y[grps == i,]))
skill.sd <- apply(skill, 1, sd)
skill.overall.sd <- sd(colSums(skill))
print(round(skill.sd,1))
for (i in 1:2000) {
swap <- sample(1:27, 2, replace=FALSE)
grps.new <- grps
grps.new[swap] <- grps[rev(swap)]
skill.new <- sapply(1:9, function(i) colSums(y[grps.new == i,]))
skill.new.sd <- apply(skill.new, 1, sd)
test <- sum(skill.new.sd - skill.sd)
if (test < .1) {
skill.out <- skill.new
grps <- grps.new
skill.sd <- skill.new.sd
print(round(unname(skill.new.sd),1))
}
}
image(t(rbind(skill, skill.out)[8:1,]), col=colorRampPalette(c("white","blue"))(50), xaxt="n", yaxt="n")
rownames(y) <- x[["Your.onyen."]]
y$grps <- grps
z <- y[order(y$grps),]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment