library(DAAG) # has permutation test function pr=c("to","to","c","c","c","c","c","c","c","c","c","to","c","to","c","c","to","to") po=c("mc","mc","l","l","mc","l","l","l","l","l","l","mc","l","mc","l","l","mc","mc") hw=c(22,15,7,10,10,15,14,10,20,20,5,14,20,10,5,10,15,10) ex=c(5,15,4,4,10,5,0,6,5,7,1,6,90,3,3,5,0,14) ex[13]=floor(median(ex)) # replace '90' with imputed value # Exercise by polical idealogy boxplot(ex~po,ylab="exercise hrs/week",names=c("liberal","moderate/conservative")) twot.permutation(ex[po=="l"],ex[po=="mc"]) t.test(ex[po=="l"],ex[po=="mc"]) var.test(ex[po=="l"],ex[po=="mc"]) # Exercise by 2016 presidential choice boxplot(ex~pr,ylab="exercise hrs/week",names=c("Clinton","Trump/Other")) twot.permutation(ex[pr=="c"],ex[pr=="to"]) t.test(ex[pr=="c"],ex[pr=="to"]) var.test(ex[pr=="c"],ex[pr=="to"]) # Homework by polical idealogy boxplot(hw~po,ylab="homework hrs/week",names=c("liberal","moderate/conservative")) twot.permutation(hw[po=="l"],hw[po=="mc"]) t.test(hw[po=="l"],hw[po=="mc"]) var.test(hw[po=="l"],hw[po=="mc"])