| Title: | Heterogeneous Treatment Effects in Regression Discontinuity Designs |
|---|---|
| Description: | Understanding heterogeneous causal effects based on pretreatment covariates is a crucial step in modern empirical work in data science. Building on the recent developments in Calonico et al (2025) <doi:10.48550/arXiv.2503.13696>, this package provides tools for estimation and inference of heterogeneous treatment effects in Regression Discontinuity (RD) Designs. The package includes two main commands: 'rdhte' to conduct estimation and robust bias-corrected inference for conditional RD treatment effects (given choice of bandwidth parameter); 'rdbwhte', which implements automatic bandwidth selection methods; and 'rdhte_lincom' to test linear combinations of parameters. |
| Authors: | Sebastian Calonico [aut, cre], Matias D. Cattaneo [aut], Max H. Farrell [aut], Filippo Palomba [aut], Rocio Titiunik [aut] |
| Maintainer: | Sebastian Calonico <[email protected]> |
| License: | GPL-3 |
| Version: | 0.2.0 |
| Built: | 2026-05-26 20:21:32 UTC |
| Source: | https://github.com/cran/rdhte |
Building on the recent developments in Calonico, Cattaneo, Farrell, Palomba, and Titiunik (2025), this package implements
estimation and inference of heterogeneous treatment effects in RD designs.
The package includes two main commands: rdhte conduct estimation and robust bias-corrected inference for conditional RD treatment effects,
for a given choice of bandwidth parameter; and rdbwhte implements automatic bandwidth selection methods.
We illustrate the methods implemented in the package rdhte using a canonical empirical application.
We also demonstrate how the package rdhte complements, and in very specific cases recovers,
the methods available in the packages rdrobust (Calonico, Cattaneo, Farrell, Titiunik (2017) and rdmulti, Cattaneo, Titiunik, VazquezBare (2020).
Commands: rdhte for estimation and inference.
rdbwhte for data-driven bandwidth selection.
Related software packages useful for inference in regression discontinuity (RD) designs are described in the website: https://rdpackages.github.io/.
Sebastian Calonico, University of California, Davis [email protected].
Matias D. Cattaneo, Princeton University [email protected].
Max H. Farrell, University of California, Santa Barbara [email protected].
Filippo Palomba, Princeton University [email protected].
Rocio Titiunik, Princeton University [email protected].
Calonico, Cattaneo, Farrell, Palomba and Titiunik (2025): rdhte: Conditional Average Treatment Effects in RD Designs. Working paper.
Calonico, Cattaneo, Farrell, Palomba and Titiunik (2025): Treatment Effect Heterogeneity in Regression Discontinuity Designs. Working paper.
For an rdhte object fit with a categorical covs.hte,
draw one point per group at the conventional point estimate
(Estimate) with the robust bias-corrected confidence interval
(ci.rb). A dashed horizontal line at zero gives a visual
reference for the null effect.
## S3 method for class 'rdhte' plot(x, sort = FALSE, point.size = 2.5, errorbar.width = 0.2, zero.line = TRUE, title = NULL, xlab = NULL, ylab = NULL, ...)## S3 method for class 'rdhte' plot(x, sort = FALSE, point.size = 2.5, errorbar.width = 0.2, zero.line = TRUE, title = NULL, xlab = NULL, ylab = NULL, ...)
x |
An object of class |
sort |
Logical or character; if |
point.size |
Numeric; size of the point markers. Default 2.5. |
errorbar.width |
Numeric; width of the error-bar caps relative to the x-axis discrete unit. Default 0.2. |
zero.line |
Logical; if |
title, xlab, ylab
|
Optional plot annotations. Defaults derived
from the rdhte object ( |
... |
Currently unused. |
Continuous covs.hte (or no covs.hte) is not yet
supported – the function errors with a clear message in those cases.
Requires the ggplot2 package. The intervals shown are the same
robust bias-corrected CIs reported by print(x) and
summary(x): they are centered on Estimate.bc (not
Estimate) and use the robust standard error se.rb.
Because the point and the CI center can differ slightly, the point
may sit just inside or just outside the bar; this is the rdrobust
convention and is not a plotting bug.
Invisibly, a ggplot object.
## Not run: set.seed(1) n <- 600 x <- runif(n, -1, 1) W <- factor(sample(c("A", "B", "C"), n, replace = TRUE)) y <- 0.5 + (x >= 0) * (W == "A") * 1.0 + (x >= 0) * (W == "B") * 2.0 + (x >= 0) * (W == "C") * 0.3 + rnorm(n) m <- rdhte(y = y, x = x, covs.hte = W) plot(m) plot(m, sort = TRUE) # reorder by effect size ## End(Not run)## Not run: set.seed(1) n <- 600 x <- runif(n, -1, 1) W <- factor(sample(c("A", "B", "C"), n, replace = TRUE)) y <- 0.5 + (x >= 0) * (W == "A") * 1.0 + (x >= 0) * (W == "B") * 2.0 + (x >= 0) * (W == "C") * 0.3 + rnorm(n) m <- rdhte(y = y, x = x, covs.hte = W) plot(m) plot(m, sort = TRUE) # reorder by effect size ## End(Not run)
rdbwhte computes MSE- and CER-optimal bandwidths for
estimating RD heterogeneous treatment effects based on covariates
(Calonico, Cattaneo, Farrell, Palomba and Titiunik, 2025a).
Companion commands: rdhte for RD HTE estimation and inference,
and rdhte_lincom for testing linear restrictions of parameters.
A detailed introduction to the software is given in Calonico, Cattaneo, Farrell, Palomba and Titiunik (2025b). Related software packages for analysis and interpretation of RD designs and related methods are available in: https://rdpackages.github.io/.
For background methodology, see Calonico, Cattaneo, Farrell, and Titiunik (2019), Calonico, Cattaneo and Farrell (2020), and Cattaneo and Titiunik (2022).
rdbwhte( y, x, c = 0, covs.hte = NULL, covs.eff = NULL, p = 1, q = NULL, kernel = "tri", weights = NULL, vce = "hc3", cluster = NULL, bwselect = "mserd", bw.joint = FALSE, subset = NULL, data = NULL )rdbwhte( y, x, c = 0, covs.hte = NULL, covs.eff = NULL, p = 1, q = NULL, kernel = "tri", weights = NULL, vce = "hc3", cluster = NULL, bwselect = "mserd", bw.joint = FALSE, subset = NULL, data = NULL )
y |
Outcome variable. |
x |
Running variable. |
c |
RD cutoff in |
covs.hte |
covariates for heterogeneous treatment effects. Factor variables can be used to distinguish between continuous and categorical variables, select reference categories, specify interactions between variables, and include polynomials of continuous variables. |
covs.eff |
additional covariates to be used for efficiency improvements. |
p |
order of the local polynomial used to construct the point estimator (default = 1). |
q |
order of the local polynomial used to construct the bias correction.
If |
kernel |
kernel function used to construct the RD estimators. Options are |
weights |
variable used for optional weighting of the bandwidth-selection procedure. The unit-specific weights multiply the kernel function. |
vce |
character string specifying the variance-covariance matrix
estimator type. Without |
cluster |
variable indicating the clustering of observations. |
bwselect |
bandwidth selection procedure to be used.
Options are:
|
bw.joint |
logical. If |
subset |
optional vector specifying a subset of observations to be used. |
data |
optional data frame. When supplied, |
A list with the following named elements:
W.lev |
Group-level identifiers, or |
W.names |
Display labels for the rows of |
covs.hte_chr |
Character representation of the |
kernel |
Kernel type used. |
vce |
Variance estimator display label. |
vce_select |
Canonical lowercase variance-estimator name. |
c |
Cutoff value. |
h |
An |
p |
Order of the polynomial used for estimation. |
q |
Order of the polynomial used for bias correction. |
bwselect |
Bandwidth selection procedure used. |
N |
Length-2 vector |
Nh |
An |
covs.cont |
Logical; |
rdmodel |
Human-readable model description string. |
Sebastian Calonico, University of California, Davis [email protected].
Matias D. Cattaneo, Princeton University [email protected].
Max H. Farrell, University of California, Santa Barbara [email protected].
Filippo Palomba, Princeton University [email protected].
Rocio Titiunik, Princeton University [email protected].
Calonico, Cattaneo, Farrell, Palomba and Titiunik (2025): rdhte: Conditional Average Treatment Effects in RD Designs. Working paper.
Calonico, Cattaneo, Farrell, Palomba and Titiunik (2025): Treatment Effect Heterogeneity in Regression Discontinuity Designs. Working paper.
Cattaneo and Titiunik. 2022. Regression Discontinuity Designs. Annual Review of Economics, 14: 821-851.
Calonico, Cattaneo, and Farrell. 2020. Optimal Bandwidth Choice for Robust Bias Corrected Inference in Regression Discontinuity Designs. Econometrics Journal, 23(2): 192-210.
Calonico, Cattaneo, Farrell, and Titiunik. 2019. Regression Discontinuity Designs using Covariates. Review of Economics and Statistics, 101(3): 442-451.
Calonico, Cattaneo, and Titiunik. 2014a. Robust Nonparametric Confidence Intervals for Regression-Discontinuity Designs. Econometrica 82(6): 2295-2326.
Granzier, Pons, and Tricaud. 2023. Coordination and Bandwagon Effects: How Past Rankings Shape the Behavior of Voters and Candidates. American Economic Journal: Applied Economics, 15(4): 177-217.
set.seed(123) n <- 5000 X <- runif(n, -1, 1) W <- rbinom(n, 1, 0.5) Y <- 3 + 2*X + 1.5*X^2 + 0.5*X^3 + sin(2*X) + 3*W*(X>=0) + rnorm(n) rdbwhte.1 = rdbwhte(y=Y, x=X, covs.hte=factor(W)) summary(rdbwhte.1) ## Not run: data(rdhte_dataset) with(rdhte_dataset, { summary(rdbwhte(y = y, x = x, covs.hte = factor(w_ideology), cluster = cluster_var)) summary(rdbwhte(y = y, x = x, covs.hte = factor(w_ideology), cluster = cluster_var, bw.joint = TRUE)) summary(rdbwhte(y = y, x = x, covs.hte = w_strength, cluster = cluster_var)) }) ## End(Not run)set.seed(123) n <- 5000 X <- runif(n, -1, 1) W <- rbinom(n, 1, 0.5) Y <- 3 + 2*X + 1.5*X^2 + 0.5*X^3 + sin(2*X) + 3*W*(X>=0) + rnorm(n) rdbwhte.1 = rdbwhte(y=Y, x=X, covs.hte=factor(W)) summary(rdbwhte.1) ## Not run: data(rdhte_dataset) with(rdhte_dataset, { summary(rdbwhte(y = y, x = x, covs.hte = factor(w_ideology), cluster = cluster_var)) summary(rdbwhte(y = y, x = x, covs.hte = factor(w_ideology), cluster = cluster_var, bw.joint = TRUE)) summary(rdbwhte(y = y, x = x, covs.hte = w_strength, cluster = cluster_var)) }) ## End(Not run)
rdhte provides estimation and inference for heterogeneous
treatment effects in RD designs using local polynomial regressions,
allowing for interactions with pretreatment covariates
(Calonico, Cattaneo, Farrell, Palomba and Titiunik, 2025a).
Inference is implemented using robust bias-correction methods
(Calonico, Cattaneo, and Titiunik, 2014)
Companion commands: rdbwhte for data-driven bandwidth selection
and rdhte_lincom for testing linear restrictions of parameters.
A detailed introduction to the software is given in Calonico, Cattaneo, Farrell, Palomba and Titiunik (2025b).
Related software packages for analysis and interpretation of RD designs and related methods are available in: https://rdpackages.github.io/.
For background methodology, see Calonico, Cattaneo, Farrell, and Titiunik (2019), Calonico, Cattaneo and Farrell (2020), and Cattaneo and Titiunik (2022).
rdhte( y, x, c = 0, covs.hte = NULL, covs.eff = NULL, p = 1, q = NULL, kernel = "tri", weights = NULL, h = NULL, h.l = NULL, h.r = NULL, vce = "hc3", cluster = NULL, level = 95, bwselect = "mserd", bw.joint = FALSE, subset = NULL, data = NULL, target.contrast = NULL )rdhte( y, x, c = 0, covs.hte = NULL, covs.eff = NULL, p = 1, q = NULL, kernel = "tri", weights = NULL, h = NULL, h.l = NULL, h.r = NULL, vce = "hc3", cluster = NULL, level = 95, bwselect = "mserd", bw.joint = FALSE, subset = NULL, data = NULL, target.contrast = NULL )
y |
Outcome variable. |
x |
Running variable. |
c |
RD cutoff in |
covs.hte |
covariates for heterogeneous treatment effects. Factor variables can be used to distinguish between continuous and categorical variables, select reference categories, specify interactions between variables, and include polynomials of continuous variables. If not specified, the RD Average Treatment Effect is computed. |
covs.eff |
additional covariates to be used for efficiency improvements. |
p |
order of the local polynomial used to construct the point estimator (default = 1). |
q |
order of the local polynomial used to construct the bias correction.
If |
kernel |
kernel function used to construct the RD estimators. Options are |
weights |
variable used for optional weighting of the estimation procedure. The unit-specific weights multiply the kernel function. |
h |
main bandwidth used to construct the RD estimator. If not specified, bandwidth |
h.l |
same as |
h.r |
same as |
vce |
character string specifying the variance-covariance matrix
estimator type. Without |
cluster |
variable indicating the clustering of observations. |
level |
confidence level for confidence intervals; default is |
bwselect |
bandwidth selection procedure to be used.
Options are:
|
bw.joint |
logical. If |
subset |
optional vector specifying a subset of observations to be used. |
data |
optional data frame. When supplied, |
target.contrast |
(experimental, in-flight) optional contrast vector or
matrix used to refit the bandwidth to be MSE-optimal for a particular
contrast of the CATE vector. |
A list with the following named elements:
Estimate |
Vector of conventional local-polynomial RD estimates, one per group level (or per slope-coefficient for continuous |
Estimate.bc |
Vector of bias-corrected estimates. Also available as |
se.rb |
Vector of robust bias-corrected standard errors. |
ci.rb |
Matrix ( |
t.rb |
Vector of asymptotic z-statistics (named |
pv.rb |
Vector of two-sided p-values from the standard normal. |
vcov |
Group-level variance-covariance matrix of |
coef.full |
Full coefficient vector from the underlying joint local-polynomial regression (used by |
vcov.full |
Full variance-covariance matrix of |
W.lev |
Group-level identifiers (or coefficient names for continuous |
W.names |
Display labels for the rows of |
kernel |
Kernel type used (e.g. |
bwselect |
Bandwidth selection procedure used. |
vce |
Variance estimator display label (e.g. |
vce_select |
Canonical lowercase variance-estimator name
(e.g. |
c |
Cutoff value. |
h |
An |
p |
Order of the polynomial used for estimation. |
q |
Order of the polynomial used for bias correction. |
N |
Length-2 vector |
Nh |
An |
covs.cont |
Logical; |
level |
Confidence level used. |
rdmodel |
Human-readable model description string. |
Sebastian Calonico, University of California, Davis [email protected].
Matias D. Cattaneo, Princeton University [email protected].
Max H. Farrell, University of California, Santa Barbara [email protected].
Filippo Palomba, Princeton University [email protected].
Rocio Titiunik, Princeton University [email protected].
Calonico, Cattaneo, Farrell, Palomba and Titiunik (2025): rdhte: Conditional Average Treatment Effects in RD Designs. Working paper.
Calonico, Cattaneo, Farrell, Palomba and Titiunik (2025): Treatment Effect Heterogeneity in Regression Discontinuity Designs. Working paper.
Cattaneo and Titiunik. 2022. Regression Discontinuity Designs. Annual Review of Economics, 14: 821-851.
Calonico, Cattaneo, and Farrell. 2020. Optimal Bandwidth Choice for Robust Bias Corrected Inference in Regression Discontinuity Designs. Econometrics Journal, 23(2): 192-210.
Calonico, Cattaneo, Farrell, and Titiunik. 2019. Regression Discontinuity Designs using Covariates. Review of Economics and Statistics, 101(3): 442-451.
Calonico, Cattaneo, and Titiunik. 2014a. Robust Nonparametric Confidence Intervals for Regression-Discontinuity Designs. Econometrica 82(6): 2295-2326.
Granzier, Pons, and Tricaud. 2023. Coordination and Bandwagon Effects: How Past Rankings Shape the Behavior of Voters and Candidates. American Economic Journal: Applied Economics, 15(4): 177-217.
set.seed(123) n <- 1000 X <- runif(n, -1, 1) W <- rbinom(n, 1, 0.5) Y <- 3 + 2*X + 1.5*X^2 + 0.5*X^3 + sin(2*X) + 3*W*(X>=0) + rnorm(n) m1 = rdhte(y = Y, x = X, covs.hte = factor(W)) summary(m1) ## Not run: # Empirical examples using the bundled Granzier, Pons, and Tricaud data. data(rdhte_dataset) with(rdhte_dataset, { rd_left <- rdhte(y = y, x = x, covs.hte = factor(w_left), cluster = cluster_var) summary(rd_left) rdhte_lincom(rd_left, linfct = "`factor(w_left)1` - `factor(w_left)0` = 0") summary(rdhte(y = y, x = x, covs.hte = factor(w_left), cluster = cluster_var, bw.joint = TRUE)) summary(rdhte(y = y, x = x, covs.hte = factor(w_left):factor(w_strong), cluster = cluster_var)) summary(rdhte(y = y, x = x, covs.hte = w_strength, kernel = "uni", cluster = cluster_var)) }) ## End(Not run)set.seed(123) n <- 1000 X <- runif(n, -1, 1) W <- rbinom(n, 1, 0.5) Y <- 3 + 2*X + 1.5*X^2 + 0.5*X^3 + sin(2*X) + 3*W*(X>=0) + rnorm(n) m1 = rdhte(y = Y, x = X, covs.hte = factor(W)) summary(m1) ## Not run: # Empirical examples using the bundled Granzier, Pons, and Tricaud data. data(rdhte_dataset) with(rdhte_dataset, { rd_left <- rdhte(y = y, x = x, covs.hte = factor(w_left), cluster = cluster_var) summary(rd_left) rdhte_lincom(rd_left, linfct = "`factor(w_left)1` - `factor(w_left)0` = 0") summary(rdhte(y = y, x = x, covs.hte = factor(w_left), cluster = cluster_var, bw.joint = TRUE)) summary(rdhte(y = y, x = x, covs.hte = factor(w_left):factor(w_strong), cluster = cluster_var)) summary(rdhte(y = y, x = x, covs.hte = w_strength, kernel = "uni", cluster = cluster_var)) }) ## End(Not run)
rdhte_contrast refits an rdhte model at the
MSE-optimal bandwidth for a single user-chosen linear combination of the
Estimate vector and returns the resulting point estimate, robust
bias-corrected estimate, standard error, p-value, and confidence interval.
rdhte_contrast(model, contrast, refit = TRUE, level = 95, tol = 1e-10)rdhte_contrast(model, contrast, refit = TRUE, level = 95, tol = 1e-10)
model |
A fitted model returned by |
contrast |
Numeric vector with length equal to |
refit |
Logical. |
level |
Confidence level in percentage form, in |
tol |
Tolerance below which the estimated contrast bias is treated as zero and the contrast-targeted bandwidth is declared undefined. |
Use rdhte_lincom instead when you want joint Wald inference on
several linear restrictions at one bandwidth.
A list with the conventional estimate, robust bias-corrected estimate,
robust standard error, z-statistic, p-value, confidence interval, selected
bandwidth, pilot bandwidth, contrast diagnostics, and (when
refit = TRUE) the refitted rdhte object.
## Not run: set.seed(123) n <- 1000 X <- runif(n, -1, 1) W <- rbinom(n, 1, 0.5) Y <- 3 + 2 * X + 1.5 * X^2 + 3 * W * (X >= 0) + rnorm(n) m <- rdhte(y = Y, x = X, covs.hte = factor(W)) rdhte_contrast(m, contrast = c(-1, 1)) ## End(Not run)## Not run: set.seed(123) n <- 1000 X <- runif(n, -1, 1) W <- rbinom(n, 1, 0.5) Y <- 3 + 2 * X + 1.5 * X^2 + 3 * W * (X >= 0) + rnorm(n) m <- rdhte(y = Y, x = X, covs.hte = factor(W)) rdhte_contrast(m, contrast = c(-1, 1)) ## End(Not run)
A working extract of the data used in Granzier, Pons, and Tricaud
(2023, AEJ: Applied), distributed with the rdhte package as a
fixed-format example dataset for the package vignette and worked
examples. The running variable x is the candidate's
first-round margin against the threshold for advancing to the
runoff; y is an indicator for advancing.
data("rdhte_dataset")data("rdhte_dataset")
A data frame with 39,534 observations on the following variables.
yOutcome: indicator (0/1) for advancing to the runoff.
xRunning variable: first-round margin against the qualifying threshold (the cutoff is at zero).
cluster_varCluster identifier (district).
w_leftBinary: 1 if the candidate's party is left of center, 0 otherwise.
w_ideologyUnordered categorical (4 levels): party ideology bucket.
w_strengthContinuous: candidate's average prior national-level vote share, used as a proxy for ex-ante candidate strength.
w_strongBinary: above-median strength
(w_strength).
w_strength_qrtOrdered categorical (4 levels):
quartile bucket of w_strength.
Granzier, R., V. Pons, and C. Tricaud (2023). Coordination and Bandwagon Effects: How Past Rankings Shape the Behavior of Voters and Candidates. American Economic Journal: Applied Economics 15(4): 177-217.
data(rdhte_dataset) str(rdhte_dataset)data(rdhte_dataset) str(rdhte_dataset)
rdhte_lincom computes point estimates, p-values, and
robust bias-corrected confidence intervals for linear combinations of
parameters after any estimation using rdhte
(Calonico, Cattaneo, Farrell, Palomba and Titiunik, 2025a).
Inference is implemented using robust bias-correction methods
(Calonico, Cattaneo, and Titiunik, 2014). It is based on the R function
glht.
Companion commands: rdhte for estimation and inference of RD-HTE
and rdbwhte for data-driven bandwidth selection.
A detailed introduction to the software is given in Calonico, Cattaneo, Farrell, Palomba and Titiunik (2025b).
Related software packages for analysis and interpretation of RD designs and related methods are available in: https://rdpackages.github.io/.
For background methodology, see Calonico, Cattaneo, Farrell, and Titiunik (2019), Calonico, Cattaneo and Farrell (2020), and Cattaneo and Titiunik (2022).
rdhte_lincom(model, linfct, level = 95, digits = 3)rdhte_lincom(model, linfct, level = 95, digits = 3)
model |
a fitted model returned by |
linfct |
a specification of the linear hypotheses to be tested. Linear functions can be specified by either the matrix of coefficients or by symbolic descriptions of one or more linear hypotheses. |
level |
Confidence level for intervals (percentage form, in |
digits |
Number of decimal places to format numeric outputs (default 3). |
A list with two data frames:
individualOne row per hypothesis. Columns: hypothesis, estimate (conventional point estimate of the linear combination), z_stat (asymptotic z-statistic from the bias-corrected fit), p_value (two-sided p-value from the standard normal), conf.low, conf.high (robust bias-corrected CI bounds at the requested confidence level).
jointOne row. Columns: statistic (Wald chi-squared from the bias-corrected fit), df (number of restrictions), p_value.
Numeric columns are rounded to digits decimal places.
Sebastian Calonico, University of California, Davis [email protected].
Matias D. Cattaneo, Princeton University [email protected].
Max H. Farrell, University of California, Santa Barbara [email protected].
Filippo Palomba, Princeton University [email protected].
Rocio Titiunik, Princeton University [email protected].
Calonico, Cattaneo, Farrell, Palomba and Titiunik (2025): rdhte: Conditional Average Treatment Effects in RD Designs. Working paper.
Calonico, Cattaneo, Farrell, Palomba and Titiunik (2025): Treatment Effect Heterogeneity in Regression Discontinuity Designs. Working paper.
Cattaneo and Titiunik. 2022. Regression Discontinuity Designs. Annual Review of Economics, 14: 821-851.
Calonico, Cattaneo, and Farrell. 2020. Optimal Bandwidth Choice for Robust Bias Corrected Inference in Regression Discontinuity Designs. Econometrics Journal, 23(2): 192-210.
Calonico, Cattaneo, Farrell, and Titiunik. 2019. Regression Discontinuity Designs using Covariates. Review of Economics and Statistics, 101(3): 442-451.
Calonico, Cattaneo, and Titiunik. 2014a. Robust Nonparametric Confidence Intervals for Regression-Discontinuity Designs. Econometrica 82(6): 2295-2326.
Granzier, Pons, and Tricaud. 2023. Coordination and Bandwagon Effects: How Past Rankings Shape the Behavior of Voters and Candidates. American Economic Journal: Applied Economics, 15(4): 177-217.
set.seed(123) n <- 1000 X <- runif(n, -1, 1) W <- rbinom(n, 1, 0.5) Y <- 3 + 2*X + 1.5*X^2 + 0.5*X^3 + sin(2*X) + 3*W*(X>=0) + rnorm(n) m1 <- rdhte(y = Y, x = X, covs.hte = factor(W)) linfct <- c("`factor(W)0` - `factor(W)1` = 0") rdhte_lincom(model = m1, linfct = linfct) ## Not run: data(rdhte_dataset) with(rdhte_dataset, { rd_ideology <- rdhte(y = y, x = x, covs.hte = factor(w_ideology), cluster = cluster_var) rdhte_lincom(rd_ideology, linfct = c("`factor(w_ideology)4` - `factor(w_ideology)3` = 0", "`factor(w_ideology)4` = 0")) }) ## End(Not run)set.seed(123) n <- 1000 X <- runif(n, -1, 1) W <- rbinom(n, 1, 0.5) Y <- 3 + 2*X + 1.5*X^2 + 0.5*X^3 + sin(2*X) + 3*W*(X>=0) + rnorm(n) m1 <- rdhte(y = Y, x = X, covs.hte = factor(W)) linfct <- c("`factor(W)0` - `factor(W)1` = 0") rdhte_lincom(model = m1, linfct = linfct) ## Not run: data(rdhte_dataset) with(rdhte_dataset, { rd_ideology <- rdhte(y = y, x = x, covs.hte = factor(w_ideology), cluster = cluster_var) rdhte_lincom(rd_ideology, linfct = c("`factor(w_ideology)4` - `factor(w_ideology)3` = 0", "`factor(w_ideology)4` = 0")) }) ## End(Not run)