[R] FOR loop with statistical analysis for microarray data

Seb seba.bat at gmail.com
Thu Oct 27 16:41:06 CEST 2011


thanks for the replies.... so, i remove the indices pv[i] and
fc[i]..but when i run it like this:
===============
fc=0
pv=0
for (i in 1:nrow(data))
{
	
	v1= c(y1[i,1], y1[i,2])	
	v2= c(y2[i,1], y2[1,2])
	fc=v1-v2
	w=t.test(v1,v2)
	pv=w$p.value
}

results = cbind(row.names(y1), fc, pv)

head(results)
=================

i get

===========
Warning message:
In cbind(row.names(y1), fc, pv) :
  number of rows of result is not a multiple of vector length (arg 2)
=============

and the "fc" values are repeated over until the end of the rows and
the "pv" is the same all across the samples...how can i fix it?!

...i apologize if it's a silly situation but i'm new to this and can't
get my head around it!

thanks so much!!







On Thu, Oct 27, 2011 at 9:02 AM, Weidong Gu <anopheles123 at gmail.com> wrote:
> In your loop, you assign, for example, pv twice
> pv=w$p.value # pv is scalar
> pv[i]= w[2]   # pv is a vector
>
> give an example for the point
>
> pv=1
> pv[5]=2
> pv
> [1]  1 NA NA NA  2
>
> This may not be what you want.
>
> Weidong
>
> On Thu, Oct 27, 2011 at 7:40 AM, Seb <seba.bat at gmail.com> wrote:
>> y1,y2 were designed as follow,from the original data file :
>> y1=data[,1:2]
>> y2=data[,3:4]
>>
>> ...I am a bit confused with what "redesign the whole vector again" and
>> "specify indices twice " actually mean?...could u point it out in the
>> script?
>>
>> Thanks so much I really appreciate it!!
>>
>> Sent from my -DROID-
>>
>> On Oct 26, 2011 6:56 PM, "Weidong Gu"  wrote:
>>>
>>> If you provide an example data (y1 and y2 in the loop), you might have
>>> got specific helps already. A few things in your loop seem suspicious.
>>> fc and pv are vectors, and in each loop you redesigned the whole
>>> vectors and specific indices twice. That may cause your problems.
>>>
>>> Weidong Gu
>>>
>>>
>>>
>>> On Wed, Oct 26, 2011 at 4:56 PM, Seb <seba.bat at gmail.com> wrote:
>>> > hi all
>>> >
>>> > i started recently using R and i found myself stuck when i try to
>>> > analyze microarray data.
>>> >
>>> > i use the "affy" package to obtain  the intensities of the probes, i
>>> > have two CTRs and two treated.
>>> >
>>> >  HG.U133A.Experiment1.CEL HG.U133A.Experiment2.CEL
>>> > HG.U133A_Control1.CEL HG.U133A_Control2.CEL
>>> > 1007_s_at               2156.23115                467.75615
>>> >  364.60615             362.11865
>>> > 1053_at                   88.76368                 93.58436
>>> >  438.49365             357.75615
>>> > 117_at                   144.00743                101.26120
>>> >  95.11117             107.01623
>>> > 121_at                   551.36865                639.45615
>>> >  456.66865             435.95615
>>> > 1255_g_at                 65.33164                 18.39570
>>> >  14.22565              20.74632
>>> > 1294_at                  106.19083                169.69369
>>> >  78.15722              81.14689
>>> >
>>> > i divided the first two columns in two data.frames to divide Experim and
>> CTRs
>>> >
>>> > then, i created a FOR loop to create a vector per each row containing
>>> > a vector with two values per each gene and i wanted to do a
>>> > Wilcox.test to obtain the significant genes..BUT i get a list of NULL
>>> > like you can see here
>>> > ..the first row works but then i get NULL down till the end of the
>> array...
>>> >
>>> >                fc        pv
>>> > [1,] "1007_s_at" -20.248   0.4664612
>>> > [2,] "1053_at"   -344.7132 NULL
>>> > [3,] "117_at"    NULL      NULL
>>> > [4,] "121_at"    NULL      NULL
>>> > [5,] "1255_g_at" NULL      NULL
>>> > [6,] "1294_at"   NULL      NULL
>>> >
>>> > the script i used is:
>>> > ===================
>>> > fc=0
>>> > pv=0
>>> > for (i in 1:nrow(data))
>>> > {
>>> >        v1= c(y1[i,1], y1[i,2])
>>> >        v2= c(y2[i,1], y2[1,2])
>>> >        fc=v1-v2
>>> >        w=t.test(v1,v2)
>>> >        pv=w$p.value
>>> >        fc[i]= w[1]
>>> >        pv[i]= w[2]
>>> > }
>>> >
>>> > results = cbind(row.names(y1), fc, pv)
>>> >
>>> > head(results)
>>> >
>>> > ================
>>> >
>>> > what did i do wrong? i can't find a way around this!!!
>>> >
>>> > thanks so much!!!
>>> >
>>> > Seb
>>> >
>>> > ______________________________________________
>>> > R-help at r-project.org mailing list
>>> > https://stat.ethz.ch/mailman/listinfo/r-help
>>> > PLEASE do read the posting guide
>> http://www.R-project.org/posting-guide.html
>>> > and provide commented, minimal, self-contained, reproducible code.
>>> >
>>
>>        [[alternative HTML version deleted]]
>>
>> ______________________________________________
>> R-help at r-project.org mailing list
>> https://stat.ethz.ch/mailman/listinfo/r-help
>> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
>> and provide commented, minimal, self-contained, reproducible code.
>>
>



More information about the R-help mailing list