[R] permutation/randomization test assumption on observations

2011-05-21 Thread Wenjin Mao
Hi,

I have two groups of data of different size:
   group A: x1, x2, , x_n;
   group B: y1, y2, , y_m; (m is not equal to n)

The two groups are independent but observations within each group are
not independent,
  i.e., x1, x2, ..., x_n are not independent; but x's are independent from y's

I wonder if randomization test is still applicable to this case; if
so, anything I have to pay attention?

Thank you very much,
Wenjin

__
R-help@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.


Re: [R] permutation/randomization

2008-04-09 Thread Greg Snow
You can randomize the order (permute) of a single column with something
like:

> x <- cbind( x=1:10, y=101:110, z=201:210 )
> rownames(x) <- letters[1:10]
> new.x <- x
> new.x[,1] <- sample(new.x[,1])
> new.x
   x   y   z
a  8 101 201
b 10 102 202
c  5 103 203
d  9 104 204
e  3 105 205
f  1 106 206
g  7 107 207
h  4 108 208
i  2 109 209
j  6 110 210

You could do that for each of the columns that you want randomized.  A
quick way to do a separate randomization on each column is:

> new.x <- apply(x, 2, sample)
> rownames(new.x) <- letters[1:10]
> new.x
   x   y   z
a  2 101 203
b  3 107 204
c  6 102 205
d  1 104 207
e  4 105 208
f  7 108 201
g 10 110 206
h  8 106 209
i  5 103 210
j  9 109 202
> 

Hope this helps,

-- 
Gregory (Greg) L. Snow Ph.D.
Statistical Data Center
Intermountain Healthcare
[EMAIL PROTECTED]
(801) 408-8111
 
 

