# Simulate multi-source heterogeneous data
n <- 50 # number of samples per source
K <- 3 # number of sources
p <- 100 # number of homogeneous covariates
q <- 5 # number of heterogeneous covariates
tau <- 0.5
set.seed(1)
theta <- matrix(c(c(-1,0.5,1,-0.5,2),rep(0,p-5)), ncol = 1)
beta <- matrix(1, nrow = q, ncol = K)
for (k in 1:K) {
beta[,k] <- matrix(c(rep(log(k+1),5),rep(0,q-5)), ncol = 1)
}
zdata <- MASS::mvrnorm(K*n, rep(0,q), diag(q))
Z <- array(data=zdata,dim=c(n,q,K))
xdata <- MASS::mvrnorm(K*n, rep(0,p), diag(p))
X <- array(data=xdata,dim=c(n,p,K))
Y <- matrix(0, nrow = n, ncol = K)
for (k in 1:K) {
Y[,k] <- MASS::mvrnorm(1, X[,,k]%*%theta+Z[,,k]%*%beta[,k], diag(n))
}
# Fit local model with Laplace prior
res <- vbms(X, Z, Y, global=FALSE, tau=tau)
# View results
print(head(res$mu_hom)) # Homogeneous coefficients mean
print(head(res$lr_mu_hom)) # Low rank correction estimation
print(head(res$gamma_hom)) # Homogeneous variable selection
print(res$mu_het) # Heterogeneous coefficients mean
Run the code above in your browser using DataLab