smmSAR | R Documentation |
smmSAR
implements the Simulated Method of Moments (SMM) estimator of the linear-in-mean SAR model when only the linking probabilities are available or can be estimated.
smmSAR(
formula,
contextual = FALSE,
fixed.effects = FALSE,
dnetwork,
W = "identity",
smm.ctr = list(R = 30L, iv.power = 2L, opt.tol = 1e-04, smoother = FALSE, print =
FALSE),
cond.var = TRUE,
data
)
formula |
object of class formula: a symbolic description of the model. The |
contextual |
logical; if true, this means that all individual variables will be set as contextual variables. In contrast |
fixed.effects |
logical; if true, group heterogeneity is included as fixed effects. |
dnetwork |
a list, where the m-th elements is the matrix of link probability in the m-th sub-network. |
W |
is the weighted-matrix in the objective function of the SMM. |
smm.ctr |
is the list of some control parameters (see details). |
cond.var |
logical; if true the estimator variance conditional on |
data |
optional data frame, list or environment (or object coercible by as.data.frame to a data frame) containing the variables
in the model. If missing, the variables are taken from |
The parameter smm.ctr
is the list of some control parameters such as:
R
numbers of draws R (in the package, we assume S = 1 and T = 1);
iv.power
number of powers of the network matrix G
to be used to construct instruments;
opt.tol
optimization tolerance that will be used in optimize;
smoother
(logical) which indicates if draws should be performed using the smoother simulator;
h
bandwith of the smoother (required if smoother = TRUE
);
print
(logical) indicates if the optimization process should be printed step by step.
A list consisting of:
n.group |
number of groups. |
N |
vector of each group size. |
time |
elapsed time to run the SMM in second. |
estimates |
vector of estimated parameters. |
formula |
input value of |
contextual |
input value of |
fixed.effects |
input value of |
smm.ctr |
input value of |
details |
other details of the model. |
# Number of groups
M <- 100
# size of each group
N <- rep(30,M)
# covariates
X <- cbind(rnorm(sum(N),0,5),rpois(sum(N),7))
# network formation model parameter
rho <- c(-0.8, 0.2, -0.1)
# individual effects
beta <- c(2, 1, 1.5, 5, -3)
# endogenous effects
alpha <- 0.4
# std-dev errors
se <- 1
# network
tmp <- c(0, cumsum(N))
X1l <- lapply(1:M, function(x) X[c(tmp[x] + 1):tmp[x+1],1])
X2l <- lapply(1:M, function(x) X[c(tmp[x] + 1):tmp[x+1],2])
dist.net <- function(x, y) abs(x - y)
X1.mat <- lapply(1:M, function(m) {
matrix(kronecker(X1l[[m]], X1l[[m]], FUN = dist.net), N[m])})
X2.mat <- lapply(1:M, function(m) {
matrix(kronecker(X2l[[m]], X2l[[m]], FUN = dist.net), N[m])})
Xnet <- as.matrix(cbind("Const" = 1,
"dX1" = mat.to.vec(X1.mat),
"dX2" = mat.to.vec(X2.mat)))
ynet <- Xnet %*% rho
ynet <- c(1*((ynet + rlogis(length(ynet))) > 0))
G0 <- vec.to.mat(ynet, N, normalise = FALSE)
# normalise
G0norm <- norm.network(G0)
# Matrix GX
GX <- peer.avg(G0norm, X)
# simulate dependent variable use an external package
y <- CDatanet::simsar(~ X, contextual = TRUE, Glist = G0norm,
theta = c(alpha, beta, se))
Gy <- y$Gy
y <- y$y
# build dataset
dataset <- as.data.frame(cbind(y, X, Gy, GX))
colnames(dataset) <- c("y","X1","X2", "Gy", "GX1", "GX2")
nNet <- nrow(Xnet) # network formation model sample size
Aobs <- sample(1:nNet, round(0.3*nNet)) # We observed 30%
# We can estimate rho using the gml function from the stats package
logestim <- glm(ynet[Aobs] ~ -1 + Xnet[Aobs,], family = binomial(link = "logit"))
slogestim <- summary(logestim)
rho.est <- logestim$coefficients
rho.var <- slogestim$cov.unscaled # we also need the covariance of the estimator
d.logit <- lapply(1:M, function(x) {
out <- 1/(1 + exp(-rho.est[1] - rho.est[2]*X1.mat[[x]] -
rho.est[3]*X2.mat[[x]]))
diag(out) <- 0
out})
smm.logit <- smmSAR(y ~ X1 + X2, dnetwork = d.logit, contextual = TRUE,
smm.ctr = list(R = 100L, print = TRUE), data = dataset)
summary(smm.logit, dnetwork = d.logit, data = dataset)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.