[R] How to repeat 2 functions in succession for 400 times? (microarray data)
arun
smartpink111 at yahoo.com
Sat May 11 21:33:29 CEST 2013
Hi David,
Yes.
Both are similar in speed.
set.seed(48)
system.time({fourPGCs <- replicate(400, { permutation<-sample(mydata4)
PGC <- (rowMeans(permutation[ ,1:27]) -
rowMeans( permutation[ ,28:38]))/
(rowSds( permutation [,1:27]) + rowSds( permutation [,28:38]))
}
)})
# user system elapsed
# 3.712 0.000 3.723
set.seed(48)
system.time({res<-do.call(cbind,lapply(1:400, function(i) {permutation<-sample(mydata4); (rowMeans(permutation[,1:27])-rowMeans(permutation[,28:38]))/(rowSds(permutation[,1:27])+rowSds(permutation[,28:38]))} )) })
# user system elapsed
# 3.624 0.000 3.632
identical(fourPGCs,res)
#[1] TRUE
A.K.
----- Original Message -----
From: David Winsemius <dwinsemius at comcast.net>
To: arun <smartpink111 at yahoo.com>
Cc: R help <r-help at r-project.org>
Sent: Saturday, May 11, 2013 2:31 PM
Subject: Re: [R] How to repeat 2 functions in succession for 400 times? (microarray data)
On May 11, 2013, at 9:21 AM, arun wrote:
> Hi,
> May be this helps:
>
> set.seed(24)
> mydata4<- as.data.frame(matrix(sample(1:100,10*38,replace=TRUE),ncol=38))
> dim(mydata4)
> #[1] 10 38
> library(matrixStats)
> res<-do.call(cbind,lapply(1:400, function(i) {permutation<-sample(mydata4); (rowMeans(permutation[,1:27])-rowMeans(permutation[,28:38]))/(rowSds(permutation[,1:27])+rowSds(permutation[,28:38]))} ))
> dim(res)
> #[1] 10 400
>
>
> A.K.
>
>> I want to do permutation test and then get a PGC score 400 times on mydata4 (microarray data)
>>
>> I use 2 functions as below:
>> 1. permutation<-sample(mydata4)
>> 2. PGC <- (rowMeans(permutation[ ,1:27]) - rowMeans(permutation[
> ,28:38]))/ (rowSds(permutation [,1:27]) + rowSds(permutation [,28:38]))
>>
>> What should I do to repeat these 2 functions in succession for
> 400 times and combine (cbind?) the 400 PGC score for the 7129 genes in
> one file?
Couldn't that just be:
fourPGCs <- replicate(400, { permutation<-sample(mydata4)
PGC <- (rowMeans(permutation[ ,1:27]) -
rowMeans( permutation[ ,28:38]))/
(rowSds( permutation [,1:27]) + rowSds( permutation [,28:38]))
}
--
David Winsemius
Alameda, CA, USA
More information about the R-help
mailing list