This class implements functions to calculate the test statistic for the original data as well as the statistics for bootstrap samples. It also offers the possibility to compute the corresponding bootstrap p-value.
Methods
Method new()
Initialize an instance of class GOFTest.
Usage
GOFTest$new(
data,
model_fitted,
test_stat,
nboot,
resample = resample_param,
loglik = loglik_xy
)
Arguments
data
data.frame()
containing the datamodel_fitted
object of class ParamRegrModel with fitted parameters
test_stat
object of class TestStatistic
nboot
number of bootstrap iterations
resample
function(data, model)
used to resample data in bootstrap iterations, defaults toresample_param()
loglik
function(data, model, params)
negative log-likelihood function used to fit model to resampled data in bootstrap iterations, defaults tologlik_xy()
Method get_stat_orig()
Calculates the test statistic for the original data and model.
Returns
object of class TestStatistic
Method get_stats_boot()
Calculates the test statistics for the resampled data and corresponding models.
Returns
vector of length nboot
containing objects of class
TestStatistic
Method plot_procs()
Plots the processes underlying the bootstrap test statistics (gray) and the original test statistic (red)
Arguments
title
text to be displayed as title of the plot; defaults to "Test statistic: xxx, p-value: xxx"
subtitle
text to be displayed as subtitle of the plot; default is no subtitle
color_boot
color used to plot bootstrap test statistics; default is "red"
color_orig
color used to plot original test statistic; default is "gray40"
x_lab
label to use for the x-axis; default is "plot.x"
y_lab
label to use for the y-axis; default is "plot.y"
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)
# Calculate the bootstrap p-value and plot the corresponding processes
goftest <- GOFTest$new(data, model, test_stat = CondKolmY$new(), nboot = 10)
goftest$get_pvalue()
#> [1] 0.6
goftest$plot_procs()
# 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)
# Calculate the bootstrap p-value and plot the corresponding processes
goftest2 <- GOFTest$new(data, model2, test_stat = CondKolmY$new(), nboot = 10)
goftest2$get_pvalue()
#> [1] 0
goftest2$plot_procs()