[R] apply, t-test and p-values

2008-10-16 Thread John Sorkin
R 2.7.2 Windows XP I am using apply to compute a series of Student's t-test from two matrices, sample1 and sample2. boo-apply(sample1,1,t.test,sample2) I want to pick of the p-values from the tests, but can't seem to get it to work. I have tried several methods to get the values including:

Re: [R] apply, t-test and p-values

2008-10-16 Thread Jorge Ivan Velez
Dear John, Yes. Assuming that 'sample2' is fixed, something like this should do what you want: # Data sets set.seed(123) sample1=matrix(rnorm(100),ncol=10) sample2=rnorm(10,5,4) # t-test p-values apply(X,1,function(x) t.test(x,sample2)$p.value) [1] 0.002348970 0.004733230 0.004810952 0.004907549

Re: [R] apply, t-test and p-values

2008-10-16 Thread David Winsemius
On Oct 16, 2008, at 8:11 AM, Jorge Ivan Velez wrote: Dear John, Yes. Assuming that 'sample2' is fixed, something like this should do what you want: # Data sets set.seed(123) sample1=matrix(rnorm(100),ncol=10) sample2=rnorm(10,5,4) # t-test p-values apply(X,1,function(x)

Re: [R] apply, t-test and p-values

2008-10-16 Thread Jorge Ivan Velez
Thanks for the correction David! You're absolutely right! A typo :- ) ... Cheers, Jorge On Thu, Oct 16, 2008 at 10:00 AM, David Winsemius [EMAIL PROTECTED]wrote: On Oct 16, 2008, at 8:11 AM, Jorge Ivan Velez wrote: Dear John, Yes. Assuming that 'sample2' is fixed, something like this

Re: [R] apply, t-test and p-values

2008-10-16 Thread John Sorkin
Jorge, David, Thank you for a brilliant solution to my problem! Thanks John John David Sorkin M.D., Ph.D. Chief, Biostatistics and Informatics University of Maryland School of Medicine Division of Gerontology Baltimore VA Medical Center 10 North Greene Street GRECC (BT/18/GR) Baltimore, MD

Re: [R] apply, t-test and p-values PREVIOUS SUGGESTION DID NOT WORK

2008-10-16 Thread John Sorkin
Although I am grateful to Jorge and David for their suggestions, their solution will not solve my problem as sample2 is not fixed. Let me demonstrate what I want to do: # Define two matricies sample1-matrix(data=c(1:20),byrow=TRUE,ncol=5,nrow=4) sample2-sample1+rnorm(20) These are the

Re: [R] apply, t-test and p-values PREVIOUS SUGGESTION DID NOT WORK

2008-10-16 Thread Gábor Csárdi
How about the following? sapply(1:nrow(sample1), function(x) t.test(sample1[x,], sample2[x,])$p.value) Gabor On Thu, Oct 16, 2008 at 6:07 PM, John Sorkin [EMAIL PROTECTED] wrote: Although I am grateful to Jorge and David for their suggestions, their solution will not solve my problem as

Re: [R] apply, t-test and p-values PREVIOUS SUGGESTION DID NOT WORK

2008-10-16 Thread Jorge Ivan Velez
Dear John, Perhaps is possible to do the job using apply or any of its friends. For now, here is a solution using for() : # Data sets set.seed(123) sample1-matrix(data=c(1:20),byrow=TRUE,ncol=5,nrow=4) sample2-sample1+rnorm(20) # t-test p-values k=nrow(sample1) res=NULL for(i in 1:k)