#################################################
#### Run the model on simulated data
#################################################
#### Load other libraries required
library(MCMCpack)
#### Set up a network
observations <- 200
numberOfMultipleClassifications <- 50
W <- matrix(rbinom(observations * numberOfMultipleClassifications, 1, 0.05),
ncol = numberOfMultipleClassifications)
numberOfActorsWithNoPeers <- sum(apply(W, 1, function(x) { sum(x) == 0 }))
peers <- sample(1:numberOfMultipleClassifications, numberOfActorsWithNoPeers,
TRUE)
actorsWithNoPeers <- which(apply(W, 1, function(x) { sum(x) == 0 }))
for(i in 1:numberOfActorsWithNoPeers) {
W[actorsWithNoPeers[i], peers[i]] <- 1
}
W <- t(apply(W, 1, function(x) { x / sum(x) }))
#### Generate the covariates and response data
X <- matrix(rnorm(2 * observations), ncol = 2)
colnames(X) <- c("x1", "x2")
beta <- c(1, -0.5, 0.5)
sigmaSquaredU <- 1
uRandomEffects <- rnorm(numberOfMultipleClassifications, mean = 0,
sd = sqrt(sigmaSquaredU))
logTheta <- cbind(rep(1, observations), X) %*% beta + W %*% uRandomEffects
Y <- rpois(n = observations, lambda = exp(logTheta))
data <- data.frame(cbind(Y, X))
#### Run the model
formula <- Y ~ x1 + x2
if (FALSE) model <- uniNet(formula = formula, data = data, family="poisson",
W = W, numberOfSamples = 10000, burnin = 10000,
thin = 10, seed = 1)
Run the code above in your browser using DataLab