[R] automating aov function

Michael Morley mmorley at mail.med.upenn.edu
Thu May 27 14:46:32 CEST 2004


If you want a matrix (perhaps a data.frame so you can add different data 
types(gene name, accession, etc) of just the F and Ps from each anova.
Something like this works for me. Though I'm a newbie too, so if there 
is a better way someone let me know!
----------------------
#create 2 by # genes matrix, can add row names or col names
#precomputing your matrix will save some computational time as compare 
to rbind
#assume genes is some matrix or data.frame

results <- matrix(ncol=2, nrow=length(genes[,1]))

for(i in 1:length(genes[,1]){
     an <- anova(lm(formula,data))
     results[i,] <- c(an$F[1], an$P[1] )
}

------------------

Don't forget about the multiple testing!

-Mike


Joshi, Nina (NIH/NCI) wrote:

> 
>
>I am running the aov function to determine the linear relationship between
>individual genes and a number of covariates in a micro-array data set.  My
>aov function is working, but I have not been able to write a code to save
>these results in a matrix.  I am using the following code or a slight
>variation of this code:
>
> 
>
>for(i in 1(length(m[1,])-20)
>
> 
>
>{tmp<- aov(m[,i]~treat, data=m)
>
> 
>
>{results [i] <- tmp}}
>
> 
>
>Any help would be appreciated.
>
> 
>
> 
>
>Thanks,
>
> 
>
>Nina
>
> 
>
> 
>
>Nina Joshi, PhD
>
>NIH/NCI/ Genetics Branch
>
>National Naval Medical Center, Bldg. 8, Rm. 5101
>
>8901 Wisconsin Ave.
>
>Bethesda, MD. 20889-5101
>
>(301) 435-5436 - phone
>
>(301) 496-0047 - fax
>
> 
>
> 
>
>
>	[[alternative HTML version deleted]]
>
>______________________________________________
>R-help at stat.math.ethz.ch mailing list
>https://www.stat.math.ethz.ch/mailman/listinfo/r-help
>PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
>  
>

-- 
Michael Morley
Bioinformatics Specialist
University of Pennsylvania
Department of Pediatrics
3516 Civic Center Blvd.,
510B Abramson Pediatric Research Center,
Philadelphia, PA 19104-4318.
Phone: (215) 590-7673
FAX: (215) 590-3709




More information about the R-help mailing list