## 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=cbind(Y1=Y1,X1)
df2=cbind(Y2=Y2,X2)
coloc.bma( df1, df2, snps=colnames(X1), response1="Y1", response2="Y2",
family1="gaussian", family2="gaussian",
nsnps=2,bayes.factor=c(1,2,3),plot.coeff=TRUE)
Run the code above in your browser using DataLab