Julia_2010
2010-Apr-03 00:06 UTC
[R] Writing summary.aov results to a file which can be opened in Excel
Hi everyone, I'm fairly new to R (and this forum!), so first of all apologies if this question has already been answered (I've tried searching the forum but haven't come across anything which has solved the problem I'm having). I have a data frame containing an "independent variable" and a series of potential "dependent variables", and I'd like to find the "dependent variable" with the strongest association to my "independent variable" (essentially my "dependent variables" are principal components and the "independent variable" is a systemic factor which may correlate with one/several of the PCs and account for batch effects seen in the data I'm working with. There may be a better way of getting at this but if there is I don't know it!). Searching through a number of different forums, I decided that the manova command might be appropriate for my purposes. I've carried out a MANOVA in R as follows: depvariablesmatrix <-cbind(variables[,6:1248]) #produce a data frame containing my dependent variables MANOVA <- manova(as.matrix(depvariablesmatrix) ~ as.factor(variables$independentvariable)) I can access the results of this using the following: MANOVA_results <-summary.aov(MANOVA) This produces a list of all my results in the following format: Response depvariable1 : Df Sum Sq Mean Sq F value Pr(>F) as.factor(variables$independentvariable) 55 0.58179 0.01058 30.024 < 2.2e-16 *** Residuals 1187 0.41821 0.00035 --- Signif. codes: 0 ?***? 0.001 ?**? 0.01 ?*? 0.05 ?.? 0.1 ? ? 1 Response depvariable2: Df Sum Sq Mean Sq F value Pr(>F) as.factor(variables$independentvariable) 55 0.78587 0.01429 79.207 < 2.2e-16 *** Residuals 1187 0.21413 0.00018 --- Signif. codes: 0 ?***? 0.001 ?**? 0.01 ?*? 0.05 ?.? 0.1 ? ? 1 Response depvariable3 : Df Sum Sq Mean Sq F value Pr(>F) as.factor(variables$independentvariable) 55 0.41267 0.00750 15.164 < 2.2e-16 *** Residuals 1187 0.58733 0.00049 --- Signif. codes: 0 ?***? 0.001 ?**? 0.01 ?*? 0.05 ?.? 0.1 ? ? 1 ....etc for all my 1243 potential dependent variables. What I'd like to do is write these in a table format so that I can open these results in Excel, (essentially to sort by Pr(>F)), however when I try to write these results to a file I get the following error: Error in as.data.frame.default(x[[i]], optional = TRUE, stringsAsFactors stringsAsFactors) : c("cannot coerce class \"summary.aov\" into a data.frame", "cannot coerce class \"listof\" into a data.frame") I've tried using capture.output instead of write.table, however this doesn't produce a tab-delimited file I can sort in Excel. Would anyone be able to tell me how to write these results to a tab-delimited file which I can open and sort in Excel? I'd appreciate any help or advice you can offer. Thanks! Julia -- View this message in context: http://n4.nabble.com/Writing-summary-aov-results-to-a-file-which-can-be-opened-in-Excel-tp1749775p1749775.html Sent from the R help mailing list archive at Nabble.com.
Sam Albers
2010-Apr-03 16:37 UTC
[R] Writing summary.aov results to a file which can be opened in Excel
Julia, I think exporting to excel takes you a step back. Likely it would be easier to work solely in R and sort the P values like that. I had to do something similar only with a bunch of regressions a while back. I found this post extremely helpful as well as the plyr package http://www.r-bloggers.com/r-calculating-all-possible-linear-regression-models-for-a-given-set-of-predictors/ Not much help I realize but maybe it will point you in the right path. Sam -- View this message in context: http://n4.nabble.com/Writing-summary-aov-results-to-a-file-which-can-be-opened-in-Excel-tp1749775p1750249.html Sent from the R help mailing list archive at Nabble.com.