# set number of genes (p) and samples (n)
p <- 10
n <- 1000
# sample cis-effects
beta <- abs(rnorm(p))
# sample trans-effects for first sample
Theta1 <- matrix(sample(c(-1,1), p^2, replace=TRUE, prob=c(0.2, 0.8)), ncol=p) *
matrix(runif(p^2), ncol=p) / 4
diag(Theta1) <- 1
# sample trans-effects for second sample
idDiff <- sample(which(Theta1 != 1), 10)
Theta2 <- Theta1
Theta2[idDiff] <- -Theta1[idDiff]
# sample error variances
Sigma <- diag(rchisq(p, df=1)/5 + 0.5)
# sample DNA copy number data of sample 1
X1 <- matrix(runif(n*p, min=-2, max=2), ncol=p)
# sample gene expression data
Y1 <- t(apply(X1, 1, function(Y, beta){ Y * beta }, beta=beta)) %*% t(solve(Theta1)) +
rmvnorm(n, sigma=solve(Theta1) %*% Sigma %*% t(solve(Theta1)))
# sample DNA copy number data of sample 1
X2 <- matrix(runif(n*p, min=-2, max=2), ncol=p)
# sample gene expression data
Y2 <- t(apply(X2, 1, function(Y, beta){ Y * beta }, beta=beta)) %*% t(solve(Theta2)) +
rmvnorm(n, sigma=solve(Theta2) %*% Sigma %*% t(solve(Theta2)))
# construct id-vector
id <- c(rep(0, n), rep(1, n))
# fit model
pFit <- pathway2sample(Y=rbind(Y1, Y2), X=rbind(X1, X2), id=id, lambda1=0, lambdaF=0.01)
# compare fit to "truth" for cis-effects
plot(pFit@Cis ~ beta, pch=20)
# compare fit to "truth" for differential trans-effects
penFits1 <- c(pFit@Trans1[upper.tri(Theta1)], pFit@Trans1[lower.tri(Theta1)])
penFits2 <- c(pFit@Trans2[upper.tri(Theta2)], pFit@Trans2[lower.tri(Theta2)])
truth1 <- c(Theta1[upper.tri(Theta1)], Theta1[lower.tri(Theta1)])
truth2 <- c(Theta2[upper.tri(Theta2)], Theta2[lower.tri(Theta2)])
plot(penFits1 - penFits2, truth1 - truth2, pch=20)
cor(penFits1 - penFits2, truth1 - truth2, m="s")Run the code above in your browser using DataLab