# NOT RUN {
## simulate covariate matrix (X) and continuous response vector (Y)
## for two populations/triats Y1 and Y2 depend equally on f1 and f2
## within each population, although their distributions differ between
## populations. They are compatible with a null hypothesis that they
## share a common causal variant
set.seed(1)
X1 <- matrix(rbinom(2000,1,0.4),ncol=4)
Y1 <- rnorm(500,rowSums(X1[,1:2]),2)
X2 <- matrix(rbinom(2000,1,0.6),ncol=4)
Y2 <- rnorm(500,rowSums(X2[,1:2]),5)
boxplot(list(Y1,Y2),names=c("Y1","Y2"))
## fit and store linear model objects
colnames(X1) <- colnames(X2) <- sprintf("f%s",1:ncol(X1))
summary(lm1 <- lm(Y1~f1+f2+f3+f4,data=as.data.frame(X1)))
summary(lm2 <- lm(Y2~f1+f2+f3+f4,data=as.data.frame(X2)))
## test colocalisation using bma
df1=as.data.frame(cbind(Y1=Y1,X1))
df2=as.data.frame(cbind(Y2=Y2,X2))
result <- coloc.bma( df1, df2, snps=colnames(X1), response1="Y1", response2="Y2",
family1="gaussian", family2="gaussian",
nsnps=2,bayes.factor=c(1,2,3))
result
plot(result)
## test colocalisation when one dataset contains a stratifying factor in column named "s"
df1$s <- rbinom(500,1,0.5)
result <- coloc.bma( df1, df2, snps=colnames(X1), response1="Y1", response2="Y2",
stratum1="s",
family1="gaussian", family2="gaussian",
nsnps=2,bayes.factor=c(1,2,3))
result
plot(result)
# }
Run the code above in your browser using DataLab