Skip to content

FOR loop with statistical analysis for microarray data

4 messages · Sébastien Bihorel, Weidong Gu

#
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:
#
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:
#
Looks like you have problems with indexing. In your code, fc is a
vector of length 2, pv is a scalar(it only keeps the last value of the
loop), then you try to cbind different lengths of vectors
(row.names(y1), fc and pv). cbind only works for vectors with the same
length.

I don't know what you want to achieve, but you can keep p.value using
pv[i]. In the previous code, you reassiged pv before pv[i]. So your
1st assignment of pv wiped out pv vector. You need to read helps about
indexing, vectors.

Weidong
On Thu, Oct 27, 2011 at 10:41 AM, Seb <seba.bat at gmail.com> wrote: