This R package provides classes and methods to fit parametric regression models to given data and to perform bootstrap-based goodness-of-fit tests using different test statistics.
The data can either consist of \((X,Y)\) pairs of covariates and response variables or in case of random censorship it consists of tuples \((X, Z, \delta)\) denoting covariates, censored survival times and censoring indicators. The package includes different parametric regression models (mostly generalized linear models) and test statistics (based on different papers). It can easily be extended by other user-defined models and test statistics.
You can install it from CRAN
install.packages("gofreg")
or github
::install_github("gkremling/gofreg") devtools
This is a basic example which shows how to fit a parametric
regression model to a given dataset and afterwards perform a
goodness-of-fit test. In this example, we use the dataset
datasets::cars
, a generalized linear model with normal
distribution and the conditional Kolmogorov test statistic of the
marginal distribution of \(Y\) defined
in Kremling & Dikta (2024) arXiv:2409.20262.
library(gofreg)
set.seed(123)
<- dplyr::tibble(x = datasets::cars$speed, y = datasets::cars$dist)
data <- GLM.new(distr = "normal", linkinv = identity)
model $fit(data, params_init = list(beta = 3, sd = 2), inplace = TRUE)
modelprint(model$get_params())
#> $beta
#> [1] 2.908838
#>
#> $sd
#> [1] 16.09429
<- GOFTest$new(data = data, model_fitted = model, test_stat = CondKolmY$new(), nboot = 100)
gt print(gt$get_pvalue())
#> [1] 0.01
$plot_procs() gt