Title: Safe Anytime Valid Inference for Linear Models
Version: 0.1.0
Description: Anytime-valid inference for linear models, namely, sequential t-tests, sequential F-tests, and confidence sequences with time-uniform Type-I error and coverage guarantees. This allows hypotheses to be continuously tested without sacrificing false positive guarantees. It is based on the methods documented in Lindon et al. (2022) <doi:10.48550/arXiv.2210.08589>.
License: MIT + file LICENSE
Encoding: UTF-8
RoxygenNote: 7.3.2
Suggests: testthat (≥ 3.0.0)
Config/testthat/edition: 3
NeedsCompilation: no
Packaged: 2025-04-20 01:18:55 UTC; mlindon
Author: Michael Lindon [aut, cre]
Maintainer: Michael Lindon <michael.s.lindon@gmail.com>
Repository: CRAN
Date/Publication: 2025-04-23 10:10:06 UTC

Anytime-valid Conversion Generic Function

Description

This generic function converts a fitted model object into an anytime-valid version. The conversion is performed by the appropriate S3 method based on the class of the input model.

Usage

av(model, g = 1, ...)

Arguments

model

A fitted model object (e.g., an object of class aov or lm).

g

An integer precision parameter for anytime-valid inference. Defaults to 1.

...

Additional arguments passed to the method.

Value

An enhanced version of model with anytime-valid inference capabilities.


Convert an aov Object to Anytime-Valid aov (avaov)

Description

Converts an object of class aov to an anytime-valid version by setting the precision parameter g as an attribute and updating the class.

Usage

## S3 method for class 'aov'
av(model, g = 1, ...)

Arguments

model

An aov object resulting from an ANOVA analysis.

g

An integer precision parameter for anytime-valid inference. Default is 1.

...

Additional arguments passed to or from other methods.

Value

An object of class avaov with anytime-valid p-values.


Convert a Linear Model (lm) Object to Anytime-Valid lm (avlm)

Description

Converts an lm object into an anytime-valid version by storing a precision parameter g as an attribute and updating the object's class. The resulting object supports anytime-valid inference.

Usage

## S3 method for class 'lm'
av(model, g = 1, vcov_estimator = NULL, ...)

Arguments

model

An lm object from a linear model fit.

g

An integer precision parameter for anytime-valid inference. Default is 1.

vcov_estimator

Optional character string specifying the type of robust standard errors to use. Must be one of "HC0", "HC1", "HC2", or "HC3". If NULL (default), no robust variance estimation is applied.

...

Additional arguments passed to or from other methods.

Value

An enhanced lm object of class avlm with anytime-valid inference capabilities.

Examples

# Fit a linear model on the built-in mtcars dataset
fit <- lm(mpg ~ wt + hp, data = mtcars)

# Convert the standard lm object to an anytime-valid avlm object
av_fit <- av(fit, g = 1)

# Print the summary of the anytime-valid model
summary(av_fit)


Confidence Intervals for Anytime-Valid lm (avlm) Objects

Description

Computes confidence intervals for the coefficients of an avlm object by adjusting the standard errors using the precision parameter g and an anytime-valid approach.

Usage

## S3 method for class 'avlm'
confint(object, parm, level = 0.95, ...)

Arguments

object

An avlm object.

parm

A specification of which parameters are to be given confidence intervals; can be a vector of numbers or names.

level

The confidence level required for the intervals. Defaults to 0.95.

...

Additional arguments passed to or from other methods.

Value

A matrix with the lower and upper confidence limits for the specified parameters.

Examples

# Fit a simple linear model using the mtcars dataset
fit <- lm(mpg ~ wt + hp, data = mtcars)

# Convert the standard lm object to an anytime-valid avlm object with precision parameter g = 1
av_fit <- av(fit, g = 1)

# Calculate and print confidence intervals for the coefficients
conf_intervals <- confint(av_fit)
print(conf_intervals)


Computes the value of g such that width of the 1-\alpha confidence interval at sample size n is minimized

Description

Computes the value of g such that width of the 1-\alpha confidence interval at sample size n is minimized

Usage

optimal_g(n, number_of_coefficients, alpha)

Arguments

n

A positive sample size integer.

number_of_coefficients

A positive integer of coefficients in the full model

alpha

A positive numeric scalar in (0,1) for nominal Type I error.

Value

A positive numeric scalar representing the optimal g that minimizes the CI width.

Examples

n <- 10000
alpha <- 0.05
g_star <- optimal_g(n, 5, alpha)
cat("The optimal g is:", g_star, "\n")


Print Method for summary.avaov Objects

Description

This method prints the summary of an avaov object. It captures the output from the default printing method, substitutes the header "Pr(>F)" with "p value", and adds a note indicating that anytime-valid inference is used.

Usage

## S3 method for class 'summary.avaov'
print(
  x,
  digits = max(3L, getOption("digits") - 3L),
  signif.stars = getOption("show.signif.stars"),
  ...
)

Arguments

x

An object of class summary.avaov.

digits

The number of significant digits to use when printing. Defaults to a value based on options.

signif.stars

Logical indicating whether significance stars should be printed.

...

Additional arguments passed to or from other methods.

Value

Invisibly returns the summary object.


Print Method for summary.avlm Objects

Description

Custom print method for summary.avlm objects that mimics the standard summary.lm output, but replaces p-value column headers and includes anytime-valid annotations.

Usage

## S3 method for class 'summary.avlm'
print(
  x,
  digits = max(3L, getOption("digits") - 3L),
  signif.stars = getOption("show.signif.stars"),
  ...
)

Arguments

x

An object of class summary.avlm containing the summary of an anytime-valid lm object.

digits

The number of significant digits to use when printing. Defaults based on system options.

signif.stars

Logical indicating whether significance stars should be printed.

...

Additional arguments passed to or from other methods.

Value

Invisibly returns the summary object.


Summary Method for Anytime-Valid aov Objects

Description

This method produces a summary for objects of class avaov. It first calls the default summary.aov method and then replaces the standard p-values with anytime-valid p-values calculated using the precision parameter g.

Usage

## S3 method for class 'avaov'
summary(object, ...)

Arguments

object

An object of class avaov created by av.aov.

...

Additional arguments passed to or from other methods.

Value

A summary object of class summary.avaov that includes the anytime-valid p-values.

Examples


# Fit an ANOVA model to the iris dataset.
# This model tests whether the sepal length differs by species.
fit_aov <- aov(Sepal.Length ~ Species, data = iris)

# Convert the standard aov object to an anytime-valid aov (avaov) with precision parameter g = 1.
av_fit_aov <- av(fit_aov, g = 1)

# Print the summary of the anytime-valid ANOVA model.
# The summary replaces standard p-values with anytime-valid p-values.
summary(av_fit_aov)


Summary Method for Anytime-Valid lm (avlm) Objects

Description

Computes a summary for an avlm object, a linear model enhanced with anytime-valid inference. In addition to the standard lm summary statistics, the p-values for the coefficient tests are recalculated using an anytime-valid method.

Usage

## S3 method for class 'avlm'
summary(object, ...)

Arguments

object

An avlm object generated by av.lm.

...

Additional arguments passed to or from other methods.

Value

A summary object of class summary.avlm that includes updated p-values for the coefficients.