# \donttest{
# Group sizes
set.seed(123)
M <- 5 # Number of sub-groups
nvec <- round(runif(M, 100, 200))
n <- sum(nvec)
# Parameters
lambda <- 0.4
Gamma <- c(2, -1.9, 0.8, 1.5, -1.2)
sigma <- 1.5
theta <- c(lambda, Gamma, sigma)
# Covariates (X)
X <- cbind(rnorm(n, 1, 1), rexp(n, 0.4))
# Network creation
G <- list()
for (m in 1:M) {
nm <- nvec[m]
Gm <- matrix(0, nm, nm)
max_d <- 30
for (i in 1:nm) {
tmp <- sample((1:nm)[-i], sample(0:max_d, 1))
Gm[i, tmp] <- 1
}
rs <- rowSums(Gm); rs[rs == 0] <- 1
Gm <- Gm / rs
G[[m]] <- Gm
}
# Data creation
data <- data.frame(X, peer.avg(G, cbind(x1 = X[, 1], x2 = X[, 2])))
colnames(data) <- c("x1", "x2", "gx1", "gx2")
## Complete information game
ytmp <- simsart(formula = ~ x1 + x2 + gx1 + gx2, Glist = G, theta = theta,
data = data, cinfo = TRUE)
data$yc <- ytmp$y
## Incomplete information game
ytmp <- simsart(formula = ~ x1 + x2 + gx1 + gx2, Glist = G, theta = theta,
data = data, cinfo = FALSE)
data$yi <- ytmp$y
# Complete information estimation for yc
outc1 <- sart(formula = yc ~ x1 + x2 + gx1 + gx2, optimizer = "nlm",
Glist = G, data = data, cinfo = TRUE)
summary(outc1)
# Complete information estimation for yi
outc1 <- sart(formula = yi ~ x1 + x2 + gx1 + gx2, optimizer = "nlm",
Glist = G, data = data, cinfo = TRUE)
summary(outc1)
# Incomplete information estimation for yc
outi1 <- sart(formula = yc ~ x1 + x2 + gx1 + gx2, optimizer = "nlm",
Glist = G, data = data, cinfo = FALSE)
summary(outi1)
# Incomplete information estimation for yi
outi1 <- sart(formula = yi ~ x1 + x2 + gx1 + gx2, optimizer = "nlm",
Glist = G, data = data, cinfo = FALSE)
summary(outi1)
# }
Run the code above in your browser using DataLab