[BioC] average replicate columns in a matrix
Yi, Ming (NIH/NCI) [C]
yiming at mail.nih.gov
Wed Mar 30 20:10:57 CEST 2011
Dear Dr. Gordon:
I saw your reply as below to somebody's question in the BioC mailing list. I already get the password to the list, which is why I can see the list's email, but I still have to wait on the list moderator to review my request for approval and my message is being held because of that. So I copied and pasted my original message send to the list as below and hope you can give me a quick answer or suggestion. Thanks a lot in advance!
Hi, List:
I have a question regarding paired samples test in limma package.
Here is what I got
####W and B are race
####T and N are tumor and normal(paired by same Samples), respectively ####Samples are individual patients: tar$AccNum######## ####
> library(limma);
> tar<-readTargets("Test_Desc.txt");
> mydata<-read.delim("TestData.txt",as.is=TRUE,row.names=1);
> mydata<-mydata[,tar$mRNASampleNames];
> tar$Type<-gsub("Tumor","T",tar$Type)
> tar$Type<-gsub("Normal","N",tar$Type)
> group1<-paste(tar$RACE,tar$Type,sep=".");
> group<-factor(group1, levels=c( "W.T","W.N","B.T","B.N"))
> Samples<-factor(tar$AccNum);
####first option to set up the design matrix#########
> design<-model.matrix(~Samples+group);
> colnames(design)<-sub("group","",colnames(design));
> colnames(design)<-sub("Samples","",colnames(design));
> colnames(design)[1] <- "Intercept";
> con.matrix<-makeContrasts(AA.T_AA.N=B.T-B.N,EA.T_EA.N=-W.N,levels=desi
> gn);
> lmFit(mydata,design)->fit1;
Coefficients not estimable: B.N
Warning message:
Partial NA coefficients for 26804 probe(s)
> contrasts.fit(fit1, con.matrix)->fit2
Error in contrasts.fit(fit1, con.matrix) :
trying to take contrast of non-estimable coefficient ################it did not work!!! not sure why??#########
##########then I tried the 2nd option to set up the design matrix####
> design<-model.matrix(~-1+group+Samples);
> colnames(design)<-sub("group","",colnames(design));
> colnames(design)<-sub("Samples","",colnames(design));
> con.matrix<-makeContrasts(AA.T_AA.N=B.T-B.N,EA.T_EA.N=W.T-W.N,levels=d
> esign);
> lmFit(mydata,design)->fit1;
Coefficients not estimable: S14810
Warning message:
Partial NA coefficients for 26804 probe(s)
> contrasts.fit(fit1, con.matrix)->fit2
> eBayes(fit2)->fit3
>
#######it works somehow in terms of generating lists, but leave an warning message when I did the fit1 using > lmFit(mydata,design)->fit1 (...Coefficients not estimable: S14810) I am sure why is like this? Using some other dataset, I didn't see such warning at all. It seems dataset specific, I am not sure why there is warning here and whether the list come out is good or not.
Could someone please have some suggestions?
Thanks in advance!
Ming
Ming Yi
ABCC/ISP
National Cancer Institute at Frederick
Post Office Box B,
Frederick, MD 21702
Phone: 301-846-5764
Fax: 301-846-7070
myi at ncifcrf.gov
-----Original Message-----
From: Gordon K Smyth [mailto:smyth at wehi.edu.au]
Sent: Tuesday, March 29, 2011 6:15 PM
To: Zhu, Lihua (Julie)
Cc: Wendy Qiao; Bioconductor mailing list
Subject: Re: [BioC] average replicate columns in a matrix
Dear Julie,
Do you mean computing the sum of the replicate columns rather than the
mean? You can essentially do that with a call to rowsum() on the
transposed matrix.
Best wishes
Gordon
On Tue, 29 Mar 2011, Zhu, Lihua (Julie) wrote:
> Dear Gordon,
>
> Is there a corresponding method for sum over replicate arrays? Thank you so
> much for your help!
>
> Best regards,
>
> Julie
>
>
> On 3/28/11 6:08 PM, "Gordon K Smyth" <smyth at wehi.EDU.AU> wrote:
>
>> Dear Wendy,
>>
>> The function avearrays() in the limma package does exactly this:
>>
>>> library(limma)
>>> avearrays(test)
>> A B
>> [1,] 2.5 10
>> [2,] 3.5 11
>> [3,] 4.5 12
>>
>> Best wishes
>> Gordon
>>
>>> Date: Sun, 27 Mar 2011 19:25:29 -0400
>>> From: Wendy Qiao <wendy2.qiao at gmail.com>
>>> To: bioconductor at r-project.org
>>> Subject: [BioC] average replicate columns in a matrix
>>> Message-ID:
>>>
>>> I have a matrix like following
>>>
>>>> test=matrix(c(1:15),nrow=3,ncol=5)
>>>> colnames(test)=c("A","A","B","B","B")
>>>> test
>>> A A B B B
>>> [1,] 1 4 7 10 13
>>> [2,] 2 5 8 11 14
>>> [3,] 3 6 9 12 15
>>>
>>> I want to calculate the average of each replicates, ie. I want the output to
>>> be
>>> A B
>>> [1,] 2.5 10
>>> [2,] 3.5 11
>>> [3,] 4.5 12
>>>
>>> I can do this by looping through each level of the column name, but I was
>>> wondering if there is a function for calculating the average of replicates
>>> in one step.
>>>
>>> Thank you in advance.
>>> Wendy
______________________________________________________________________
The information in this email is confidential and intend...{{dropped:9}}
More information about the Bioconductor
mailing list