Conditional Kolmogorov test statistic for the joint distribution of (X,Y)
Source:R/CondKolmXY.R
CondKolmXY.Rd
This class inherits from TestStatistic and implements a function to calculate the test statistic (and x-y-values that can be used to plot the underlying process).
The process underlying the test statistic is given in Andrews (1997) doi:10.2307/2171880 and defined by $$\nu_n(x,y) = \frac{1}{\sqrt{n}} \sum_{i=1}^n \left(I_{\{Y_i \le y\}} - F(y|\hat{\vartheta}_n, X_i) \right) I_{\{X_i \le x\}},\quad (x,y) \in R^{p+1}.$$
Super class
gofreg::TestStatistic
-> CondKolmXY
Methods
Method calc_stat()
Calculate the value of the test statistic for given data and a model to test for.
Arguments
data
data.frame()
with columns x and y containing the datamodel
ParamRegrModel to test for, already fitted to the data
Examples
# Create an example dataset
n <- 100
x <- cbind(runif(n), rbinom(n, 1, 0.5))
model <- NormalGLM$new()
y <- model$sample_yx(x, params=list(beta=c(2,3), sd=1))
data <- dplyr::tibble(x = x, y = y)
# Fit the correct model
model$fit(data, params_init=list(beta=c(1,1), sd=3), inplace = TRUE)
# Print value of test statistic and plot corresponding process
ts <- CondKolmXY$new()
ts$calc_stat(data, model)
print(ts)
#> Test statistic with value 0.3495807
plot(ts)
# Fit a wrong model
model2 <- NormalGLM$new(linkinv = function(u) {u+10})
model2$fit(data, params_init=list(beta=c(1,1), sd=3), inplace = TRUE)
# Print value of test statistic and plot corresponding process
ts2 <- CondKolmXY$new()
ts2$calc_stat(data, model2)
print(ts2)
#> Test statistic with value 3.791774
plot(ts2)