[R] help with parallel processing code

1Rnwb sbpurohit at gmail.com
Thu Oct 27 14:50:47 CEST 2011


Hello R gurus,

I have the code below for which i need help and pointers to make it run in
parallel on a dual core win7 computer with R 2.13.x, using foreach,
iterators,doMC.
library(scatterplot3d) # Loads 3D library.
library(fields)
library(MASS)
library(ROCR)
library(verification)
library(caret)
library(gregmisc)

##simulated data
d=replicate(9, rnorm(40)+10) 
colnames(d)<-c("LEPTIN","SAA","PTH","sEGFR","IGFBP6","MMP2","OPG","IGFBP3","PDGFAABB")
mols=c("LEPTIN","SAA","PTH","sEGFR","IGFBP6","MMP2","OPG","IGFBP3","PDGFAABB")

####Name of the results output
  
file1="AUCvalues_3plex.csv"
  temp1=c('protein comb', 'AUC')
  pdf('ROC Charts-3plex.pdf')
 
#generate combinations
  pc3 = combinations(n=length(mols),r=3)
 
#runing the combinations
  for (len in 1:dim(pc3)[1])
   {
      prs = pc3[len,]
     
## new data mat
 samples <- mols[prs]
 mat <-data [,c(samples,'Self_T1D')]
 mat<-mat[complete.cases(mat),]
 
##### LDA #########
 rows<- c(1:nrow(mat))
 
 scores <- c()
 labels <-c()
 for (itr in 1:1000)
 {
 train <- sample(rows, length(rows)-1)
 label =0 ; if (mat$Self_T1D[-train] == "N") label = 1  #need the value for
this line, should it be 'N' or 'Y'
 z <- lda(Self_T1D ~ ., mat, subset = train)
 score = predict(z, mat[-train, ])$pos[1]
 scores <- c(scores, score) 
 labels<- c(labels, label) 
 }
 
########## ROC #########
 
 pred <- prediction(scores, labels)
 perf <- performance(pred,"tpr", "fpr")
 plot(perf,colorize = F)
 # plot a ROC curve for a single prediction run
 # with CI by bootstrapping and fitted curve
 #roc.plot(labels,scores, xlab = "False positive rate",
 #ylab = "True positive rate", main = NULL, CI = T, n.boot = 100, plot =
"both", binormal = TRUE)
 auc <- as.numeric(performance(pred, measure = "auc", x.measure =
"cutoff")@y.values)
 auc = round(auc,3)
      text(.9,0,paste("  AUC=", auc, sep=" "), cex=1)
 names1 = paste (samples, collapse="+")
 text(.8,.05,names1, cex=0.75)
      temp = c(names1,  auc)
      temp1 = rbind(temp1 , temp)
print(paste(3,' ','done len=',len," ",names1,' ',date(),sep=''))
   }

dev.off()
write.csv(temp1 , file=file1)

Thanks
sharad


--
View this message in context: http://r.789695.n4.nabble.com/help-with-parallel-processing-code-tp3944303p3944303.html
Sent from the R help mailing list archive at Nabble.com.



More information about the R-help mailing list