[R] do faster ANOVAS

From: melissa <mellepage_at_orange.fr>
Date: Thu, 10 Jun 2010 15:47:21 +0200 (CEST)

Dear all R users,
I want to realize 800 000 ANOVAS and to store Sum of Squares of the effects. Here is an extract of my table data Product attribute subject rep t1 t2 t3 … t101 P1 A1 S1 R1 1 0 0 … 1
I want to realize 1 ANOVA per timepoint and per attribute, there are 101 timepoints and 8 attributes so I want to realize 808 ANOVAS. This will be an ANOVA with two factors : Here is one example:
Aov(t1~Subject*Product,data[data$attribute==”A1”,]) I want to store for each ANOVA SSprod,SSsujet,SSerreur,SSinter and SStotal. In fact I want the result in several matrices: Ssprod matrice:
T1 t2 t3 t4 … t101
A1 ssprod(A1,T1)

So I would like a matrice like that for ssprod, ssujet,sserreur,ssinter and sstotal. And this is for one permutation, and I want to do 1000 permutations Here is my code:

listmat<-apply(daten.temp[,5:105],2,function(x,y){ tab2<-as.data.frame(cbind(x,y))
tab.class<-by(tab2[,1:3],tab2[,4],function(x){ f <- formula(paste(names(x)[1],"~",names(x)[2],"*",names(x)[3],sep="")) anovas <- aov(f, data=x)
anovas$call$formula <-f
s1 <- summary(anovas)
qa <- s1[[1]][,2]
ar <- array(unlist(listmat),dim=c(length(listmat[[1]][[1]]),length(listmat[[1]]),length(listmat))) l=lapply(1:4,function(i) ar[i,,])


ss=rbind(sssujet,ssprod,ssinter,sserreur,sstotal) ss=as.data.frame(ss)

system.time(por <- lapply(c(1:1000), SSmatrixglobal))

But it takes time about 90seconds for a permutation so *1000, how can I do in order to do faster ANOVAS?

Many thanks
Best regards

PS: I think that I can gain a lot of time in the aov function but I don't know how to do

        [[alternative HTML version deleted]]

R-help_at_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. Received on Thu 10 Jun 2010 - 16:11:02 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Thu 10 Jun 2010 - 17:10:28 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.

list of date sections of archive