Skip to content

Implement S3 classes for function outputs in dubicube #97

@wlangera

Description

@wlangera

Background

The dubicube package currently provides functions that operate on processed_cube objects from other packages. All functions return data frames representing bootstrapped results, confidence intervals, or effect classifications.

Currently:

  • There is no standard object structure for these outputs.
  • Users must inspect raw data frames to understand results.
  • Method dispatch (e.g., print, summary, plot) is not available.

Goal: Introduce S3 classes for dubicube outputs to improve clarity, usability, and method dispatch.

Proposed S3 Classes

Function / Output Proposed S3 Class Fields / Structure Methods
cross_validate_cube() cube_cv dataframe with LOO or k-fold results, metadata print, summary, plot
bootstrap_cube() cube_bootstrap, boot_list (when using boot::boot?) bootstrap replicates, statistic, metadata print, summary, plot
calculate_bootstrap_ci() bootstrap_ci statistic, CI bounds, method, metadata print, summary, plot
add_effect_classification() effect_classification original data frame + effect class column print, summary, plot
calculate_acceleration() acceleration_result dataframe with acceleration statistics print, summary, plot

Implementation Plan

  1. Define S3 Constructors

    • Example:

      new_cube_bootstrap <- function(df, statistic, n_boot, ...) {
        structure(list(data = df, statistic = statistic, n_boot = n_boot, ...),
                  class = "cube_bootstrap")
      }
  2. Implement S3 Methods

    • print() → concise summary of main results.
    • summary() → high-level statistics and CI coverage.
    • plot() → visualization of bootstrap distributions, effect classes, acceleration trends, etc.
  3. Update Functions to Return S3 Objects

    • Wrap data frame outputs in the appropriate S3 constructor.
    • Keep raw data frames accessible (e.g., as.data.frame() method) for compatibility.
  4. Add Helper Functions

    • is_cube_bootstrap(), is_bootstrap_ci(), etc., for input validation.
    • Optional coercion methods: as.data.frame.cube_bootstrap()
  5. Testing

    • Unit tests to ensure correct class assignment.
    • Validate method dispatch (print, summary, plot).

Next Steps

  • Create S3 constructors for each result type.
  • Implement print(), summary(), and plot() methods.
  • Update dubicube functions to return S3 objects.
  • Add unit tests for class handling and method dispatch.
  • Update documentation and vignettes.

Metadata

Metadata

Assignees

Labels

OOPObject oriented programming

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions