GOFTest | R Documentation |
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.
new()
Initialize an instance of class GOFTest.
GOFTest$new( data, model_fitted, test_stat, nboot, resample = resample_param, loglik = loglik_xy )
data
data.frame()
containing the data
model_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 to resample_param()
loglik
function(data, model, params)
negative log-likelihood
function used to fit model to resampled data in bootstrap iterations,
defaults to loglik_xy()
a new instance of the class
get_stat_orig()
Calculates the test statistic for the original data and model.
GOFTest$get_stat_orig()
object of class TestStatistic
get_stats_boot()
Calculates the test statistics for the resampled data and corresponding models.
GOFTest$get_stats_boot()
vector of length nboot
containing objects of class
TestStatistic
get_pvalue()
Calculates the bootstrap p-value for the given model.
GOFTest$get_pvalue()
p-value for the null hypothesis that y
was generated according
to model
plot_procs()
Plots the processes underlying the bootstrap test statistics (gray) and the original test statistic (red)
GOFTest$plot_procs( title = sprintf("Test Statistic: %s, p-value: %s", class(private$test_stat)[1], self$get_pvalue()), subtitle = ggplot2::waiver(), color_boot = "gray40", color_orig = "red", x_lab = "plot.x", y_lab = "plot.y" )
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"
The object (self
), allowing for method chaining.
clone()
The objects of this class are cloneable with this method.
GOFTest$clone(deep = FALSE)
deep
Whether to make a deep clone.
# 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()
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()
goftest2$plot_procs()
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.