| Title: | Quantile Peer Effect Models |
|---|---|
| Description: | Simulating and estimating peer effect models including the quantile-based specification (Houndetoungan, 2025 <doi:10.48550/arXiv.2506.12920>), and the models with Constant Elasticity of Substitution (CES)-based social norm (Boucher et al., 2024 <doi:10.3982/ECTA21048>). |
| Authors: | Aristide Houndetoungan [cre, aut] (ORCID: <https://orcid.org/0009-0003-2733-9362>) |
| Maintainer: | Aristide Houndetoungan <[email protected]> |
| License: | GPL-3 |
| Version: | 0.0.2 |
| Built: | 2026-06-01 09:45:36 UTC |
| Source: | https://github.com/ahoundetoungan/quantilepeer |
The QuantilePeer package simulates and estimates peer effect models including the quantile-based specification (Houndetoungan, 2025 doi:10.3982/ECTA21048), and the models with Constant Elasticity of Substitution (CES)-based social norm (Boucher et al., 2024 doi:10.3982/ECTA21048).
Maintainer: Aristide Houndetoungan [email protected] (ORCID)
Boucher, V., Rendall, M., Ushchev, P., & Zenou, Y. (2024). Toward a general theory of peer effects. Econometrica, 92(2), 543-565, doi:10.3982/ECTA21048.
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.
Useful links:
Report bugs at https://github.com/ahoundetoungan/QuantilePeer/issues
cespeer estimates the CES-based peer effects model introduced by Boucher et al. (2024). See Details.
cespeer( formula, instrument, Glist, structural = FALSE, fixed.effects = FALSE, set.rho = NULL, grid.rho = seq(-400, 400, radius), radius = 5, tol = 1e-08, drop = NULL, compute.cov = TRUE, HAC = "iid", data )cespeer( formula, instrument, Glist, structural = FALSE, fixed.effects = FALSE, set.rho = NULL, grid.rho = seq(-400, 400, radius), radius = 5, tol = 1e-08, drop = NULL, compute.cov = TRUE, HAC = "iid", data )
formula |
An object of class formula: a symbolic description of the model. |
instrument |
An object of class formula indicating the excluded instrument. It should be specified as |
Glist |
The adjacency matrix. For networks consisting of multiple subnets (e.g., schools), |
structural |
A logical value indicating whether the reduced-form or structural specification should be estimated (see details). |
fixed.effects |
A logical value or string specifying whether the model includes subnet fixed effects. The fixed effects may differ between isolated and non-isolated nodes. Accepted values are |
set.rho |
A fixed value for the CES substitution parameter to estimate a constrained model. Given this value, the other parameters can be estimated. |
grid.rho |
A finite grid of values for the CES substitution parameter |
radius |
The radius of the subset in which the estimate for |
tol |
A tolerance value used in the QR factorization to identify columns of explanatory variable and instrument matrices that ensure a full-rank matrix (see the qr function). The same tolerance is also used in the to minimize the concentrated GMM objective function (see optimise). |
drop |
A dummy vector of the same length as the sample, indicating whether an observation should be dropped. This can be used, for example, to remove false isolates or to estimate the model only on non-isolated agents. These observations cannot be directly removed from the network by the user because they may still be friends with other agents. |
compute.cov |
A logical value indicating whether the covariance matrix of the estimator should be computed. |
HAC |
A character string specifying the correlation structure among the idiosyncratic error terms for covariance computation. Options are |
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 |
Let be a set of agents indexed by the integer .
Agents are connected through a network characterized by an adjacency matrix of dimension , where if agent is a friend of agent , and otherwise.
In weighted networks, can be a nonnegative variable (not necessarily binary) that measures the intensity of the outgoing link from to . The model can also accommodate such networks.
Note that the network generally consists of multiple independent subnets (e.g., schools).
The Glist argument is the list of subnets. In the case of a single subnet, Glist should be a list containing one matrix.
The reduced-form specification of the CES-based peer effects model is given by:
where is an idiosyncratic error term, captures the effect of the social norm ,
and captures the effect of on . The parameter determines the form of the social norm in the model.
When , individuals are more sensitive to peers with high outcomes.
When , individuals are more sensitive to peers with low outcomes.
When , peer effects are uniform across peer outcome values.
The structural specification of the model differs for isolated and non-isolated individuals.
For an isolated , the specification is similar to a standard linear-in-means model without social interactions, given by:
If node is non-isolated, the specification is:
where determines whether preferences exhibit conformity or complementarity/substitution.
Identification of and requires the network to include a sufficient number of isolated individuals.
A list containing:
model.info |
A list with information about the model, including the number of subnets, the number of observations, and other key details. |
gmm |
A list of GMM estimation results, including parameter estimates, the covariance matrix, and related statistics. |
first.search |
A list containing initial estimations on the grid of values for |
Boucher, V., Rendall, M., Ushchev, P., & Zenou, Y. (2024). Toward a general theory of peer effects. Econometrica, 92(2), 543-565, doi:10.3982/ECTA21048.
set.seed(123) ngr <- 50 # Number of subnets nvec <- rep(30, ngr) # Size of subnets n <- sum(nvec) ### Simulating Data ## Network matrix G <- lapply(1:ngr, function(z) { Gz <- matrix(rbinom(nvec[z]^2, 1, 0.3), nvec[z], nvec[z]) diag(Gz) <- 0 # Adding isolated nodes (important for the structural model) niso <- sample(0:nvec[z], 1, prob = (nvec[z] + 1):1 / sum((nvec[z] + 1):1)) if (niso > 0) { Gz[sample(1:nvec[z], niso), ] <- 0 } # Row-normalization rs <- rowSums(Gz); rs[rs == 0] <- 1 Gz/rs }) X <- cbind(rnorm(n), rpois(n, 2)) l <- 0.55 b <- c(2, -0.5, 1) rho <- -2 eps <- rnorm(n, 0, 0.4) ## Generating `y` y <- cespeer.sim(formula = ~ X, Glist = G, rho = rho, lambda = l, beta = b, epsilon = eps)$y ### Estimation ## Computing instruments z <- fitted.values(lm(y ~ X)) ## Reduced-form model rest <- cespeer(formula = y ~ X, instrument = ~ z, Glist = G, fixed.effects = "yes", radius = 5, grid.rho = seq(-10, 10, 1)) summary(rest) ## Structural model sest <- cespeer(formula = y ~ X, instrument = ~ z, Glist = G, fixed.effects = "yes", radius = 5, structural = TRUE, grid.rho = seq(-10, 10, 1)) summary(sest) ## Quantile model z <- qpeer.inst(formula = ~ X, Glist = G, tau = seq(0, 1, 0.1), max.distance = 2, checkrank = TRUE)$instruments qest <- qpeer(formula = y ~ X, excluded.instruments = ~ z, Glist = G, fixed.effects = "yes", tau = seq(0, 1, 1/3), structural = TRUE) summary(qest)set.seed(123) ngr <- 50 # Number of subnets nvec <- rep(30, ngr) # Size of subnets n <- sum(nvec) ### Simulating Data ## Network matrix G <- lapply(1:ngr, function(z) { Gz <- matrix(rbinom(nvec[z]^2, 1, 0.3), nvec[z], nvec[z]) diag(Gz) <- 0 # Adding isolated nodes (important for the structural model) niso <- sample(0:nvec[z], 1, prob = (nvec[z] + 1):1 / sum((nvec[z] + 1):1)) if (niso > 0) { Gz[sample(1:nvec[z], niso), ] <- 0 } # Row-normalization rs <- rowSums(Gz); rs[rs == 0] <- 1 Gz/rs }) X <- cbind(rnorm(n), rpois(n, 2)) l <- 0.55 b <- c(2, -0.5, 1) rho <- -2 eps <- rnorm(n, 0, 0.4) ## Generating `y` y <- cespeer.sim(formula = ~ X, Glist = G, rho = rho, lambda = l, beta = b, epsilon = eps)$y ### Estimation ## Computing instruments z <- fitted.values(lm(y ~ X)) ## Reduced-form model rest <- cespeer(formula = y ~ X, instrument = ~ z, Glist = G, fixed.effects = "yes", radius = 5, grid.rho = seq(-10, 10, 1)) summary(rest) ## Structural model sest <- cespeer(formula = y ~ X, instrument = ~ z, Glist = G, fixed.effects = "yes", radius = 5, structural = TRUE, grid.rho = seq(-10, 10, 1)) summary(sest) ## Quantile model z <- qpeer.inst(formula = ~ X, Glist = G, tau = seq(0, 1, 0.1), max.distance = 2, checkrank = TRUE)$instruments qest <- qpeer(formula = y ~ X, excluded.instruments = ~ z, Glist = G, fixed.effects = "yes", tau = seq(0, 1, 1/3), structural = TRUE) summary(qest)
cespeer.data computes the CES social norm, along with the first and second derivatives of the CES social norm with respect to the substitution parameter .
cespeer.data(y, Glist, rho)cespeer.data(y, Glist, rho)
y |
A vector of outcomes used to compute the social norm. |
Glist |
The adjacency matrix. For networks consisting of multiple subnets (e.g., schools), |
rho |
The CES substitution parameter. |
A four-column matrix with the following columns:
y |
The outcome; |
ces(y, rho)
|
The CES social norm; |
d[ces(y, rho)]
|
The first derivative of the social norm; |
dd[ces(y, rho)]
|
The second derivative of the social norm. |
cespeer.sim simulates peer effect models with a Constant Elasticity of Substitution (CES) based social norm (Boucher et al., 2024).
cespeer.sim( formula, Glist, parms, rho, lambda, beta, epsilon, structural = FALSE, init, tol = 1e-10, maxit = 500, data )cespeer.sim( formula, Glist, parms, rho, lambda, beta, epsilon, structural = FALSE, init, tol = 1e-10, maxit = 500, data )
formula |
A formula object (formula): a symbolic description of the model. |
Glist |
The adjacency matrix. For networks consisting of multiple subnets (e.g., schools), |
parms |
A vector defining the true values of |
rho |
The true value of the substitution parameter of the CES function. |
lambda |
The true value of the peer effect parameter |
beta |
The true value of the vector |
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 |
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 |
init |
An optional initial guess for the equilibrium. |
tol |
The tolerance value used in the Fixed Point Iteration Method to compute the outcome |
maxit |
The maximum number of iterations for the Fixed Point Iteration Method. |
data |
An optional data frame, list, or environment containing the model variables. If a variable is not found in |
A list containing:
y |
The simulated variable. |
epsilon |
The idiosyncratic error. |
init |
The initial guess. |
iteration |
The number of iterations before convergence. |
Boucher, V., Rendall, M., Ushchev, P., & Zenou, Y. (2024). Toward a general theory of peer effects. Econometrica, 92(2), 543-565, doi:10.3982/ECTA21048.
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/rowSums(Gz) # Row-normalized network }) tau <- seq(0, 1, 0.25) X <- cbind(rnorm(n), rpois(n, 2)) l <- 0.55 rho <- 3 b <- c(4, -0.5, 1) out <- cespeer.sim(formula = ~ X, Glist = G, rho = rho, lambda = l, beta = b) summary(out$y) out$iterationset.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/rowSums(Gz) # Row-normalized network }) tau <- seq(0, 1, 0.25) X <- cbind(rnorm(n), rpois(n, 2)) l <- 0.55 rho <- 3 b <- c(4, -0.5, 1) out <- cespeer.sim(formula = ~ X, Glist = G, rho = rho, lambda = l, beta = b) summary(out$y) out$iteration
demean demeans variables by subtracting the within-subnetwork average. In each subnetwork, this transformation can be performed separately
for isolated and non-isolated nodes.
demean(X, Glist, separate = FALSE, drop = NULL)demean(X, Glist, separate = FALSE, drop = NULL)
X |
A matrix or vector to demean. |
Glist |
The adjacency matrix. For networks consisting of multiple subnets (e.g., schools), |
separate |
A logical value specifying whether variables should be demeaned separately for isolated and non-isolated individuals.
This is similar to setting |
drop |
A logical vector of the same length as the sample, indicating whether an observation should be dropped. This can be used, for example, to remove false isolates or to estimate the model only on non-isolated agents. These observations cannot be directly removed from the network by the user, as they may still be connected to other agents. |
A matrix or vector with the same dimensions as X, containing the demeaned values.
qpeer estimates the quantile peer effect models introduced by Houndetoungan (2025). In the linpeer function, quantile peer variables are replaced with the average peer variable, and they can be replaced with other peer variables in the genpeer function.
genpeer( formula, excluded.instruments, endogenous.variables, Glist, data, estimator = "IV", structural = FALSE, drop = NULL, fixed.effects = FALSE, HAC = "iid", checkrank = FALSE, compute.cov = TRUE, boot = 500, nthreads = 1, tol = 1e-10, print = TRUE ) linpeer( formula, excluded.instruments, Glist, data, estimator = "IV", structural = FALSE, drop = NULL, fixed.effects = FALSE, HAC = "iid", checkrank = FALSE, compute.cov = TRUE, boot = 500, nthreads = 1, tol = 1e-10, print = TRUE ) qpeer( formula, excluded.instruments, Glist, tau, type = 7, data, estimator = "IV", structural = FALSE, fixed.effects = FALSE, HAC = "iid", checkrank = FALSE, drop = NULL, compute.cov = TRUE, boot = 500, nthreads = 1, tol = 1e-10, print = TRUE )genpeer( formula, excluded.instruments, endogenous.variables, Glist, data, estimator = "IV", structural = FALSE, drop = NULL, fixed.effects = FALSE, HAC = "iid", checkrank = FALSE, compute.cov = TRUE, boot = 500, nthreads = 1, tol = 1e-10, print = TRUE ) linpeer( formula, excluded.instruments, Glist, data, estimator = "IV", structural = FALSE, drop = NULL, fixed.effects = FALSE, HAC = "iid", checkrank = FALSE, compute.cov = TRUE, boot = 500, nthreads = 1, tol = 1e-10, print = TRUE ) qpeer( formula, excluded.instruments, Glist, tau, type = 7, data, estimator = "IV", structural = FALSE, fixed.effects = FALSE, HAC = "iid", checkrank = FALSE, drop = NULL, compute.cov = TRUE, boot = 500, nthreads = 1, tol = 1e-10, print = TRUE )
formula |
An object of class formula: a symbolic description of the model. |
excluded.instruments |
An object of class formula to indicate excluded instruments. It should be specified as |
endogenous.variables |
An object of class formula that allows specifying endogenous variables. It is used to indicate the peer variables whose effects will be estimated. These can include average peer variables, quantile peer variables,
or a combination of multiple variables. It should be specified as |
Glist |
The adjacency matrix. For networks consisting of multiple subnets (e.g., schools), |
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 |
estimator |
A character string specifying the estimator to be used. The available options are:
|
structural |
A logical value indicating whether the reduced-form or structural specification should be estimated (see Details). |
drop |
A dummy vector of the same length as the sample, indicating whether an observation should be dropped. This can be used, for example, to remove false isolates or to estimate the model only on non-isolated agents. These observations cannot be directly removed from the network by the user because they may still be friends with other agents. |
fixed.effects |
A logical value or string specifying whether the model includes subnet fixed effects. The fixed effects may differ between isolated and non-isolated nodes. Accepted values are |
HAC |
A character string specifying the correlation structure of the idiosyncratic error terms used for covariance computation.
Options are |
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. |
compute.cov |
A logical value indicating whether the covariance matrix of the estimator should be computed. |
boot |
An integer indicating the number of bootstrap replications. |
nthreads |
A strictly positive integer indicating the number of threads to use when computing quantiles of peer variables or when performing the bootstrap. |
tol |
A tolerance value used in the QR factorization to identify columns of explanatory variable and instrument matrices that ensure a full-rank matrix (see the qr function). |
print |
A Boolean indicating whether the progression bar should be printed for bootstrap methods. |
tau |
A numeric vector specifying the 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). |
Let be a set of agents indexed by the integer .
Agents are connected through a network that is characterized by an adjacency matrix of dimension , where if agent is a friend of agent , and otherwise.
In weighted networks, can be a nonnegative variable (not necessarily binary) that measures the intensity of the outgoing link from to . The model can also accommodate such networks. Note that the network is generally constituted in many independent subnets (eg: schools).
The Glist argument is the list of subnets. In the case of a single subnet, Glist will be a list containing one matrix.
Let be a set of quantile levels. The reduced-form specification of quantile peer effect models is given by:
where is the vector of outcomes for other units, and is the
sample -quantile of peer outcomes. The term is an idiosyncratic error term, captures the effect of the -quantile of peer outcomes on ,
and captures the effect of on . For the definition of the sample -quantile, see Hyndman and Fan (1996).
If the network matrix is weighted, the sample weighted quantile can be used, where the outcome for friend of is weighted by . It can be shown that
the sample -quantile is a weighted average of two peer outcomes. For more details, see the quantile and qpeer.instruments functions.
The quantile can be replaced with the average peer variable in linpeer or with other measures in genpeer through the endogenous.variables argument.
In genpeer, it is possible to specify multiple peer variables, such as male peer averages and female peer averages. Additionally, both quantiles and averages can be included (genpeer
is general and encompasses qpeer and linpeer). See examples.
One issue in linear peer effect models is that individual preferences with conformity and complementarity/substitution lead to the same reduced form.
However, it is possible to disentangle both types of preferences using isolated individuals (individuals without friends).
The structural specification of the model differs between isolated and nonisolated individuals.
For isolated , the specification is similar to a standard linear-in-means model without social interactions, given by:
If node is non-isolated, the specification is given by:
where determines whether preferences exhibit conformity or complementarity/substitution. In general, and this means that that preferences are conformist (anti-conformity may be possible in some models when ).
In contrast, when , there is complementarity/substitution between individuals depending on the signs of the parameters.
It is obvious that and can be identified only if the network includes enough isolated individuals.
A list containing:
model.info |
A list with information about the model, such as the number of subnets, number of observations, and other key details. |
gmm |
A list of GMM estimation results, including parameter estimates, the covariance matrix, and related statistics. |
data |
A list containing the outcome, outcome quantiles among peers, control variables, and excluded instruments used in the model. |
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.
set.seed(123) ngr <- 50 # Number of subnets nvec <- rep(30, ngr) # Size of subnets n <- sum(nvec) ### Simulating Data ## Network matrix G <- lapply(1:ngr, function(z) { Gz <- matrix(rbinom(nvec[z]^2, 1, 0.3), nvec[z], nvec[z]) diag(Gz) <- 0 # Adding isolated nodes (important for the structural model) niso <- sample(0:nvec[z], 1, prob = (nvec[z] + 1):1 / sum((nvec[z] + 1):1)) if (niso > 0) { Gz[sample(1:nvec[z], niso), ] <- 0 } Gz }) tau <- seq(0, 1, 1/3) X <- cbind(rnorm(n), rpois(n, 2)) l <- c(0.2, 0.15, 0.1, 0.2) b <- c(2, -0.5, 1) eps <- rnorm(n, 0, 0.4) ## Generating `y` y <- qpeer.sim(formula = ~ X, Glist = G, tau = tau, lambda = l, beta = b, epsilon = eps)$y ### Estimation ## Computing instruments Z <- qpeer.inst(formula = ~ X, Glist = G, tau = seq(0, 1, 0.1), max.distance = 2, checkrank = TRUE) Z <- Z$instruments ## Reduced-form model rest <- qpeer(formula = y ~ X, excluded.instruments = ~ Z, Glist = G, tau = tau) summary(rest) summary(rest, diagnostic = TRUE) # Summary with diagnostics ## Structural model sest <- qpeer(formula = y ~ X, excluded.instruments = ~ Z, Glist = G, tau = tau, structural = TRUE) summary(sest, diagnostic = TRUE) # The lambda^* parameter is y_q (conformity) in the outputs. # There is no conformity in the data, so the estimate will be approximately 0. ## Structural model with double fixed effects per subnet using optimal GMM ## and controlling for heteroskedasticity sesto <- qpeer(formula = y ~ X, excluded.instruments = ~ Z, Glist = G, tau = tau, structural = TRUE, fixed.effects = "separate", HAC = "hetero", estimator = "gmm.optimal") summary(sesto, diagnostic = TRUE) ## Average peer effect model # Row-normalized network to compute instruments Gnorm <- lapply(G, function(g) { d <- rowSums(g) d[d == 0] <- 1 g / d }) # GX and GGX Gall <- Matrix::bdiag(Gnorm) GX <- as.matrix(Gall %*% X) GGX <- as.matrix(Gall %*% GX) # Standard linear model lpeer <- linpeer(formula = y ~ X + GX, excluded.instruments = ~ GGX, Glist = Gnorm) summary(lpeer, diagnostic = TRUE) # Note: The normalized network is used here by definition of the model. # Contextual effects are also included (this is also possible for the quantile model). # The standard model can also be structural lpeers <- linpeer(formula = y ~ X + GX, excluded.instruments = ~ GGX, Glist = Gnorm, structural = TRUE, fixed.effects = "separate") summary(lpeers, diagnostic = TRUE) ## Estimation using `genpeer` # Average peer variable computed manually and included as an endogenous variable Gy <- as.vector(Gall %*% y) gpeer1 <- genpeer(formula = y ~ X + GX, excluded.instruments = ~ GGX, endogenous.variables = ~ Gy, Glist = Gnorm, structural = TRUE, fixed.effects = "separate") summary(gpeer1, diagnostic = TRUE) # Using both average peer variables and quantile peer variables as endogenous, # or only the quantile peer variable # Quantile peer `y` qy <- qpeer.inst(formula = y ~ 1, Glist = G, tau = tau) qy <- qy$qy # Model estimation gpeer2 <- genpeer(formula = y ~ X + GX, excluded.instruments = ~ GGX + Z, endogenous.variables = ~ Gy + qy, Glist = Gnorm, structural = TRUE, fixed.effects = "separate") summary(gpeer2, diagnostic = TRUE)set.seed(123) ngr <- 50 # Number of subnets nvec <- rep(30, ngr) # Size of subnets n <- sum(nvec) ### Simulating Data ## Network matrix G <- lapply(1:ngr, function(z) { Gz <- matrix(rbinom(nvec[z]^2, 1, 0.3), nvec[z], nvec[z]) diag(Gz) <- 0 # Adding isolated nodes (important for the structural model) niso <- sample(0:nvec[z], 1, prob = (nvec[z] + 1):1 / sum((nvec[z] + 1):1)) if (niso > 0) { Gz[sample(1:nvec[z], niso), ] <- 0 } Gz }) tau <- seq(0, 1, 1/3) X <- cbind(rnorm(n), rpois(n, 2)) l <- c(0.2, 0.15, 0.1, 0.2) b <- c(2, -0.5, 1) eps <- rnorm(n, 0, 0.4) ## Generating `y` y <- qpeer.sim(formula = ~ X, Glist = G, tau = tau, lambda = l, beta = b, epsilon = eps)$y ### Estimation ## Computing instruments Z <- qpeer.inst(formula = ~ X, Glist = G, tau = seq(0, 1, 0.1), max.distance = 2, checkrank = TRUE) Z <- Z$instruments ## Reduced-form model rest <- qpeer(formula = y ~ X, excluded.instruments = ~ Z, Glist = G, tau = tau) summary(rest) summary(rest, diagnostic = TRUE) # Summary with diagnostics ## Structural model sest <- qpeer(formula = y ~ X, excluded.instruments = ~ Z, Glist = G, tau = tau, structural = TRUE) summary(sest, diagnostic = TRUE) # The lambda^* parameter is y_q (conformity) in the outputs. # There is no conformity in the data, so the estimate will be approximately 0. ## Structural model with double fixed effects per subnet using optimal GMM ## and controlling for heteroskedasticity sesto <- qpeer(formula = y ~ X, excluded.instruments = ~ Z, Glist = G, tau = tau, structural = TRUE, fixed.effects = "separate", HAC = "hetero", estimator = "gmm.optimal") summary(sesto, diagnostic = TRUE) ## Average peer effect model # Row-normalized network to compute instruments Gnorm <- lapply(G, function(g) { d <- rowSums(g) d[d == 0] <- 1 g / d }) # GX and GGX Gall <- Matrix::bdiag(Gnorm) GX <- as.matrix(Gall %*% X) GGX <- as.matrix(Gall %*% GX) # Standard linear model lpeer <- linpeer(formula = y ~ X + GX, excluded.instruments = ~ GGX, Glist = Gnorm) summary(lpeer, diagnostic = TRUE) # Note: The normalized network is used here by definition of the model. # Contextual effects are also included (this is also possible for the quantile model). # The standard model can also be structural lpeers <- linpeer(formula = y ~ X + GX, excluded.instruments = ~ GGX, Glist = Gnorm, structural = TRUE, fixed.effects = "separate") summary(lpeers, diagnostic = TRUE) ## Estimation using `genpeer` # Average peer variable computed manually and included as an endogenous variable Gy <- as.vector(Gall %*% y) gpeer1 <- genpeer(formula = y ~ X + GX, excluded.instruments = ~ GGX, endogenous.variables = ~ Gy, Glist = Gnorm, structural = TRUE, fixed.effects = "separate") summary(gpeer1, diagnostic = TRUE) # Using both average peer variables and quantile peer variables as endogenous, # or only the quantile peer variable # Quantile peer `y` qy <- qpeer.inst(formula = y ~ 1, Glist = G, tau = tau) qy <- qy$qy # Model estimation gpeer2 <- genpeer(formula = y ~ X + GX, excluded.instruments = ~ GGX + Z, endogenous.variables = ~ Gy + qy, Glist = Gnorm, structural = TRUE, fixed.effects = "separate") summary(gpeer2, diagnostic = TRUE)
linpeer.sim simulates linear peer effect models.
linpeer.sim( formula, Glist, parms, lambda, beta, epsilon, structural = FALSE, nthreads = 1, data )linpeer.sim( formula, Glist, parms, lambda, beta, epsilon, structural = FALSE, nthreads = 1, data )
formula |
An object of class formula: a symbolic description of the model. |
Glist |
The adjacency matrix. For networks consisting of multiple subnets (e.g., schools), |
parms |
A vector defining the true values of |
lambda |
The true value of the vector |
beta |
The true value of the vector |
epsilon |
A vector of idiosyncratic error terms. If not specified, it will be simulated from a standard normal distribution. |
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 |
nthreads |
A strictly positive integer indicating the number of threads to use. |
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 |
A list containing:
y |
The simulated variable. |
Gy |
the average of y among friends. |
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/rowSums(Gz) # Row-normalized network }) X <- cbind(rnorm(n), rpois(n, 2)) l <- 0.5 b <- c(2, -0.5, 1) out <- linpeer.sim(formula = ~ X, Glist = G, lambda = l, beta = b) summary(out$y)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/rowSums(Gz) # Row-normalized network }) X <- cbind(rnorm(n), rpois(n, 2)) l <- 0.5 b <- c(2, -0.5, 1) out <- linpeer.sim(formula = ~ X, Glist = G, lambda = l, beta = b) summary(out$y)
A print method for the class qpeer.test.
## S3 method for class 'qpeer.test' print(x, ...)## S3 method for class 'qpeer.test' print(x, ...)
x |
an object of class |
... |
Further arguments passed to or from other methods. |
No return value, called for side effects
qpeer.instruments computes quantile peer variables.
qpeer.instruments( formula, Glist, tau, type = 7, data, max.distance = 1, checkrank = FALSE, nthreads = 1, tol = 1e-10 ) qpeer.instrument( formula, Glist, tau, type = 7, data, max.distance = 1, checkrank = FALSE, nthreads = 1, tol = 1e-10 ) qpeer.inst( formula, Glist, tau, type = 7, data, max.distance = 1, checkrank = FALSE, nthreads = 1, tol = 1e-10 ) qpeer.insts( formula, Glist, tau, type = 7, data, max.distance = 1, checkrank = FALSE, nthreads = 1, tol = 1e-10 )qpeer.instruments( formula, Glist, tau, type = 7, data, max.distance = 1, checkrank = FALSE, nthreads = 1, tol = 1e-10 ) qpeer.instrument( formula, Glist, tau, type = 7, data, max.distance = 1, checkrank = FALSE, nthreads = 1, tol = 1e-10 ) qpeer.inst( formula, Glist, tau, type = 7, data, max.distance = 1, checkrank = FALSE, nthreads = 1, tol = 1e-10 ) qpeer.insts( formula, Glist, tau, type = 7, data, max.distance = 1, checkrank = FALSE, nthreads = 1, tol = 1e-10 )
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. |
nthreads |
A strictly positive integer indicating the number of threads to use when computing the quantiles of peer variables. |
tol |
A tolerance value used in the QR factorization to identify columns that ensure a full-rank matrix (see the qr function). |
The sample quantile is computed as a weighted average of two peer outcomes (see Hyndman and Fan, 1996). Specifically:
where are the order statistics of the outcome within 's peers, and represents the sample -quantile
of the outcome within 's peer group. If y is specified, then the ranks and the weights 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 of is weighted by , the entry of the network matrix.
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. |
Hyndman, R. J., & Fan, Y. (1996). Sample quantiles in statistical packages. The American Statistician, 50(4), 361-365, doi:10.1080/00031305.1996.10473566.
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)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)
qpeer.optimal.inst computes optimal (or "good") instruments for quantile peer effect models using a bootstrap approach.
qpeer.optimal.instruments( model, Glist, tau, boot = 100L, nthreads = 1L, seed, tol = 1e-10, maxit = 500 ) qpeer.optimal.instrument( model, Glist, tau, boot = 100L, nthreads = 1L, seed, tol = 1e-10, maxit = 500 ) qpeer.optimal.insts( model, Glist, tau, boot = 100L, nthreads = 1L, seed, tol = 1e-10, maxit = 500 ) qpeer.optimal.inst( model, Glist, tau, boot = 100L, nthreads = 1L, seed, tol = 1e-10, maxit = 500 )qpeer.optimal.instruments( model, Glist, tau, boot = 100L, nthreads = 1L, seed, tol = 1e-10, maxit = 500 ) qpeer.optimal.instrument( model, Glist, tau, boot = 100L, nthreads = 1L, seed, tol = 1e-10, maxit = 500 ) qpeer.optimal.insts( model, Glist, tau, boot = 100L, nthreads = 1L, seed, tol = 1e-10, maxit = 500 ) qpeer.optimal.inst( model, Glist, tau, boot = 100L, nthreads = 1L, seed, tol = 1e-10, maxit = 500 )
model |
An object of class |
Glist |
The adjacency matrix. For networks consisting of multiple subnets (e.g., schools),
|
tau |
A numeric vector specifying the quantile levels for the instrument matrix. The default value is the vector of quantile levels used to estimate the model. |
boot |
A strictly positive integer indicating the number of bootstrap replications. |
nthreads |
A strictly positive integer indicating the number of threads to use when bootstrapping. |
seed |
The random number generator (RNG) state used for random number generation.
This can also be set using the |
tol |
The tolerance value used in the fixed-point iteration method to compute the outcome |
maxit |
The maximum number of iterations for the fixed-point iteration method. |
A matrix of instruments, where the k-th column corresponds to the instrument for the k-th endogenous variable.
set.seed(123) ngr <- 30 # Number of subnets nvec <- rep(30, ngr) # Size of subnets n <- sum(nvec) ### Simulating Data ## Network matrix G <- lapply(1:ngr, function(z) { Gz <- matrix(rbinom(nvec[z]^2, 1, 0.3), nvec[z], nvec[z]) diag(Gz) <- 0 # Adding isolated nodes (important for the structural model) niso <- sample(0:nvec[z], 1, prob = (nvec[z] + 1):1 / sum((nvec[z] + 1):1)) if (niso > 0) { Gz[sample(1:nvec[z], niso), ] <- 0 } Gz }) tau <- seq(0, 1, 1/3) X <- cbind(rnorm(n), rpois(n, 2)) l <- c(0.2, 0.15, 0.1, 0.2) b <- c(2, -0.5, 1) eps <- rnorm(n, 0, 0.4) ## Generating `y` y <- qpeer.sim(formula = ~ X, Glist = G, tau = tau, lambda = l, beta = b, epsilon = eps)$y ### Estimation ## Computing instruments Z <- qpeer.inst(formula = ~ X, Glist = G, tau = seq(0, 1, 0.1), max.distance = 2, checkrank = TRUE) Z <- Z$instruments ## Reduced-form model rest <- qpeer(formula = y ~ X, excluded.instruments = ~ Z, Glist = G, tau = tau) summary(rest, diagnostic = TRUE) # Estimation using the optimal instrument Ired <- qpeer.optimal.insts(rest, Glist = G, boot = 100, nthreads = 2) summary(qpeer(formula = y ~ X, excluded.instruments = ~ Ired, Glist = G, tau = tau), diagnostic = TRUE) ## Structural model sest <- qpeer(formula = y ~ X, excluded.instruments = ~ Z, Glist = G, tau = tau, structural = TRUE) summary(sest, diagnostic = TRUE) # Estimation using the optimal instrument Istr <- qpeer.optimal.insts(sest, Glist = G, boot = 100, nthreads = 2) summary(qpeer(formula = y ~ X, excluded.instruments = ~ Istr, Glist = G, tau = tau), diagnostic = TRUE)set.seed(123) ngr <- 30 # Number of subnets nvec <- rep(30, ngr) # Size of subnets n <- sum(nvec) ### Simulating Data ## Network matrix G <- lapply(1:ngr, function(z) { Gz <- matrix(rbinom(nvec[z]^2, 1, 0.3), nvec[z], nvec[z]) diag(Gz) <- 0 # Adding isolated nodes (important for the structural model) niso <- sample(0:nvec[z], 1, prob = (nvec[z] + 1):1 / sum((nvec[z] + 1):1)) if (niso > 0) { Gz[sample(1:nvec[z], niso), ] <- 0 } Gz }) tau <- seq(0, 1, 1/3) X <- cbind(rnorm(n), rpois(n, 2)) l <- c(0.2, 0.15, 0.1, 0.2) b <- c(2, -0.5, 1) eps <- rnorm(n, 0, 0.4) ## Generating `y` y <- qpeer.sim(formula = ~ X, Glist = G, tau = tau, lambda = l, beta = b, epsilon = eps)$y ### Estimation ## Computing instruments Z <- qpeer.inst(formula = ~ X, Glist = G, tau = seq(0, 1, 0.1), max.distance = 2, checkrank = TRUE) Z <- Z$instruments ## Reduced-form model rest <- qpeer(formula = y ~ X, excluded.instruments = ~ Z, Glist = G, tau = tau) summary(rest, diagnostic = TRUE) # Estimation using the optimal instrument Ired <- qpeer.optimal.insts(rest, Glist = G, boot = 100, nthreads = 2) summary(qpeer(formula = y ~ X, excluded.instruments = ~ Ired, Glist = G, tau = tau), diagnostic = TRUE) ## Structural model sest <- qpeer(formula = y ~ X, excluded.instruments = ~ Z, Glist = G, tau = tau, structural = TRUE) summary(sest, diagnostic = TRUE) # Estimation using the optimal instrument Istr <- qpeer.optimal.insts(sest, Glist = G, boot = 100, nthreads = 2) summary(qpeer(formula = y ~ X, excluded.instruments = ~ Istr, Glist = G, tau = tau), diagnostic = TRUE)
qpeer.sim simulates the quantile peer effect models developed by Houndetoungan (2025).
qpeer.sim( formula, Glist, tau, parms, lambda, beta, epsilon, structural = FALSE, init, type = 7, tol = 1e-10, maxit = 500, details = TRUE, nthreads = 1, data )qpeer.sim( formula, Glist, tau, parms, lambda, beta, epsilon, structural = FALSE, init, type = 7, tol = 1e-10, maxit = 500, details = TRUE, nthreads = 1, data )
formula |
An object of class formula: a symbolic description of the model. |
Glist |
The adjacency matrix. For networks consisting of multiple subnets (e.g., schools), |
tau |
The vector of quantile levels. |
parms |
A vector defining the true values of |
lambda |
The true value of the vector |
beta |
The true value of the vector |
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 |
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 |
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 |
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. |
nthreads |
A strictly positive integer indicating the number of threads to use. |
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 |
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. |
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.
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$iterationset.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
qpeer.test performs specification tests on peer effects models. These include monotonicity tests on quantile peer effects, as well as tests for instrument validity when an alternative set of instruments is available.
qpeer.test( model1, model2 = NULL, which, full = FALSE, boot = 500, nthreads = 1L, print = TRUE, maxit = 1e+06, eps_f = 1e-09, eps_g = 1e-09 )qpeer.test( model1, model2 = NULL, which, full = FALSE, boot = 500, nthreads = 1L, print = TRUE, maxit = 1e+06, eps_f = 1e-09, eps_g = 1e-09 )
model1, model2
|
|
which |
A character string indicating the type of test to be implemented.
The value must be one of |
full |
A Boolean indicating whether the parameters associated with the exogenous variables should be compared. This is used for tests that compare two competing parameter sets. |
boot |
An integer indicating the number of bootstrap replications to use for the encompassing test and for computing |
nthreads |
Number of CPU cores (threads) used to run parts of the estimation in parallel. |
print |
A Boolean indicating whether the progression bar should be printed for bootstrap methods. |
maxit, eps_f, eps_g
|
Control parameters for the |
The monotonicity tests evaluate whether the quantile peer effects are constant, increasing, or decreasing. In this case, model1 must be an object of class qpeer, and the which argument specifies the null hypothesis: "uniform", "increasing", or "decreasing".
For the "uniform" test, a standard Wald test is performed. For the "increasing" and "decreasing" tests, the procedure follows Kodde and Palm (1986).
The instrument validity tests assess whether a second set of instruments is valid, assuming that a baseline set is valid. In this case, both model1 and model2 must be objects of class qpeer, linpeer, or genpeer.
The test compares the estimates obtained using each instrument set. If nests , it is recommended to compare the overidentification statistics from both estimations (see Hayashi, 2000, Proposition 3.7).
If does not nest , the estimates themselves are compared. To compare the overidentification statistics, set the which argument to "sargan". To compare the estimates directly, set the which argument to "wald".
Given two competing models, it is possible to test whether one is significantly worse using an encompassing test by setting which to "encompassing". The null hypothesis is that model1 is not worse.
A list containing:
test |
A vector or matrix containing the test statistics, degrees of freedom, and p-values. |
lambda |
Peer effect estimates from tests based on a single model (monotonicity tests). |
diff.theta |
Differences in peer effect estimates from tests based on two models (endogeneity and encompassing tests). |
delta |
The estimate of |
which |
The value of |
boot |
The value of |
Hayashi, F. (2000). Econometrics. Princeton University Press.
Kodde, D. A., & Palm, F. C. (1986). Wald criteria for jointly testing equality and inequality restrictions. Econometrica, 54(5), 1243–1248.
set.seed(123) ngr <- 50 # Number of subnets nvec <- rep(30, ngr) # Size of subnets n <- sum(nvec) ### Simulating Data ## Network matrix G <- lapply(1:ngr, function(z) { Gz <- matrix(rbinom(nvec[z]^2, 1, 0.3), nvec[z], nvec[z]) diag(Gz) <- 0 # Adding isolated nodes (important for the structural model) niso <- sample(0:nvec[z], 1, prob = (nvec[z] + 1):1 / sum((nvec[z] + 1):1)) if (niso > 0) { Gz[sample(1:nvec[z], niso), ] <- 0 } Gz }) tau <- seq(0, 1, 1/3) X <- cbind(rnorm(n), rpois(n, 2)) l <- c(0.2, 0.15, 0.1, 0.2) b <- c(2, -0.5, 1) eps <- rnorm(n, 0, 0.4) ## Generating `y` y <- qpeer.sim(formula = ~ X, Glist = G, tau = tau, lambda = l, beta = b, epsilon = eps)$y ### Estimation ## Computing instruments Z1 <- qpeer.inst(formula = ~ X, Glist = G, tau = seq(0, 1, 0.1), max.distance = 2, checkrank = TRUE)$instruments Z2 <- qpeer.inst(formula = y ~ X, Glist = G, tau = seq(0, 1, 0.1), max.distance = 2, checkrank = TRUE)$instruments ## Reduced-form model rest1 <- qpeer(formula = y ~ X, excluded.instruments = ~ Z1, Glist = G, tau = tau) summary(rest1, diagnostic = TRUE) rest2 <- qpeer(formula = y ~ X, excluded.instruments = ~ Z1 + Z2, Glist = G, tau = tau) summary(rest2, diagnostic = TRUE) qpeer.test(model1 = rest1, which = "increasing") qpeer.test(model1 = rest1, which = "decreasing") qpeer.test(model1 = rest1, model2 = rest2, which = "sargan") #' A model with a mispecified tau rest3 <- qpeer(formula = y ~ X, excluded.instruments = ~ Z1 + Z2, Glist = G, tau = c(0, 1)) summary(rest3) #' Test is rest3 is worse than rest1 qpeer.test(model1 = rest3, model2 = rest1, which = "encompassing")set.seed(123) ngr <- 50 # Number of subnets nvec <- rep(30, ngr) # Size of subnets n <- sum(nvec) ### Simulating Data ## Network matrix G <- lapply(1:ngr, function(z) { Gz <- matrix(rbinom(nvec[z]^2, 1, 0.3), nvec[z], nvec[z]) diag(Gz) <- 0 # Adding isolated nodes (important for the structural model) niso <- sample(0:nvec[z], 1, prob = (nvec[z] + 1):1 / sum((nvec[z] + 1):1)) if (niso > 0) { Gz[sample(1:nvec[z], niso), ] <- 0 } Gz }) tau <- seq(0, 1, 1/3) X <- cbind(rnorm(n), rpois(n, 2)) l <- c(0.2, 0.15, 0.1, 0.2) b <- c(2, -0.5, 1) eps <- rnorm(n, 0, 0.4) ## Generating `y` y <- qpeer.sim(formula = ~ X, Glist = G, tau = tau, lambda = l, beta = b, epsilon = eps)$y ### Estimation ## Computing instruments Z1 <- qpeer.inst(formula = ~ X, Glist = G, tau = seq(0, 1, 0.1), max.distance = 2, checkrank = TRUE)$instruments Z2 <- qpeer.inst(formula = y ~ X, Glist = G, tau = seq(0, 1, 0.1), max.distance = 2, checkrank = TRUE)$instruments ## Reduced-form model rest1 <- qpeer(formula = y ~ X, excluded.instruments = ~ Z1, Glist = G, tau = tau) summary(rest1, diagnostic = TRUE) rest2 <- qpeer(formula = y ~ X, excluded.instruments = ~ Z1 + Z2, Glist = G, tau = tau) summary(rest2, diagnostic = TRUE) qpeer.test(model1 = rest1, which = "increasing") qpeer.test(model1 = rest1, which = "decreasing") qpeer.test(model1 = rest1, model2 = rest2, which = "sargan") #' A model with a mispecified tau rest3 <- qpeer(formula = y ~ X, excluded.instruments = ~ Z1 + Z2, Glist = G, tau = c(0, 1)) summary(rest3) #' Test is rest3 is worse than rest1 qpeer.test(model1 = rest3, model2 = rest1, which = "encompassing")
Summary and print methods for the class cespeer.
## S3 method for class 'cespeer' summary(object, fullparameters = TRUE, ...) ## S3 method for class 'summary.cespeer' print(x, ...) ## S3 method for class 'cespeer' print(x, ...)## S3 method for class 'cespeer' summary(object, fullparameters = TRUE, ...) ## S3 method for class 'summary.cespeer' print(x, ...) ## S3 method for class 'cespeer' print(x, ...)
object |
An object of class |
fullparameters |
A logical value indicating whether all parameters should be summarized (may be useful for the structural model). |
... |
Further arguments passed to or from other methods. |
x |
An object of class |
A list containing:
model.info |
A list with information about the model, such as the number of subnets, number of observations, and other key details. |
coefficients |
A summary of the estimates, standard errors, and p-values. |
gmm |
A list of GMM estimation results, including parameter estimates, the covariance matrix, and related statistics. |
Summary and print methods for the class qpeer.
## S3 method for class 'genpeer' summary( object, fullparameters = TRUE, diagnostic = FALSE, diagnostics = FALSE, boot = NULL, nthreads = 1L, print = TRUE, ... ) ## S3 method for class 'summary.genpeer' print(x, ...) ## S3 method for class 'genpeer' print(x, ...) ## S3 method for class 'linpeer' summary( object, fullparameters = TRUE, diagnostic = FALSE, diagnostics = FALSE, boot = NULL, nthreads = 1L, print = TRUE, ... ) ## S3 method for class 'summary.linpeer' print(x, ...) ## S3 method for class 'linpeer' print(x, ...) ## S3 method for class 'qpeer' summary( object, fullparameters = TRUE, diagnostic = FALSE, diagnostics = FALSE, boot = NULL, nthreads = 1L, print = TRUE, ... ) ## S3 method for class 'summary.qpeer' print(x, ...) ## S3 method for class 'qpeer' print(x, ...)## S3 method for class 'genpeer' summary( object, fullparameters = TRUE, diagnostic = FALSE, diagnostics = FALSE, boot = NULL, nthreads = 1L, print = TRUE, ... ) ## S3 method for class 'summary.genpeer' print(x, ...) ## S3 method for class 'genpeer' print(x, ...) ## S3 method for class 'linpeer' summary( object, fullparameters = TRUE, diagnostic = FALSE, diagnostics = FALSE, boot = NULL, nthreads = 1L, print = TRUE, ... ) ## S3 method for class 'summary.linpeer' print(x, ...) ## S3 method for class 'linpeer' print(x, ...) ## S3 method for class 'qpeer' summary( object, fullparameters = TRUE, diagnostic = FALSE, diagnostics = FALSE, boot = NULL, nthreads = 1L, print = TRUE, ... ) ## S3 method for class 'summary.qpeer' print(x, ...) ## S3 method for class 'qpeer' print(x, ...)
object |
An object of class |
fullparameters |
A logical value indicating whether all parameters should be summarized (may be useful for the structural model). |
diagnostics, diagnostic
|
Logical. Should diagnostic tests for the instrumental-variable regression be performed? These include an F-test of the first-stage regression for weak instruments, a Wu-Hausman test for endogeneity, and a Hansen's J-test for overidentifying restrictions (only if there are more instruments than regressors). |
boot |
An integer indicating the number of bootstrap replications for the encompassing test. |
nthreads |
A strictly positive integer indicating the number of threads used to perform the bootstrap. |
print |
A logical indicating whether a progress bar should be displayed for bootstrap methods. |
... |
Further arguments passed to or from other methods. |
x |
An object of class |
A list containing:
model.info |
A list with information about the model, such as the number of subnets, number of observations, and other key details. |
coefficients |
A summary of the estimates, standard errors, and p-values. |
diagnostics |
A summary of the diagnostic tests for the instrumental-variable regression if requested. |
KP.cv |
Critical values for the Kleibergen–Paap Wald test (5% level). |
gmm |
A list of GMM estimation results, including parameter estimates, the covariance matrix, and related statistics. |