Title: | Linear Specification Testing |
---|---|
Description: | Tests whether the linear hypothesis of a model is correct specified using Dominguez-Lobato test. Also Ramsey's RESET (Regression Equation Specification Error Test) test is implemented and Wald tests can be carried out. Although RESET test is widely used to test the linear hypothesis of a model, Dominguez and Lobato (2019) proposed a novel approach that generalizes well known specification tests such as Ramsey's. This test relies on wild-bootstrap; this package implements this approach to be usable with any function that fits linear models and is compatible with the update() function such as 'stats'::lm(), 'lfe'::felm() and 'forecast'::Arima(), for ARMA (autoregressive–moving-average) models. Also the package can handle custom statistics such as Cramer von Mises and Kolmogorov Smirnov, described by the authors, and custom distributions such as Mammen (discrete and continuous) and Rademacher. Manuel A. Dominguez & Ignacio N. Lobato (2019) <doi:10.1080/07474938.2019.1687116>. |
Authors: | Federico Garza [aut, cre] |
Maintainer: | Federico Garza <[email protected]> |
License: | GPL (>= 2) |
Version: | 1.0.0 |
Built: | 2024-11-15 04:52:10 UTC |
Source: | https://github.com/azulgarza/lineartestr |
Tests the specification of a linear model using wild-bootstrap.
dominguez_lobato_test( model, distribution = "rnorm", statistic = "cvm_value", times = 300, quantiles = c(0.9, 0.95, 0.99), verbose = FALSE, n_cores = 1 )
dominguez_lobato_test( model, distribution = "rnorm", statistic = "cvm_value", times = 300, quantiles = c(0.9, 0.95, 0.99), verbose = FALSE, n_cores = 1 )
model |
An existing fit from a model function such as 'lm', 'lfe' and others compatible with 'update'. |
distribution |
Type of noise added to residuals, ej 'rnorm' or 'rrademacher'. |
statistic |
Type of statistic to be used, can be one of 'cvm_value' or 'kmv_value'. |
times |
Number of bootstrap samples. |
quantiles |
Vector of quantiles to calculate pvalues. |
verbose |
TRUE to print each bootstrap iteration. |
n_cores |
Number of cores to be used. |
A list with dataframe results and the ordered values of each bootstrap iteration.
Manuel A. Dominguez and Ignacio N. Lobato (2019). Specification Testing with Estimated Variables. Econometric Reviews.
x <- 1:10 + rnorm(10) y <- 1:10 model <- lm(y~x) dl_test <- dominguez_lobato_test(model) dl_test <- dominguez_lobato_test(model, distribution = "rmammen_point", statistic = "kmv_value") dl_test <- dominguez_lobato_test(model, times = 100)
x <- 1:10 + rnorm(10) y <- 1:10 model <- lm(y~x) dl_test <- dominguez_lobato_test(model) dl_test <- dominguez_lobato_test(model, distribution = "rmammen_point", statistic = "kmv_value") dl_test <- dominguez_lobato_test(model, times = 100)
Plots the Dominguez-Lobato test.
plot_dl_test(x)
plot_dl_test(x)
x |
An object of class 'dl_test'. |
Plot of type ggplot.
x <- 1:10 y <- 1:10 model <- lm(y~x-1) dl_test <- dominguez_lobato_test(model) plot_dl_test(dl_test)
x <- 1:10 y <- 1:10 model <- lm(y~x-1) dl_test <- dominguez_lobato_test(model) plot_dl_test(dl_test)
Plot the reset test.
plot_reset_test(x)
plot_reset_test(x)
x |
An object of class 'reset_test'. |
Plot of type ggplot.
x <- 1:10 + rnorm(10) y <- 1:10 model <- lm(y~x-1) r_test <- reset_test(model) plot_reset_test(r_test)
x <- 1:10 + rnorm(10) y <- 1:10 model <- lm(y~x-1) r_test <- reset_test(model) plot_reset_test(r_test)
Calculates the accumulated distribution of residuals at each residual point.
presiduals(fitted_values, resids)
presiduals(fitted_values, resids)
fitted_values |
Vector of fitted values. |
resids |
Residuals vector of each fitted value. |
Vector of size length(resids).
y_hat <- c(4, 8, 7) resids <- c(1, 5, 3) presiduals(y_hat, resids)
y_hat <- c(4, 8, 7) resids <- c(1, 5, 3) presiduals(y_hat, resids)
Reset test. Tests the specification of a linear model adding and testing powers of fitted values.
reset_test( model, robust = FALSE, vcov = NULL, max_power = 3, quantiles = c(0.9, 0.95, 0.99) )
reset_test( model, robust = FALSE, vcov = NULL, max_power = 3, quantiles = c(0.9, 0.95, 0.99) )
model |
An existing fit from a model function such as 'lm', 'lfe' and others compatible with 'update'. |
robust |
Use robust 'varcov' matrix. |
vcov |
Particular variance and covariances matrix. |
max_power |
Max power of fitted values to add. |
quantiles |
Vector of quantiles to calculate pvalues. |
A 'tibble' with the Wald value, the corresponding pvalue, and the quantiles of the distribution.
x <- 1:10 + rnorm(10) y <- 1:10 model <- lm(y~x) r_test <- reset_test(model) r_test <- reset_test(model, robust = TRUE) r_test <- reset_test(model, quantiles = c(.97)) r_test <- reset_test(model, max_power = 4) r_test <- reset_test(model, robust = TRUE, max_power = 4)
x <- 1:10 + rnorm(10) y <- 1:10 model <- lm(y~x) r_test <- reset_test(model) r_test <- reset_test(model, robust = TRUE) r_test <- reset_test(model, quantiles = c(.97)) r_test <- reset_test(model, max_power = 4) r_test <- reset_test(model, robust = TRUE, max_power = 4)
Random deviates of Mammen continuous distribution.
rmammen_cont(n)
rmammen_cont(n)
n |
Number of observations. |
Random deviates of size n.
rmammen_cont(10)
rmammen_cont(10)
Random deviates of Mammen distribution.
rmammen_point(n)
rmammen_point(n)
n |
Number of observations. |
Random deviates of size n.
rmammen_point(10)
rmammen_point(10)
Random deviates of Rademacher distribution.
rrademacher(n)
rrademacher(n)
n |
Number of observations. |
Random deviates of size n.
rrademacher(10)
rrademacher(10)
Calculates the Cramer von Mises value or Kolmogorov value given a linear model compatible with 'fitted.values' and 'residuals' functions.
statistic_value(model, value = "cvm_value")
statistic_value(model, value = "cvm_value")
model |
An existing fit from a linear model function. |
value |
Type of value to compute, can be 'cvm_value' or 'kmv_value'. |
The statistic value of the model.
x <- 1:10 y <- 2*x + rnorm(10) model <- lm(y~x-1) statistic_value(model) statistic_value(model, value = "cvm_value") statistic_value(model, value = "kmv_value")
x <- 1:10 y <- 2*x + rnorm(10) model <- lm(y~x-1) statistic_value(model) statistic_value(model, value = "cvm_value") statistic_value(model, value = "kmv_value")
Constructs a new model with noised residuals: y_new = y_fitted + residuals*noise
updated_model(model, fitting_data, distribution = "rnorm")
updated_model(model, fitting_data, distribution = "rnorm")
model |
An existing fit from a model function such as 'lm', 'lfe', 'Arima' and others compatible with 'update'. |
fitting_data |
Data used to adjust a linear model. |
distribution |
Type of noise added to residuals, ej "rnorm" or "rrademacher". |
Constructed linear model.
x <- 1:100 y <- 2*x + rnorm(100) model <- lm(y~x-1) fitting_data <- model.frame(model) updated_model(model, fitting_data) updated_model(model, fitting_data, distribution = "rnorm") updated_model(model, fitting_data, distribution = "rmammen_point") updated_model(model, fitting_data, distribution = "rmammen_cont") updated_model(model, fitting_data, distribution = "rrademacher") x_arma <- rnorm(100) arma_model <- forecast::Arima(x_arma, c(1, 0, 1)) fitting_data_arma <- model.frame(arma_model) updated_model(arma_model, fitting_data_arma)
x <- 1:100 y <- 2*x + rnorm(100) model <- lm(y~x-1) fitting_data <- model.frame(model) updated_model(model, fitting_data) updated_model(model, fitting_data, distribution = "rnorm") updated_model(model, fitting_data, distribution = "rmammen_point") updated_model(model, fitting_data, distribution = "rmammen_cont") updated_model(model, fitting_data, distribution = "rrademacher") x_arma <- rnorm(100) arma_model <- forecast::Arima(x_arma, c(1, 0, 1)) fitting_data_arma <- model.frame(arma_model) updated_model(arma_model, fitting_data_arma)
Wald test. Tests restrictions*coefficients = value.
wald_test( model, restrictions, value, robust = FALSE, vcov = NULL, quantiles = c(0.9, 0.95, 0.99) )
wald_test( model, restrictions, value, robust = FALSE, vcov = NULL, quantiles = c(0.9, 0.95, 0.99) )
model |
Model compatible with 'fitted' and 'residuals' functions. |
restrictions |
Matrix of size (number of restrictions) times length(coefficients), for free restrictions use zeros. |
value |
Values of restrictions. |
robust |
Use robust 'varcov' matrix. |
vcov |
Particular variance and covariances matrix. |
quantiles |
Vector of quantiles to calculate pvalues. |
A 'tibbble' with the Wald value, the corresponding pvalue and the quantiles of the distribution.
x <- 1:10 z <- x**2 y <- 1:10 model <- lm(y~x+z) restrictions <- diag(3) value <- as.matrix(c(0, 0, 0)) w_test <- wald_test(model, restrictions, value) w_test <- wald_test(model, restrictions, value, robust = TRUE) w_test <- wald_test(model, restrictions, value, quantiles = c(.97))
x <- 1:10 z <- x**2 y <- 1:10 model <- lm(y~x+z) restrictions <- diag(3) value <- as.matrix(c(0, 0, 0)) w_test <- wald_test(model, restrictions, value) w_test <- wald_test(model, restrictions, value, robust = TRUE) w_test <- wald_test(model, restrictions, value, quantiles = c(.97))