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) res[i]=t.t
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 s
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 comput
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 21201-1
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 li
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) t.test(x,sample2)$p
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
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:
bo
8 matches
Mail list logo