SS <- matrix(c( 0.01, -0.0008, -0.003, 0.007, 0.002,
-0.0008, 0.02, 0.002, -0.0004, -0.001,
-0.003, 0.002, 0.03, -0.0054, -0.009,
0.007, -0.0004, -0.00538, 0.02, 0.0008,
0.002, -0.001, -0.009, 0.0008, 0.07), ncol=5)
sim.Sigma <- function()
{
S <- matrix(rep(0,25),ncol=5)
x <- mvrnorm(n=10, mu=rep(0,5), Sigma=10*SS)
for(i in 1:10)
S <- S+crossprod(t(x[i,]))
solve(S)
}
## Now let's simulate a dataset with three biological conditions
## 500 genes in total, 10 of them have different expected time course profiles
## across biological conditions
## the first condition has 3 replicates, while the second condition has 4 replicates,
## and the third condition has 2 replicates. 5 time points for each condition.
sim.data <- function(x, indx=1)
{
mu <- rep(runif(1,8,x[1]),5)
if(indx==1)
res <- c(as.numeric(t(mvrnorm(n=3, mu=mu+rnorm(5,sd=5), Sigma=sim.Sigma()))),
as.numeric(t(mvrnorm(n=4, mu=mu+rnorm(5,sd=3.2), Sigma=sim.Sigma()))),
as.numeric(t(mvrnorm(n=2, mu=mu+rnorm(5,sd=2), Sigma=sim.Sigma()))))
if(indx==0) res <- as.numeric(t(mvrnorm(n=9, mu=mu+rnorm(5,sd=3), Sigma=sim.Sigma())))
res
}
M <- matrix(rep(14,500*45), ncol=45)
M[1:10,] <- t(apply(M[1:10,],1,sim.data))
M[11:500,] <- t(apply(M[11:500,],1,sim.data, 0))
assay <- rep(c("1.2.04","2.4.04","3.5.04","5.21.04","7.17.04","9.10.04","12.1.04","1.2.05","4.1.05"),each=5)
trt <- c(rep(c("wildtype","mutant1"),each=15),rep("mutant1",5), rep("mutant2", 10))
# Caution: since "mutant1" < "mutant2" < "wildtype", the sample sizes should be in the order of 4,2,3,
# but NOT 3,4,2.
size <- matrix(c(4,2,3), byrow=TRUE, nrow=500, ncol=3)
MB.multi <- mb.MANOVA(M, times=5, D=3, size=size, rep.grp=assay, condition.grp=trt)
plotProfile(MB.multi, stats="MB", type="b") # plots the no. 1 gene
Run the code above in your browser using DataLab