Title: | Yatchew (1997), De Chaisemartin & D'Haultfoeuille (2024) Linearity Test |
---|---|
Description: | Test of linearity originally proposed by Yatchew (1997) <doi:10.1016/S0165-1765(97)00218-8> and improved by de Chaisemartin & D'Haultfoeuille (2024) <doi:10.2139/ssrn.4284811> to be robust under heteroskedasticity. |
Authors: | Diego Ciccia [aut, cre], Felix Knau [aut], Doulo Sow [aut], Clément de Chaisemartin [aut], Xavier D'Haultfoeuille [aut] |
Maintainer: | Diego Ciccia <[email protected]> |
License: | MIT + file LICENSE |
Version: | 1.1.1 |
Built: | 2025-02-19 06:49:09 UTC |
Source: | CRAN |
Test of Linearity of a Conditional Expectation Function (Yatchew, 1997; de Chaisemartin and D'Haultfoeuille, 2024)
yatchew_test(data, ...)
yatchew_test(data, ...)
data |
A data object. |
... |
Undocumented. |
Method dispatch depending on the data object class.
General yatchew_test method for unclassed dataframes
## S3 method for class 'data.frame' yatchew_test(data, Y, D, het_robust = FALSE, path_plot = FALSE, order = 1, ...)
## S3 method for class 'data.frame' yatchew_test(data, Y, D, het_robust = FALSE, path_plot = FALSE, order = 1, ...)
data |
(data.frame) A dataframe. |
Y |
(char) Dependent variable. |
D |
(char) Independent variable. |
het_robust |
(logical) If FALSE, the test is performed under the assumption of homoskedasticity (Yatchew, 1997). If TRUE, the test is performed using the heteroskedasticity-robust test statistic proposed by de Chaisemartin and D'Haultfoeuille (2024). |
path_plot |
(logical) if TRUE and |
order |
(nonnegative integer k) If this option is specified, the program tests whether the conditional expectation of |
... |
Undocumented. |
A list with test results.
This program implements the linearity test proposed by Yatchew (1997) and its heteroskedasticity-robust version proposed by de Chaisemartin and D'Haultfoeuille (2024). In this overview, we sketch the intuition behind the two tests, as to motivate the use of the package and its options. Please refer to Yatchew (1997) and Section 3 of de Chaisemartin and D'Haultfoeuille (2024) for further details.
Yatchew (1997) proposes a useful extension of the test with multiple independent variables.
The program implements this extension when the D
argument has length .
It should be noted that the power and consistency of the test in the multivariate case are not backed by proven theoretical results.
We implemented this extension to allow for testing and exploratory research.
Future theoretical exploration of the multivariate test will depend on the demand and usage of the package.
Let and
be two random variables.
Let
.
The null hypothesis of the test is that
for two real numbers
and
.
This means that, under the null,
is linear in
.
The outcome variable can be decomposed as
, with
and
for
.
In a dataset with
i.i.d. realisations of
, one can test this hypothesis as follows:
sort the dataset by ;
denote the corresponding observations by , with
;
approximate , i.e. the variance of the first differenced residuals
, by the variance of
;
compute , i.e. the variance of the residuals from an OLS regression of
on
.
Heuristically, the validity of step (3) derives from the fact that =
+
and the first difference term is close to zero for
.
Sorting at step (1) ensures that consecutive
s are as close as possible, and when the sample size goes to infinity the distance between consecutive observations goes to zero.
Then, Yatchew (1997) shows that under homoskedasticity and regularity conditions
Then, one can reject the linearity of with significance level
if
.
If the homoskedasticity assumption fails, this test leads to overrejection.
De Chaisemartin and D'Haultfoeuille (2024) propose a heteroskedasticity-robust version of the test statistic above.
This version of the Yatchew (1997) test can be implemented by running the command with the option het_robust = TRUE
.
Let be a vector of
random variables.
Let
.
Denote with
the Euclidean distance between two vectors.
The null hypothesis of the multivariate test is
, with
, for
real numbers
,
, ...,
.
This means that, under the null,
is linear in
.
Following the same logic as the univariate case, in a dataset with
i.i.d. realisations of
we can approximate the first difference
by
valuing
between consecutive observations.
The program runs a nearest neighbor algorithm to find the sequence of observations such that the Euclidean distance between consecutive positions is minimized.
The algorithm has been programmed in C++ and it has been integrated in R thanks to the
Rcpp
library. The program follows a very simple nearest neighbor approach:
collect all the Euclidean distances between all the possible unique pairs of rows in in the matrix
, where
with
;
setup the queue to , the (empty) path vector
and the starting index
;
remove from
and find the column index
of M such that
;
append to
and start again from step 3 with
until
is empty.
To improve efficiency, the program collects only the Euclidean distances corresponding to the lower triangle of matrix
and chooses
such that
.
The output of the algorithm, i.e. the vector
, is a sequence of row numbers such that the distance between the corresponding rows
s is minimized.
The program also uses two refinements suggested in Appendix A of Yatchew (1997):
The entries in are normalized in
;
The algorithm is applied to sub-cubes, i.e. partitions of the space, and the full path is obtained by joining the extrema of the subpaths.
By convention, the program computes subcubes, where each univariate partition is defined by grouping observations in
quantile bins. If
, the user can visualize in a ggplot graph the exact path across the normalized
s by running the command with the option
path_plot = TRUE
.
Once the dataset is sorted by , the program resumes from step (2) of the univariate case.
If you wish to inquire about the functionalities of this package or to report bugs/suggestions, feel free to post your question in the Issues section of the yatchew_test GitHub repository.
de Chaisemartin, C., d'Haultfoeuille, X. (2024). Two-way Fixed Effects and Difference-in-Difference Estimators in Heterogeneous Adoption Designs.
Yatchew, A. (1997). An elementary estimator of the partial linear model.
df <- as.data.frame(matrix(NA, nrow = 1E3, ncol = 0)) df$x <- rnorm(1E3) df$b <- runif(1E3) df$y <- 2 + df$b * df$x yatchew_test(data = df, Y = "y", D = "x")
df <- as.data.frame(matrix(NA, nrow = 1E3, ncol = 0)) df$x <- rnorm(1E3) df$b <- runif(1E3) df$y <- 2 + df$b * df$x yatchew_test(data = df, Y = "y", D = "x")