qpeer.instruments {QuantilePeer} | R Documentation |
Computing Instruments for Linear Models with Quantile Peer Effects
Description
qpeer.instruments
computes quantile peer variables.
Usage
qpeer.instruments(
formula,
Glist,
tau,
type = 7,
data,
max.distance = 1,
checkrank = FALSE,
tol = 1e-10
)
qpeer.instrument(
formula,
Glist,
tau,
type = 7,
data,
max.distance = 1,
checkrank = FALSE
)
qpeer.inst(
formula,
Glist,
tau,
type = 7,
data,
max.distance = 1,
checkrank = FALSE
)
qpeer.insts(
formula,
Glist,
tau,
type = 7,
data,
max.distance = 1,
checkrank = FALSE
)
Arguments
formula |
An object of class formula: a symbolic description of the model. The |
Glist |
The adjacency matrix. For networks consisting of multiple subnets (e.g., schools), |
tau |
The vector of quantile levels. |
type |
An integer between 1 and 9 selecting one of the nine quantile algorithms used to compute peer quantiles (see the quantile function). |
data |
An optional data frame, list, or environment (or an object that can be coerced by as.data.frame to a data frame) containing the variables
in the model. If not found in |
max.distance |
The maximum network distance of friends to consider in computing instruments. |
checkrank |
A logical value indicating whether the instrument matrix should be checked for full rank. If the matrix is not of full rank, unimportant columns will be removed to obtain a full-rank matrix. |
tol |
A tolerance value used in the QR factorization to identify columns that ensure a full-rank matrix (see the qr function). |
Details
The sample quantile is computed as a weighted average of two peer outcomes (see Hyndman and Fan, 1996). Specifically:
q_{\tau,i}(x_{-i}) = (1 - \omega_i)x_{i,(\pi_i)} + \omega_ix_{i,(\pi_i+1)},
where x_{i,(1)}, x_{i,(2)}, x_{i,(3)}, \ldots
are the order statistics of the outcome within i
's peers, and q_{\tau,i}(x_{-i})
represents the sample \tau
-quantile
of the outcome within i
's peer group. If y
is specified, then the ranks \pi_i
and the weights \omega_i
for the variables in X
are determined based on y
.
The network matrices in Glist
can be weighted or unweighted. If weighted, the sample weighted quantile is computed, where the outcome for friend j
of i
is weighted by g_{ij}
, the (i, j)
entry of the network matrix.
Value
A matrix including quantile peer variables
A list containing:
qy |
Quantiles of peer variable y. |
instruments |
Matrix of instruments. |
index |
The indices of the two peers whose weighted average gives the quantile. |
weight |
The weights of the two peers whose weighted average gives the quantile. |
References
Hyndman, R. J., & Fan, Y. (1996). Sample quantiles in statistical packages. The American Statistician, 50(4), 361-365, doi:10.1080/00031305.1996.10473566.
See Also
Examples
ngr <- 50
nvec <- rep(30, ngr)
n <- sum(nvec)
G <- lapply(1:ngr, function(z){
Gz <- matrix(rbinom(sum(nvec[z]*(nvec[z] - 1)), 1, 0.3), nvec[z])
diag(Gz) <- 0
Gz
})
tau <- seq(0, 1, 0.25)
X <- cbind(rnorm(n), rpois(n, 2))
l <- c(0.2, 0.1, 0.05, 0.1, 0.2)
b <- c(2, -0.5, 1)
y <- qpeer.sim(formula = ~X, Glist = G, tau = tau, lambda = l, beta = b)$y
Inst <- qpeer.instruments(formula = ~ X, Glist = G, tau = tau, max.distance = 2)$instruments
summary(Inst)