[R] stack overflow

Thomas W Blackwell tblackw at umich.edu
Fri Sep 5 22:34:12 CEST 2003


Bill  -

Here's what I would do, starting after your display of  anovaresults[[1]].

temp.1 <- unlist(lapply(anovaresults, function(x) { x["Pr(>F)"][1:3],] }))
temp.2 <- matrix(temp.1, length(anovaresults), 3, byrow=T)
dimnames(temp.2) <- list(names(anovaresults),
	 	 	 dimnames(anovaresults[[1]])[[1]][1:3])
rm("anovaresults")
pvalues <- data.frame(temp.2)

Another suggestion is to do the subscripting that extracts the
single column of p-values inside your function  aof().  Then the
list returned by  apply()  will be much smaller and have a simpler
structure.

HTH  -  tom blackwell  -  u michigan medical school  -  ann arbor  -

On Fri, 5 Sep 2003, William Noble wrote:

> I am trying to do an ANOVA on a microarray data set consisting of
> 22690 elements.  The ANOVA is fine, but when I try to put the data in
> a frame in order to exporting it, I get a stack overflow.  I have
> found documentation on dynamic memory in R, but not on how to increase
> the stack size.  The code I'm using is below.  If anyone has any
> suggestions for a workaround here, I'd appreciate it.
>
> Thank you.
> Bill Noble
> ------------
>
> > invisible(options(echo = TRUE))
> > sdata <- read.table("../../data/02-09-03/data.mtx", header=T, row.names=1)
> > infection <- gl(2,8,16, label=c("no infection", "infection"))
> > labor <- gl(2,4,16, label=c("no labor", "labor"))
> > aof <- function(x) {
> +   m <- data.frame(infection, labor, x);
> +   anova(aov(x ~ infection + labor + infection*labor, m))
> + }
> > anovaresults <- apply(sdata, 1, aof)
> > pvalues <- data.frame(lapply(anovaresults, function(x) { x["Pr(>F)"][1:3,] }))
> Error: protect(): stack overflow
> >
> > anovaresults[[1]]
> Analysis of Variance Table
>
> Response: x
>                 Df Sum Sq Mean Sq F value  Pr(>F)
> infection        1   9082    9082  0.2315 0.63907
> labor            1  98722   98722  2.5164 0.13865
> infection:labor  1 143262  143262  3.6517 0.08019 .
> Residuals       12 470776   39231
> ---
> Signif. codes:  0 `***' 0.001 `**' 0.01 `*' 0.05 `.' 0.1 ` ' 1
> >
> > temp <- lapply(anovaresults, function(x) { x["Pr(>F)"][1:3,] })
> > length(temp)
> [1] 22690
> > temp[1]
> $"AFFX-BioB-5_at"
>          1          2          3
> 0.63906707 0.13865289 0.08018914
> > gc(verbose=TRUE)
> Garbage collection 62 = 23+6+33 (level 2) ...
> 1430471 cons cells free (28%)
> 17.4 Mbytes of heap free (32%)
>           used (Mb) gc trigger  (Mb)
> Ncells 3249183 86.8    4953636 132.3
> Vcells 4749443 36.3    7025348  53.6
> > pvalues <- data.frame(temp)
> Error: protect(): stack overflow
> > gc(verbose=TRUE)
> Garbage collection 63 = 23+6+34 (level 2) ...
> 1636368 cons cells free (33%)
> 19.5 Mbytes of heap free (34%)
>           used (Mb) gc trigger  (Mb)
> Ncells 3317268 88.6    4953636 132.3
> Vcells 4794917 36.6    7353029  56.1
>




More information about the R-help mailing list