#I imported using import dataset GUI
##Problem 1
blast = blastForClass
attach(blast)
meansByFactors <- function(x,factorList){tapply(X=x,INDEX=factorList,FUN=mean,na.rm=TRUE)}
blast$T3T0Diff = Test3 -Test0
##1
meansByFactors(blast$T3T0Diff,list(blast$gender,blast$combined.condition))
##2
#I appears that the males better adapted to the learning style, and the ZPD style was the most effective
##3
blastNR = subset(blast,blast$policy!="RANDOM",drop=T)
meansByFactors(blastNR$T3T0Diff,list(blastNR$gender,blastNR$combined.condition))
#We see an increase in learning with the removal of random 
##4
mNR= subset(blastNR,blastNR$gender!="female",drop=T)
fNR= subset(blastNR,blastNR$gender!="male",drop=T)
(aovF=aov(fNR$T3T0Diff~fNR$combined.condition))
(aovM=aov(mNR$T3T0Diff~mNR$combined.condition))
summary(aovF)
##5
#The female standard error is lower allowing me to thinking that the females imformation is more acurrate
##6
install.packages("gmodels")
library(gmodels)
levels(fNR$combined.condition)
contrasts <- rbind("ZPD vs NO" = c(0,-1,1))
fit.contrast( aovF, "fNR$combined.condition", contrasts)                   
##7
contrasts <- rbind("CHOICE_ZPD + CHOICE vs NO_CHOICE" = c(0.5,0.5,-1))
fit.contrast( aovF, "fNR$combined.condition", contrasts)
#The differences are minute and the P value is .0378


##Problem 2
##1

dbar <- function(xA,xB){
  d=0
  num = c(0:length(xA))
  len=length(xA)
  n = sample(num,1)
  d <- d + (xA[n] - xB[n])
  return(d/len)
}
##2
rep=replicate(1000,dbar(mNR$Test3,mNR$Test0))
rep=rep[rep!="numeric(0)"]
rep=unlist(rep)
hist(rep)
(upper3=quantile(rep,.95))
abline(v=upper3,col="red",lw=2)
#yes we can reject it
##3
rep=replicate(1000,dbar(mNR$Test1,mNR$Test0))
rep=rep[rep!="numeric(0)"]
rep=unlist(rep)
hist(rep)
(upper1=quantile(rep,.95))
abline(v=upper1,col="red",lw=2)
#yes we can reject it
