The goal of lineartestr
is to contrast the linear
hypothesis of a model:
Using the DomÃnguez-Lobato test which relies on wild-bootstrap. Also the Ramsey RESET test is implemented.
You can install the released version of lineartestr
from
CRAN with:
install.packages("lineartestr")
And the development version from GitHub with:
# install.packages("devtools")
::install_github("FedericoGarza/lineartestr") devtools
lm
functionlibrary(lineartestr)
<- 1:100
x <- 1:100
y
<- lm(y~x)
lm_model
<- dominguez_lobato_test(lm_model) dl_test
::glimpse(dl_test$test)
dplyr#> Observations: 1
#> Variables: 7
#> $ name_distribution <chr> "rnorm"
#> $ name_statistic <chr> "cvm_value"
#> $ statistic <dbl> 7.562182e-29
#> $ p_value <dbl> 0.4066667
#> $ quantile_90 <dbl> 2.549223e-28
#> $ quantile_95 <dbl> 3.887169e-28
#> $ quantile_99 <dbl> 6.359681e-28
Also lineartestr
can plot the results
plot_dl_test(dl_test)
library(lineartestr)
<- 1:1e5
x_p <- 1:1e5
y_p
<- lm(y_p~x_p)
lm_model_p
<- dominguez_lobato_test(lm_model_p, n_cores=7) dl_test_p
::glimpse(dl_test_p$test)
dplyr#> Observations: 1
#> Variables: 7
#> $ name_distribution <chr> "rnorm"
#> $ name_statistic <chr> "cvm_value"
#> $ statistic <dbl> 6.324343e-21
#> $ p_value <dbl> 0.3566667
#> $ quantile_90 <dbl> 1.902697e-20
#> $ quantile_95 <dbl> 2.532663e-20
#> $ quantile_99 <dbl> 4.141126e-20
library(lineartestr)
<- 1:100 + rnorm(100)
x <- 1:100
y
<- lm(y~x)
lm_model
<- reset_test(lm_model) r_test
::glimpse(r_test)
dplyr#> Observations: 1
#> Variables: 6
#> $ statistic <dbl> 0.7797557
#> $ p_value <dbl> 0.6771396
#> $ df <int> 2
#> $ quantile_90 <dbl> 4.60517
#> $ quantile_95 <dbl> 5.991465
#> $ quantile_99 <dbl> 9.21034
An then we can plot the results
plot_reset_test(r_test)
lfe
library(lineartestr)
library(dplyr)
#>
#> Attaching package: 'dplyr'
#> The following objects are masked from 'package:stats':
#>
#> filter, lag
#> The following objects are masked from 'package:base':
#>
#> intersect, setdiff, setequal, union
library(lfe)
#> Loading required package: Matrix
# This example was taken from https://www.rdocumentation.org/packages/lfe/versions/2.8-5/topics/felm
<- rnorm(1000)
x <- rnorm(length(x))
x2 # Individuals and firms
<- factor(sample(20,length(x),replace=TRUE))
id <- factor(sample(13,length(x),replace=TRUE))
firm # Effects for them
<- rnorm(nlevels(id))
id.eff <- rnorm(nlevels(firm))
firm.eff # Left hand side
<- rnorm(length(x))
u <- x + 0.5*x2 + id.eff[id] + firm.eff[firm] + u
y <- y + rnorm(length(y))
new_y ## Estimate the model
<- lfe::felm(y ~ x + x2 | id + firm)
est
## Testing the linear hypothesis and plotting results
dominguez_lobato_test(est, n_cores = 7) %>%
plot_dl_test()
library(lineartestr)
library(dplyr)
<- rnorm(100)**3
x
<- forecast::Arima(x, order = c(1, 0, 1))
arma_model #> Registered S3 method overwritten by 'xts':
#> method from
#> as.zoo.xts zoo
#> Registered S3 method overwritten by 'quantmod':
#> method from
#> as.zoo.data.frame zoo
#> Registered S3 methods overwritten by 'forecast':
#> method from
#> fitted.fracdiff fracdiff
#> residuals.fracdiff fracdiff
dominguez_lobato_test(arma_model) %>%
plot_dl_test()