## ----knitr, echo=FALSE, results='hide'------------------------------------------------------------
library("knitr")
opts_chunk$set(tidy=FALSE,dev="png",fig.show="show",
               # fig.width=7,fig.height=7, 
               echo=TRUE,
               message=FALSE, warning=FALSE)

## ----initialize, cache=FALSE, echo=FALSE----------------------------------------------------------
# load library
library('variancePartition')

## ----corStruct, results='hide'--------------------------------------------------------------------
# Fit linear mixed model and examine correlation stucture
# for one gene
data(varPartData)

form <- ~ Age + (1|Individual) + (1|Tissue)

fitList <- fitVarPartModel( geneExpr[1:2,], form, info )

# focus on one gene
fit = fitList[[1]]

## ----corStructa,out.width = "50%"-----------------------------------------------------------------
# Figure 1a
# correlation structure based on similarity within Individual
# reorder samples based on clustering
plotCorrStructure( fit, "Individual" )

## ----corStructb,out.width = "50%"-----------------------------------------------------------------
# Figure 1b
# use original order of samples
plotCorrStructure( fit, "Individual", reorder=FALSE )

## ----corStructc,out.width = "50%"-----------------------------------------------------------------
# Figure 1c
# correlation structure based on similarity within Tissue
# reorder samples based on clustering
plotCorrStructure( fit, "Tissue" )

## ----corStructd,out.width = "50%"-----------------------------------------------------------------
# Figure 1d
# use original order of samples
plotCorrStructure( fit, "Tissue", reorder=FALSE )

## ----corStructe,out.width = "50%"-----------------------------------------------------------------
# Figure 2a
# correlation structure based on similarity within 
# Individual *and* Tissue, reorder samples based on clustering
plotCorrStructure( fit )

## ----corStructf,out.width = "50%"-----------------------------------------------------------------
# Figure 2b
# use original order of samples
plotCorrStructure( fit, reorder=FALSE )

