| 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 |
Extracts the coordinates of simulated envelopes from one or more fitted models, returning a tidy data frame in long format.
df_envelopes(object, ...)df_envelopes(object, ...)
object |
A fitted model object. |
... |
Additional fitted model objects, and arguments passed to specific methods (e.g., number of simulations). |
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.
A data.frame containing columns for theoretical quantiles, observed residuals,
envelope bounds, and a factor column indicating the source model.
The generic is implemented here; class-specific behavior is defined in downstream packages that provide S3 methods.
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.
extract_equations(object, ...)extract_equations(object, ...)
object |
A fitted model object. |
... |
Additional arguments passed to specific methods (e.g., specifying "symbolic" or "numeric" modes, or selecting specific submodels). |
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.
Generally expected to return a character string containing the LaTeX code for the equations, and to print the output directly to the console.
The generic is implemented here; class-specific behavior is defined in downstream packages that provide S3 methods.
Computes, compiles, and compares standard goodness-of-fit metrics (such as log-likelihood, AIC, and BIC) for one or multiple fitted models.
gof_tab(object, ...)gof_tab(object, ...)
object |
A fitted model object. |
... |
Additional fitted model objects for side-by-side comparison. |
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.
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.
The generic is implemented here; class-specific behavior is defined in downstream packages that provide S3 methods.
fit <- structure(list(aic = 12.5), class = "demo_regression") gof_tab.demo_regression <- function(object, ...) data.frame(AIC = object$aic) gof_tab(fit)fit <- structure(list(aic = 12.5), class = "demo_regression") gof_tab.demo_regression <- function(object, ...) data.frame(AIC = object$aic) gof_tab(fit)
Conducts pairwise Vuong likelihood ratio tests across multiple non-nested competing models.
pairwise_vuong_test(...)pairwise_vuong_test(...)
... |
Fitted model objects to be compared. |
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.
The return value depends on the class-specific method, often a structured collection of pairwise statistics and p-values.
The generic is implemented here; class-specific behavior is defined in downstream packages that provide S3 methods.
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.
plot_envelope(object, ...)plot_envelope(object, ...)
object |
A fitted model object. |
... |
Additional arguments passed to specific methods (e.g., number of simulations, confidence level, parallel computing cores). |
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).
Invisibly returns a list or data frame containing the envelope coordinates, while producing a plot as a side effect.
The generic is implemented here; class-specific behavior is defined in downstream packages that provide S3 methods.
Produces a caterpillar plot of the predicted conditional modes of the random effects from a fitted mixed-effects model, optionally with uncertainty intervals.
plot_ranef(object, ...)plot_ranef(object, ...)
object |
A fitted model object containing random effects. |
... |
Additional graphical arguments passed to specific plotting methods. |
Visualizes unobserved heterogeneity at the group level. The generic delegates the extraction and sorting of the estimates to class-specific methods.
Invisibly returns a data frame containing the sorted estimated random effects and their confidence bounds, while generating a plot.
The generic is implemented here; class-specific behavior is defined in downstream packages that provide S3 methods.
Extracts predicted random effects (typically conditional modes) from a fitted mixed-effects model.
random_effects(object, ...)random_effects(object, ...)
object |
A fitted model object. |
... |
Additional arguments passed to specific methods. |
This S3 generic provides a unified way to retrieve conditional modes. Methods typically organize the output by grouping factors, handling multiple random terms.
Typically returns a list (one element per grouping variable) containing data frames of the estimated random effects.
The generic is implemented here; class-specific behavior is defined in downstream packages that provide S3 methods.
Performs backward variable selection to identify the most parsimonious model, removing predictors iteratively based on Wald test p-values or Information Criteria (AIC, BIC).
stepCriterion(object, ...)stepCriterion(object, ...)
object |
A fitted model object representing the starting full model. |
... |
Additional arguments passed to specific methods (e.g., criterion choice, p-value thresholds). |
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.
Typically returns a fitted model object representing the final selected model after the backward elimination completes.
The generic is implemented here; class-specific behavior is defined in downstream packages that provide S3 methods.
Extracts, formats, and compiles fixed-effects coefficients and their standard errors from one or multiple fitted models, facilitating side-by-side comparisons.
summary_coef(object, ...)summary_coef(object, ...)
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). |
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.
Typically returns a structured object containing the compiled coefficients and standard errors, accompanied by a custom print method.
The generic is implemented here; class-specific behavior is defined in downstream packages that provide S3 methods.
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)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)
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.
vuong_test(object1, object2, ...)vuong_test(object1, object2, ...)
object1 |
A fitted model object. |
object2 |
Another fitted model object to be compared with |
... |
Additional arguments passed to specific methods (e.g., alternative hypothesis). |
The Vuong test utilizes conditional pointwise log-likelihoods. This S3 generic dispatches the extraction and statistical testing to specific model implementations.
Generally returns an object of class htest containing the test statistic,
p-value, and the conclusion regarding model preference.
The generic is implemented here; class-specific behavior is defined in downstream packages that provide S3 methods.
Translates the structure of a fitted model into boilerplate draft text for the "Methods" section of academic papers or reports.
write_methods(object, ...)write_methods(object, ...)
object |
A fitted model object. |
... |
Additional arguments passed to specific methods (e.g., language selection like English or Portuguese). |
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.
Invisibly returns a list containing the generated text and the BibTeX citation, while printing them to the console.
The generic is implemented here; class-specific behavior is defined in downstream packages that provide S3 methods.