Package 'regcore'

Title: S3 Generic Functions for Regression Models
Description: Defines S3 generic functions for model comparison, coefficient summaries, goodness-of-fit tables, equation extraction, random-effects summaries, diagnostic plots, variable selection, and methods reporting. Model-specific implementations are supplied by packages that extend these interfaces, allowing a consistent workflow across regression models.
Authors: Ricardo Rasmussen Petterle [aut, cre, cph] (ORCID: <https://orcid.org/0000-0001-7735-1077>)
Maintainer: Ricardo Rasmussen Petterle <[email protected]>
License: GPL (>= 3)
Version: 0.1.0
Built: 2026-12-05 19:57:54 UTC
Source: https://github.com/cran/regcore

Help Index


Extract Envelope Data into a Tidy Data Frame

Description

Extracts the coordinates of simulated envelopes from one or more fitted models, returning a tidy data frame in long format.

Usage

df_envelopes(object, ...)

Arguments

object

A fitted model object.

...

Additional fitted model objects, and arguments passed to specific methods (e.g., number of simulations).

Details

Unlike graphical methods such as plot_envelope(), df_envelopes() delegates the extraction of envelope data to class-specific methods. Such methods may return envelope bounds and observed residuals suitable for graphics in other packages.

Value

A data.frame containing columns for theoretical quantiles, observed residuals, envelope bounds, and a factor column indicating the source model.

See Also

The generic is implemented here; class-specific behavior is defined in downstream packages that provide S3 methods.


Extract Mathematical Equations from Fitted Models

Description

Extracts the mathematical formulation of a fitted model. Downstream methods typically support generating both theoretical (symbolic with Greek letters) and fitted (numeric with estimated coefficients) equations formatted in LaTeX.

Usage

extract_equations(object, ...)

Arguments

object

A fitted model object.

...

Additional arguments passed to specific methods (e.g., specifying "symbolic" or "numeric" modes, or selecting specific submodels).

Details

This is an S3 generic. It is designed to bridge the gap between statistical modeling and academic reporting. Methods usually identify random effects, multiple linear predictors, and assign proper indices for longitudinal data.

Value

Generally expected to return a character string containing the LaTeX code for the equations, and to print the output directly to the console.

See Also

The generic is implemented here; class-specific behavior is defined in downstream packages that provide S3 methods.


Goodness-of-Fit Table for Regression Models

Description

Computes, compiles, and compares standard goodness-of-fit metrics (such as log-likelihood, AIC, and BIC) for one or multiple fitted models.

Usage

gof_tab(object, ...)

Arguments

object

A fitted model object.

...

Additional fitted model objects for side-by-side comparison.

Details

This S3 generic acts as a unified interface to evaluate model performance. When multiple models are provided via ..., downstream methods typically align the metrics into a clear comparative table.

Value

Generally returns a structured object (e.g., a list or data frame) containing the computed metrics for each evaluated model, along with custom print methods.

See Also

The generic is implemented here; class-specific behavior is defined in downstream packages that provide S3 methods.

Examples

fit <- structure(list(aic = 12.5), class = "demo_regression")
gof_tab.demo_regression <- function(object, ...) data.frame(AIC = object$aic)
gof_tab(fit)

Pairwise Vuong Test for Multiple Models

Description

Conducts pairwise Vuong likelihood ratio tests across multiple non-nested competing models.

Usage

pairwise_vuong_test(...)

Arguments

...

Fitted model objects to be compared.

Details

Downstream methods can compare more than two models simultaneously, returning a matrix of comparisons (and, when supported, adjusted p-values) to assess relative model fit.

Value

The return value depends on the class-specific method, often a structured collection of pairwise statistics and p-values.

See Also

The generic is implemented here; class-specific behavior is defined in downstream packages that provide S3 methods.


Diagnostic Plots with Simulated Envelopes

Description

Generates a (half-)normal probability plot with a simulated envelope for model residuals. It is a visual diagnostic tool to assess goodness-of-fit and distributional assumptions.

Usage

plot_envelope(object, ...)

Arguments

object

A fitted model object.

...

Additional arguments passed to specific methods (e.g., number of simulations, confidence level, parallel computing cores).

Details

Class-specific methods evaluate whether observed residuals behave as expected under the fitted model by comparing them with simulated confidence bands. Methods may support different residual types (e.g., randomized quantile, Cox-Snell).

Value

Invisibly returns a list or data frame containing the envelope coordinates, while producing a plot as a side effect.

See Also

The generic is implemented here; class-specific behavior is defined in downstream packages that provide S3 methods.


Plot Random Effects (Caterpillar Plot)

Description

Produces a caterpillar plot of the predicted conditional modes of the random effects from a fitted mixed-effects model, optionally with uncertainty intervals.

Usage

plot_ranef(object, ...)

Arguments

object

A fitted model object containing random effects.

...

Additional graphical arguments passed to specific plotting methods.

Details

Visualizes unobserved heterogeneity at the group level. The generic delegates the extraction and sorting of the estimates to class-specific methods.

Value

Invisibly returns a data frame containing the sorted estimated random effects and their confidence bounds, while generating a plot.

See Also

The generic is implemented here; class-specific behavior is defined in downstream packages that provide S3 methods.


Extract Predicted Random Effects

Description

Extracts predicted random effects (typically conditional modes) from a fitted mixed-effects model.

Usage

random_effects(object, ...)

Arguments

object

A fitted model object.

...

Additional arguments passed to specific methods.

Details

This S3 generic provides a unified way to retrieve conditional modes. Methods typically organize the output by grouping factors, handling multiple random terms.

Value

Typically returns a list (one element per grouping variable) containing data frames of the estimated random effects.

See Also

The generic is implemented here; class-specific behavior is defined in downstream packages that provide S3 methods.


Stepwise Variable Selection (Backward Elimination)

Description

Performs backward variable selection to identify the most parsimonious model, removing predictors iteratively based on Wald test p-values or Information Criteria (AIC, BIC).

Usage

stepCriterion(object, ...)

Arguments

object

A fitted model object representing the starting full model.

...

Additional arguments passed to specific methods (e.g., criterion choice, p-value thresholds).

Details

Methods for this generic generally focus on optimizing the main location (mean/quantile) submodel, keeping random effects and auxiliary parameters (like precision or zero-inflation) intact during the elimination process.

Value

Typically returns a fitted model object representing the final selected model after the backward elimination completes.

See Also

The generic is implemented here; class-specific behavior is defined in downstream packages that provide S3 methods.


Extract and Format Summary Coefficients

Description

Extracts, formats, and compiles fixed-effects coefficients and their standard errors from one or multiple fitted models, facilitating side-by-side comparisons.

Usage

summary_coef(object, ...)

Arguments

object

A fitted model object.

...

Additional fitted model objects for comparison, and other arguments passed to specific methods (e.g., selecting submodels, LaTeX table prep).

Details

This S3 generic streamlines the creation of clean, publication-ready tables. Downstream methods usually handle multiple predictors, align identical variables across models, and can format the output as a LaTeX tabular environment.

Value

Typically returns a structured object containing the compiled coefficients and standard errors, accompanied by a custom print method.

See Also

The generic is implemented here; class-specific behavior is defined in downstream packages that provide S3 methods.

Examples

fit <- structure(list(beta = c(intercept = 0.3, slope = -0.2)), class = "demo_coef")
summary_coef.demo_coef <- function(object, ...) object$beta
summary_coef(fit)

Vuong Test for Non-Nested Models

Description

Performs the Vuong likelihood ratio test to compare two non-nested competing regression models to determine which is closer to the true data-generating process.

Usage

vuong_test(object1, object2, ...)

Arguments

object1

A fitted model object.

object2

Another fitted model object to be compared with object1.

...

Additional arguments passed to specific methods (e.g., alternative hypothesis).

Details

The Vuong test utilizes conditional pointwise log-likelihoods. This S3 generic dispatches the extraction and statistical testing to specific model implementations.

Value

Generally returns an object of class htest containing the test statistic, p-value, and the conclusion regarding model preference.

See Also

The generic is implemented here; class-specific behavior is defined in downstream packages that provide S3 methods.


Automatically Generate Methods Section Text

Description

Translates the structure of a fitted model into boilerplate draft text for the "Methods" section of academic papers or reports.

Usage

write_methods(object, ...)

Arguments

object

A fitted model object.

...

Additional arguments passed to specific methods (e.g., language selection like English or Portuguese).

Details

This generic automates academic reporting by dynamically detecting the distribution family, link functions, inflation structures, and random effects, outputting standardized descriptive text and the software citation.

Value

Invisibly returns a list containing the generated text and the BibTeX citation, while printing them to the console.

See Also

The generic is implemented here; class-specific behavior is defined in downstream packages that provide S3 methods.