Commit 3b9e1c3e authored by Simon Pintarelli's avatar Simon Pintarelli

add example

parent cacd5258
## statistics about grades, points per task grouped by department
max_points_per_task <- c(10, 10, 10, 10) # max. no. of points per task
maxpoints <- sum(max_points_per_task) # max. points
dp <- 0.5 # point interval
dg <- 0.25 # grade interval
## piecewise linear grading scale. If no grade is assigned to 0 or maxpoints,
## it is assumed that they map to grade 1 or 6 respectively.
int_points <- c(0, maxpoints)
int_grades <- c(1, 6)
library(dplyr)
library(ggplot2)
library(reshape)
library(xtable)
## read data
dset <- read.csv('marks.csv', encoding='ISO-8859-1')
dset <- dset[, !(names(dset) %in% c("Last.Name", "First.Name"))]
dset <- melt(dset, id=c("Number", "Direction"))
dset$value <- as.numeric(dset$value)
total_points <- group_by(dset, Number, Direction) %>% summarize(s=sum(value))
linscale <- data.frame(approx(int_points, int_grades, seq(0, maxpoints, by=dp)))
## join grading scale with total_points by using an auxiliary column with integer values
FUZZY <- 1e6
linscale$jj <- as.integer(round(linscale$x*FUZZY))
scale <- data.frame(grade=floor(linscale$y*1/dg)*dg, jj=linscale$jj)
## add integer column to total_points
total_points$jj <- as.integer(round(total_points$s*FUZZY))
grades <- data.frame(left_join(x=total_points, y=scale, by="jj"))
grades <- grades[,c("Number", "Direction", "s", "grade")]
## grade cdf by Direction
ggplot(grades, aes(x=grade, color=Direction)) +
stat_ecdf() +
scale_x_continuous(breaks=seq(1,6, by=1)) +
coord_cartesian(xlim=c(1,6))
## grade density by Direction
dev.new()
ggplot(grades, aes(x=grade, color=Direction)) +
geom_density(trim=TRUE) +
coord_cartesian(xlim=c(1,6))
## mark density by Direction
dev.new()
ggplot(dset, aes(x=value, color=Direction)) +
geom_density(trim=TRUE) +
facet_wrap(~variable) +
xlab("Points")
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment