###################################################
### chunk number 1: 
###################################################
library(tspair)
data(tspdata)
dim(dat)


###################################################
### chunk number 2: 
###################################################
tsp1 <- tspcalc(dat,grp)
tsp1


###################################################
### chunk number 3: 
###################################################
tsp2 <- tspcalc(eSet1,grp)
tsp3 <- tspcalc(eSet1,1)


###################################################
### chunk number 4: 
###################################################
tspplot(tsp1)


###################################################
### chunk number 5: 
###################################################
out <- tspsig(dat,grp,B=50,seed=12355)
out$p
out$nullscores


###################################################
### chunk number 6: 
###################################################
summary(tsp1,printall=TRUE) 


###################################################
### chunk number 7: 
###################################################
predict(tsp1,eSet2)
predict(tsp1,dat2)


###################################################
### chunk number 8: 
###################################################
narrays <- ncol(dat)
correct.prediction <- rep(TRUE,narrays)

for(i in 1:narrays){
	testdat <- dat[ , -i]
	testgrp <- grp[-i]
	tsptest <- tspcalc(testdat,testgrp)
	prediction <- predict(tsptest,dat)[i]
	correct.prediction[i] <- prediction == grp[i]
}
cv.error <- mean(correct.prediction==FALSE)
cv.error