> -Original Message-
> From: [EMAIL PROTECTED] 
> [mailto:[EMAIL PROTECTED] On Behalf Of Grant Gillis
> Sent: Wednesday, April 09, 2008 12:08 PM
> To: r-help@r-project.org
> Subject: [R] permutation/randomization
> 
> Hello,
> 
> I have what I suspect might be an easy problem but I am new 
> to R and stumped.  I have a data set that looks something like this
> 
> b<-c(2,3,4,5,6,7,8,9)
> x<-c(2,3,4,5,6,7,8,9)
> y<-c(9,8,7,6,5,4,3,2)
> z<-c(9,8,7,6,1,2,3,4)
> data<-cbind(x,y,z)
> row.names(data)<-c('a','b','c','d','e','f','g','h')
> 
> which gives:
> 
>  x y z
> a 2 9 9
> b 3 8 8
> c 4 7 7
> d 5 6 6
> e 6 5 1
> f 7 4 2
> g 8 3 3
> h 9 2 4
> 
> I would like to randomize data within columns. The closest I 
> have been able to come permutes data within the columns but 
> keeps rows together along with row names(example below).  For 
> some context, eventually I would like use this to generate 
> many data sets and perform calculations on these random data 
> sets (I think I know how to do this but we'll see).  So 
> ideally I would like row names to remain the same (in order a 
> through h) and column data to randomize within columns but 
> independently of the other columns.  Just shuffle the data 
> deck I guess
> 
> 
> > data[permute(1:length(data[,1])),]
>   x y z
> b 3 8 8
> c 4 7 7
> h 9 2 4
> e 6 5 1
> f 7 4 2
> a 2 9 9
> g 8 3 3
> d 5 6 6
> 
> 
> Thanks in advance for the help and also for the good advice 
> earlier this week.
> 
> Cheers
> 
>   [[alternative HTML version deleted]]
> 
> __
> R-help@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.
> 

__
R-help@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.


Re: [R] permutation/randomization

2008-04-09 Thread Philipp Pagel
On Wed, Apr 09, 2008 at 11:08:28AM -0700, Grant Gillis wrote:

> I would like to randomize data within columns.

I think the following line does what you want (minus preserving the row
labels):

apply(data, 2, sample)

Maybe someone smarter than me knows how to preserve the row names. I
would probably just steal them from the original data frame:

nam = row.names(data)
apply(data, 2, sample)
row.names(foo) = nam

cu
Philipp

-- 
Dr. Philipp Pagel  Tel.  +49-8161-71 2131
Lehrstuhl für Genomorientierte Bioinformatik   Fax.  +49-8161-71 2186
Technische Universität München
Wissenschaftszentrum Weihenstephan
85350 Freising, Germany
http://mips.gsf.de/staff/pagel

__
R-help@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.


Re: [R] permutation/randomization

2008-04-09 Thread Tobias Verbeke
Grant Gillis wrote:
> Hello,
> 
> I have what I suspect might be an easy problem but I am new to R and
> stumped.  I have a data set that looks something like this
> 
> b<-c(2,3,4,5,6,7,8,9)
> x<-c(2,3,4,5,6,7,8,9)
> y<-c(9,8,7,6,5,4,3,2)
> z<-c(9,8,7,6,1,2,3,4)
> data<-cbind(x,y,z)
> row.names(data)<-c('a','b','c','d','e','f','g','h')
> 
> which gives:
> 
>  x y z
> a 2 9 9
> b 3 8 8
> c 4 7 7
> d 5 6 6
> e 6 5 1
> f 7 4 2
> g 8 3 3
> h 9 2 4
> 
> I would like to randomize data within columns. The closest I have been able
> to come permutes data within the columns but keeps rows together along with
> row names(example below).  For some context, eventually I would like use
> this to generate many data sets and perform calculations on these random
> data sets (I think I know how to do this but we'll see).  So ideally I would
> like row names to remain the same (in order a through h) and column data to
> randomize within columns but independently of the other columns.  Just
> shuffle the data deck I guess
> 
> 
>> data[permute(1:length(data[,1])),]
>   x y z
> b 3 8 8
> c 4 7 7
> h 9 2 4
> e 6 5 1
> f 7 4 2
> a 2 9 9
> g 8 3 3
> d 5 6 6

I changed 'data' to 'mymat' as 'data' is a function in R (see ?data)
and added the row names after permuting:

someMatrix <- cbind(x, y, z)
permutedMat <- apply(someMatrix, 2, sample)
row.names(permutedMat)<-c('a','b','c','d','e','f','g','h')
permutedMat

HTH,
Tobias

__
R-help@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.


[R] permutation/randomization

2008-04-09 Thread Grant Gillis
Hello,

I have what I suspect might be an easy problem but I am new to R and
stumped.  I have a data set that looks something like this

b<-c(2,3,4,5,6,7,8,9)
x<-c(2,3,4,5,6,7,8,9)
y<-c(9,8,7,6,5,4,3,2)
z<-c(9,8,7,6,1,2,3,4)
data<-cbind(x,y,z)
row.names(data)<-c('a','b','c','d','e','f','g','h')

which gives:

 x y z
a 2 9 9
b 3 8 8
c 4 7 7
d 5 6 6
e 6 5 1
f 7 4 2
g 8 3 3
h 9 2 4

I would like to randomize data within columns. The closest I have been able
to come permutes data within the columns but keeps rows together along with
row names(example below).  For some context, eventually I would like use
this to generate many data sets and perform calculations on these random
data sets (I think I know how to do this but we'll see).  So ideally I would
like row names to remain the same (in order a through h) and column data to
randomize within columns but independently of the other columns.  Just
shuffle the data deck I guess


> data[permute(1:length(data[,1])),]
  x y z
b 3 8 8
c 4 7 7
h 9 2 4
e 6 5 1
f 7 4 2
a 2 9 9
g 8 3 3
d 5 6 6


Thanks in advance for the help and also for the good advice earlier this
week.

Cheers

[[alternative HTML version deleted]]

__
R-help@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.