#### Assume the testing data is called TestZM, with column 21 as your prediction of strength #### So the horse with max strength value within a race will be predicted as the winner. #### For a copy of the TestZM data (which only have 15 col) please try www.ms.uky.edu/~mai/sta705/ZhouMai.csv #### You need to compute your predicted strength and add to TestZM as the last column, etc. bank <- 0 DV <- rle(TestZM[,2])$lengths DV <- cumsum(DV) N <- length(DV) DV <- c(0,DV) for(i in 1:N) { temp <- TestZM[(DV[i]+1):DV[i+1], ] RV <- rle(temp[,4])$lengths RV <- cumsum(RV) nh <- length(RV) RV <- c(0,RV) for(j in 1:nh) { temp2 <- temp[(RV[j]+1):RV[j], ] win <- which.max(temp2[ , 21]) ## assume col 21 is x%*%b, the strength out <- temp2[win,6] if(out == 1) bank <- bank + 1 if(out == 2) bank <- bank + 0.3 if(out == 3) bank <- bank + 0.1 } } print(bank)