library(MASS) set.seed(123) iter <- NULL g1 <- NULL tsum1 <- NULL post1 <- NULL tsum1i <- NULL post1i <-NULL g2 <- NULL tsum2 <- NULL post2 <- NULL tsum2i <- NULL post2i <- NULL for(i in 1:500){ # Randomly select 9 ALL cases and 3 AML cases r.chips <- c(sample(1:27, 9), sample(28:38, 3)) train <- train[-r.chips,] indep <- train[r.chips,] ### One Gene Model Search ### grp <- c(rep(1, 18), rep(2, 8)) gene <- NULL run1 <- SCVD(train) df.sort1 <- SortMat(Mat=run1, Sort=c(1,2)) geneI <- as.numeric(row.names(df.sort1))[7129] g1[i] <- geneI grp <- c(rep(1, 18), rep(2, 8)) gene <- lXmat[,geneI] run2 <- SCVD(lXmat[,-geneI]) df.sort2 <- SortMat(Mat=run2, Sort=c(1,2)) bb <- as.numeric(row.names(df.sort2))[7128] geneI.2 <- ifelse(bb < geneI, bb, bb+1) iter[i] <- i grpf <- factor(grp, levels=1:2, labels = c("Positive", "Negative")) G1 <- matrix(lXmat[,geneI]) f1 <- qda(G1, grpf, cv=T) tsum1[i] <- df.sort1[7129,1] post1[i] <-df.sort1[7129,2] # Check its performance on the independent set idata <- data.frame(indep[,geneI]) ip1 <- predict(f1, idata) tsum1i[i] <- sum(ip1$class[1:9] == "Positive") + sum(ip1$class[10:12] == "Negative") post1i[i] <- (prod(ip1$posterior[1:9])*prod(ip1$posterior[10:12])) G2 <- train[,c(geneI,geneI.2)] f2 <- qda(G2, grpf, cv=T) p2 <- predict(f2) tsum2[i] <- df.sort2[7128,1] post2[i] <- df.sort2[7128,2] # Check its performance on the independent set idata2 <- data.frame(indep[,c(geneI,geneI.2)]) ip2 <- predict(f2, idata2) tsum2i[i] <- sum(ip2$class[1:9] == "Positive") + sum(ip2$class[10:12] == "Negative") post2i[i] <- (prod(ip2$posterior[1:9])*prod(ip2$posterior[10:12])) } out <- cbind(iter, g1, tsum1, post1, tsum1i, post1i, g2, tsum2, post2, tsum2i, post2i) ### To write this as a comma separated file use the following line. write.table(out, file="out.csv", sep=",")