GOFTest: Goodness-of-fit test for parametric regression

GOFTestR Documentation

Goodness-of-fit test for parametric regression

Description

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

Public 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 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()

Returns

a new instance of the class


Method get_stat_orig()

Calculates the test statistic for the original data and model.

Usage
GOFTest$get_stat_orig()
Returns

object of class TestStatistic


Method get_stats_boot()

Calculates the test statistics for the resampled data and corresponding models.

Usage
GOFTest$get_stats_boot()
Returns

vector of length nboot containing objects of class TestStatistic


Method get_pvalue()

Calculates the bootstrap p-value for the given model.

Usage
GOFTest$get_pvalue()
Returns

p-value for the null hypothesis that y was generated according to model


Method plot_procs()

Plots the processes underlying the bootstrap test statistics (gray) and the original test statistic (red)

Usage
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"
)
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"

Returns

The object (self), allowing for method chaining.


Method clone()

The objects of this class are cloneable with this method.

Usage
GOFTest$clone(deep = FALSE)
Arguments
deep

Whether to make a deep clone.

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()
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()

gofreg documentation built on Oct. 4, 2024, 5:10 p.m.