Re: [R] do faster ANOVAS

From: Douglas Bates <bates_at_stat.wisc.edu>
Date: Thu, 10 Jun 2010 11:52:55 -0500

The lm and aov functions can take a matrix response allowing you to fit all of the responses for a single attribute simultaneously.

On Thu, Jun 10, 2010 at 8:47 AM, melissa <mellepage_at_orange.fr> wrote:
> 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)
> A2
> A3
> …
> A8
> 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:
> SSmatrixglobal<-function(k){
>
> daten.temp<-data
> daten.temp$product=permutations[[k]]
> 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]
> return(qa)
> })
> return(tab.class)
> },y=daten.temp[,1:3]
> )
> ar <- array(unlist(listmat),dim=c(length(listmat[[1]][[1]]),length(listmat[[1]]),length(listmat)))
> l=lapply(1:4,function(i) ar[i,,])
> sssujet=l[[1]]
> ssprod=l[[2]]
> ssinter=l[[3]]
> sserreur=l[[4]]
> ss=rbind(sssujet,ssprod,ssinter,sserreur,sstotal)
> ss=as.data.frame(ss)
> sqlSave(channel,ss,"SS1000",append=T)
> rm(ss,numperm,daten.temp)
> }
>
> 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
> Mélissa
>
> 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.
>
>



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:55:11 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 Mon 14 Jun 2010 - 15:30:29 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