Learn R Programming

gofreg

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.

Installation

You can install it from CRAN

install.packages("gofreg")

or github

devtools::install_github("gkremling/gofreg")

Example

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)

data <- dplyr::tibble(x = datasets::cars$speed, y = datasets::cars$dist)
model <- GLM.new(distr = "normal", linkinv = identity)
model$fit(data, params_init = list(beta = 3, sd = 2), inplace = TRUE)
print(model$get_params())
#> $beta
#> [1] 2.908838
#> 
#> $sd
#> [1] 16.09429
gt <- GOFTest$new(data = data, model_fitted = model, test_stat = CondKolmY$new(), nboot = 100)
print(gt$get_pvalue())
#> [1] 0.01
gt$plot_procs()

Copy Link

Version

Install

install.packages('gofreg')

Monthly Downloads

151

Version

1.0.0

License

MIT + file LICENSE

Issues

Pull Requests

Stars

Forks

Maintainer

Gitte Kremling

Last Published

October 4th, 2024

Functions in gofreg (1.0.0)

MEP

Marked empirical process test statistic for a given GLM
GOFTest

Goodness-of-fit test for parametric regression
CondKolmbXY

Conditional Kolmogorov test statistic for the joint distribution of (beta^T X,Y)
CondKolmY

Conditional Kolmogorov test statistic for the marginal distribution of Y
CondKolmXY

Conditional Kolmogorov test statistic for the joint distribution of (X,Y)
resample_param_cens

Parametric resampling scheme for a parametric regression model under random censorship
resample_param

Parametric resampling scheme for a parametric regression model
loglik_xy

Negative log-likelihood function for a parametric regression model
TestStatistic

Test Statistic for parametric regression models (abstract class)
ParamRegrModel

Parametric regression model (abstract class)
loglik_xzd

Negative log-likelihood function for a parametric regression model under random censorship
WeibullGLM

Generalized linear model with Weibull distribution
NegBinomGLM

Generalized linear model with negative binomial distribution
NormalGLM

Generalized linear model with normal distribution
SICM

Simulated integrated conditional moment test statistic
resample_param_rsmplx

Parametric resampling scheme for a parametric regression model with resampling of covariates
ExpGLM

Generalized linear model with exponential distribution
GammaGLM

Generalized linear model with gamma distribution
GLM

Generalized linear model (abstract class)
GLM.new

Create GLM object with specific distribution family
CondKolmY_RCM

Conditional Kolmogorov test statistic for the marginal distribution of Y under random censorship