Export tukeyHSD result table
1
0
Entering edit mode
12 months ago
Peter ▴ 20

Hey guys

I have transcriptome data from five different groups. I'm comparing transcriptome from five different brain regions. My data is with genes in columns and samples in rows.

I used the following code to perform ANOVA and Tukey's post-hoc test:

> genes <- colnames(mydata)[2:ncol(mydata)]
> head(genes)
> aov.out <- lapply(genes, function(x) { lm(substitute(i ~ Groups, list(i = as.name(x))), data = mydata)})
> TukeyHSD.out <- lapply(aov.out, function(x) TukeyHSD(aov(x)))

My aov.out file is a result list for all my genes:

> TukeyHSD.out[[1]]

Tukey multiple comparisons of means
95% family-wise confidence level
Fit: aov(formula = x)
$Groups
         diff       lwr      upr     p adj
HIP-CER 0.06974 -1.716994 1.856474 0.9994666
LPS-CER 0.18248 -1.502069 1.867029 0.9890216
PFC-CER 0.30944 -1.375109 1.993989 0.9505767
LPS-HIP 0.11274 -1.673994 1.899474 0.9977672
PFC-HIP 0.23970 -1.547034 2.026434 0.9796204
PFC-LPS 0.12696 -1.557589 1.811509 0.9962189

I'd like to get a table in a data.frame that looks something like:

Comparison          Gene        diff          adj.p-value
Group1-Group2       ATF6        1.5548      0.01548

Can anybody help me?

Thanks in advance!

R • 850 views
ADD COMMENT
3
Entering edit mode
12 months ago

The object aov.out is a list and length(aov.out) is equal to length(gene). So you can iterate over the list and retrieve what you want:

# defining empty vectors. They will populate through the loop
Comparison = c()
Gene = c()
diff  = c()
adj.p_value = c()
# loop to iterate over the list elements
for(i in 1:length(TukeyHSD.out)){
  Comparison = c(Comparison, rownames(TukeyHSD.out[[i]]$group)) 
  Gene = c(Gene, rep(genes[i], dim(TukeyHSD.out[[i]]$group)[1]))
  diff = c(diff, TukeyHSD.out[[i]]$group[,1])
  adj.p_value = c(adj.p_value, TukeyHSD.out[[i]]$group[,4])
}
# putting all together
res = data.frame(Comparison, Gene, diff, adj.p_value)
ADD COMMENT

Login before adding your answer.

Traffic: 2707 users visited in the last hour
Help About
FAQ
Access RSS
API
Stats

Use of this site constitutes acceptance of our User Agreement and Privacy Policy.

Powered by the version 2.3.6