Last updated: 2017-06-08

“Uk3” is the covariance matrix corresponding to the output of the ExtremeDeconvolution algorithm that was initialized with the rank3 SVD approximation of \(X^TX\). It is the pattern of sharing with the most loading. We demonstrate which patterns have the most loading the \(\pi\) barplot.

We plot the correlation matrix and the first 3 eigenvectors of “Uk3”. This provides a visualization of the primary patterns of genetic sharing identified by our method, mash. It is also Fig. 3 in the paper.

First, we load the necessary packages into the R environment.

library(lattice)
library(ggplot2)
library(colorRamps)
library(fields)

Explain here what this next code chunk does. It looks like you are loading a bunch of data sets from files. What are these data sets? And what is the bar chart you are creating?

covmat <- readRDS("../Data_vhat/covmatwithvhat.rds")
z.stat <- read.table("../Data/maxz.txt")
pis    <- readRDS("../Data_vhat/piswithvhat.rds")$pihat
pi.mat <- matrix(pis[-length(pis)],ncol = 54,nrow = 22,byrow = TRUE)
names  <- colnames(z.stat)
colnames(pi.mat) <-
  c("ID","X'X","SVD","F1","F2","F3","F4","F5","SFA_Rank5",names,"ALL")

# Please label the horizontal and vertical axes.
barplot(colSums(pi.mat),las = 2,cex.names = 0.5)

Here, we load the indices (of the tissues?) and tissue names:

k <- 3

x           <- cov2cor(covmat[[k]])
x[x < 0]    <- 0
colnames(x) <- names
rownames(x) <- names

h <- read.table("../Data/uk3rowindices.txt")[,1]

Now we produce the heatmap. What is the heat map showing? What interesting result(s) are highlighted by this heat map? Note that this is flipped in the paper:

smat <- (x[(h),(h)])
smat[lower.tri(smat)] <- NA

clrs <- colorRampPalette(rev(c("#D73027","#FC8D59","#FEE090","#FFFFBF",
                               "#E0F3F8","#91BFDB","#4575B4")))(64)
lat <- x[rev(h),rev(h)]

lat[lower.tri(lat)] <- NA
n <- nrow(lat)
print(levelplot(lat[n:1,],col.regions = clrs,xlab = "",ylab = "",
                colorkey = TRUE,at = seq(0,1,length.out = 64),
                scales = list(cex = 0.6,x = list(rot = 45))))

Now let’s do the eigenplots. What are these plots showing, and what sort of interesting results (briefly) are being highlighted by these plots? Can you briefly explain the color scheme you are using?

missing.tissues <- c(7,8,19,20,24,25,31,34,37)
color.gtex <- read.table("../Data/GTExColors.txt",sep = "\t",
                         comment.char = '')[-missing.tissues,]

k <- 3
vold  <- svd(covmat[[k]])$v
u     <- svd(covmat[[k]])$u
d     <- svd(covmat[[k]])$d
v     <- vold[h,] # Shuffle so correct order
names <- names[h]
color.gtex <- color.gtex[h,]
for (j in 1:3)
  
  # Please add labels to the horizontal and vertical axes in these plots.
  barplot(v[,j]/v[,j][which.max(abs(v[,j]))],names = "",cex.names = 0.5,
          las = 2,main = paste0("EigenVector",j,"Uk",k),
          col = as.character(color.gtex[,2]))

Session Information

print(sessionInfo())
## R version 3.4.0 (2017-04-21)
## Platform: x86_64-apple-darwin15.6.0 (64-bit)
## Running under: OS X El Capitan 10.11.6
## 
## Matrix products: default
## BLAS: /Library/Frameworks/R.framework/Versions/3.4/Resources/lib/libRblas.0.dylib
## LAPACK: /Library/Frameworks/R.framework/Versions/3.4/Resources/lib/libRlapack.dylib
## 
## locale:
## [1] en_US.UTF-8/en_US.UTF-8/en_US.UTF-8/C/en_US.UTF-8/en_US.UTF-8
## 
## attached base packages:
## [1] grid      stats     graphics  grDevices utils     datasets  methods  
## [8] base     
## 
## other attached packages:
## [1] fields_8.10     maps_3.1.1      spam_1.4-0      colorRamps_2.3 
## [5] ggplot2_2.2.1   lattice_0.20-35
## 
## loaded via a namespace (and not attached):
##  [1] Rcpp_0.12.10     knitr_1.15.1     magrittr_1.5     munsell_0.4.3   
##  [5] colorspace_1.3-2 stringr_1.2.0    plyr_1.8.4       tools_3.4.0     
##  [9] gtable_0.2.0     htmltools_0.3.6  yaml_2.1.14      lazyeval_0.2.0  
## [13] rprojroot_1.2    digest_0.6.12    tibble_1.3.0     evaluate_0.10   
## [17] rmarkdown_1.5    stringi_1.1.5    compiler_3.4.0   scales_0.4.1    
## [21] backports_1.0.5