qpeer.sim {QuantilePeer}R Documentation

Simulating Linear Models with Quantile Peer Effects

Description

qpeer.sim simulates the quantile peer effect models developed by Houndetoungan (2025).

Usage

qpeer.sim(
  formula,
  Glist,
  tau,
  parms,
  lambda,
  beta,
  epsilon,
  structural = FALSE,
  init,
  type = 7,
  tol = 1e-10,
  maxit = 500,
  details = TRUE,
  data
)

Arguments

formula

An object of class formula: a symbolic description of the model. formula should be specified as, for example, ~ x1 + x2, where x1 and x2 are control variables, which can include contextual variables such as averages or quantiles among peers.

Glist

The adjacency matrix. For networks consisting of multiple subnets (e.g., schools), Glist must be a list of subnets, with the m-th element being an n_m \times n_m adjacency matrix, where n_m is the number of nodes in the m-th subnet.

tau

The vector of quantile levels.

parms

A vector defining the true values of (\lambda', \beta')', where \lambda is a vector of \lambda_{\tau} for each quantile level \tau. The parameters \lambda and \beta can also be specified separately using the arguments lambda and beta. For the structural model, \lambda = (\lambda_2, \lambda_{\tau_1}, \lambda_{\tau_2}, \dots)^{\prime} (see the Details section of qpeer).

lambda

The true value of the vector \lambda.

beta

The true value of the vector \beta.

epsilon

A vector of idiosyncratic error terms. If not specified, it will be simulated from a standard normal distribution (see the model specification in the Details section of qpeer).

structural

A logical value indicating whether simulations should be performed using the structural model. The default is the reduced-form model (see the Details section of qpeer).

init

An optional initial guess for the equilibrium.

type

An integer between 1 and 9 selecting one of the nine quantile algorithms used to compute peer quantiles (see the quantile function).

tol

The tolerance value used in the Fixed Point Iteration Method to compute the outcome y. The process stops if the \ell_1-distance between two consecutive values of y is less than tol.

maxit

The maximum number of iterations for the Fixed Point Iteration Method.

details

A logical value indicating whether to save the indices and weights of the two peers whose weighted average determines the quantile.

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 data, the variables are taken from environment(formula), typically the environment from which sim.qpeer is called.

Value

A list containing:

y

The simulated variable.

qy

Quantiles of the simulated variable among peers.

epsilon

The idiosyncratic error.

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.

iteration

The number of iterations before convergence.

References

Houndetoungan, A. (2025). Quantile peer effect models. arXiv preprint arXiv:2405.17290, doi:10.48550/arXiv.2506.12920.

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

qpeer, qpeer.instruments

Examples

set.seed(123)
ngr  <- 50
nvec <- rep(30, ngr)
n    <- sum(nvec)
G    <- lapply(1:ngr, function(z){
  Gz <- matrix(rbinom(nvec[z]^2, 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)

out  <- qpeer.sim(formula = ~ X, Glist = G, tau = tau, lambda = l, beta = b)
summary(out$y)
out$iteration

[Package QuantilePeer version 0.0.1 Index]