# NOT RUN {
M <- 5 # Number of sub-groups
nvec <- round(runif(M, 100, 500))
beta <- c(1, -1)
Glist <- list()
dX <- matrix(0, 0, 2)
mu <- list()
uu <- runif(M, -5, 5)
sigma2u <- runif(M, 0.5, 16)
for (m in 1:M) {
n <- nvec[m]
mum <- rnorm(n, uu[m], sqrt(sigma2u[m]))
X1 <- rnorm(n)
X2 <- rbinom(n, 1, 0.2)
Z1 <- matrix(0, n, n)
Z2 <- matrix(0, n, n)
for (i in 1:n) {
for (j in 1:n) {
Z1[i, j] <- abs(X1[i] - X1[j])
Z2[i, j] <- 1*(X2[i] == X2[j])
}
}
Gm <- 1*((Z1*beta[1] + Z2*beta[2] +
kronecker(mum, t(mum), "+") + rlogis(n^2)) > 0)
diag(Gm) <- 0
diag(Z1) <- NA
diag(Z2) <- NA
Z1 <- Z1[!is.na(Z1)]
Z2 <- Z2[!is.na(Z2)]
dX <- rbind(dX, cbind(Z1, Z2))
Glist[[m]] <- Gm
mu[[m]] <- mum
}
mu <- unlist(mu)
out <- netformation(network = Glist, formula = ~ dX, fixed.effects = T,
mcmc.ctr = list(burin = 1000, iteration = 5000))
# plot simulations
plot(out$posterior$beta[,1], type = "l")
abline(h = beta[1], col = "red")
plot(out$posterior$beta[,2], type = "l")
abline(h = beta[2], col = "red")
k <- 2
plot(out$posterior$sigmamu2[,2], type = "l")
abline(h = sigma2u[2], col = "red")
i <- 10
plot(out$posterior$mu[,i], type = "l",
ylim = c(min(out$posterior$mu[,i], mu[i]), max(out$posterior$mu[,i], mu[i])))
abline(h = mu[i], col = "red")
plot(out$posterior$uu[,k] , type = "l",
ylim = c(min(out$posterior$uu[,k], uu[k]), max(out$posterior$uu[,k], uu[k])))
abline(h = uu[k], col = "red")
# }
Run the code above in your browser using DataLab