Skip to content

Instantly share code, notes, and snippets.

@wjhopper
Last active August 29, 2015 14:08
Show Gist options
  • Save wjhopper/9ccaa3516256e833ce29 to your computer and use it in GitHub Desktop.
Save wjhopper/9ccaa3516256e833ce29 to your computer and use it in GitHub Desktop.
Psyc240_HWanalysis. Compare means across TA's
hwanalysis <- function(hwnumber = NULL, base_graphing=FALSE) {
# A standalone R function, so to use it, use source("hwanalysis.R") from the command line and then call hwanalysis() with
# 1). the numeric number of the HW you want to analyze grades for and
# 2). the graphing style you want. The default base_graphing= FALSE uses ggplot (requires ggplot2 and dplyr be
# installed). base_graphing=TRUE gives you old school base R plots, thus no additional dependencies. (but we should all
# have ggplot2 and dplyr anyway right?)
if (is.null(hwnumber)) {
stop('hwnumber must be an integer which defines which hw you want to analyze grades for!')
}
hw <- read.csv(file.choose())
hw <- hw[hw$Lab.instr!='NULL',]
col <- paste('HW',as.character(hwnumber),sep='')
aov.hw <- aov(hw[[col]] ~ hw$Lab.instr)
if (base_graphing==TRUE) {
#base
par(mfrow = c(2,2))
hist(hw[hw$Lab.instr == "Andrea",col], breaks = 20, main = "Andrea", xlab = col)
hist(hw[hw$Lab.instr == "Fiona",col], breaks = 20, main = "Fiona", xlab = col)
hist(hw[hw$Lab.instr == "Wanette",col], breaks = 20, main = "Wanette", xlab = col)
hist(hw[hw$Lab.instr == "Will",col], breaks = 20, main = "Will", xlab = col)
} else if (base_graphing == FALSE) {
#new school
library(ggplot2)
p <- ggplot(hw, aes(x=HW6,fill=Lab.instr))+
geom_histogram(alpha=.6,position='identity',binwidth=2.5)
# use this if you don't want to source by hand and include the print.eval=T option
print(p)
library(dplyr)
# means by TA
call <- substitute(summarise(group_by(hw, Lab.instr),mean_score=round(mean(col, na.omit=T), 1)),
list(col = as.name(col)))
tmp<-eval(call)
print(tmp)
}
print(summary(aov.hw))
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment