predict.f_boxcox: Predict method for f_boxcox objects

View source: R/fboxcox.R

predict.f_boxcoxR Documentation

Predict method for f_boxcox objects

Description

Applies the fitted Box-Cox transformation to new data (forward transform), or reverses it back to the original scale (inverse transform). This is useful for transforming hypothesis test parameters (e.g., mu) to the transformed scale, or for back-transforming confidence intervals to the original scale.

Usage

## S3 method for class 'f_boxcox'
predict(object, newdata, inverse = FALSE, ...)

Arguments

object

An object of class f_boxcox, as returned by f_boxcox.

newdata

A numeric vector of values to transform. For the forward transform (inverse = FALSE), all values must be strictly positive (Box-Cox requires y > 0). For the inverse transform (inverse = TRUE), values are assumed to be on the Box-Cox transformed scale.

inverse

Logical. If FALSE (default), applies the forward Box-Cox transformation to newdata using the estimated \lambda from the original fit. If TRUE, reverses the transformation, mapping values from the Box-Cox scale back to the original scale. Default is FALSE.

...

Further arguments passed to or from other methods (currently unused).

Details

The forward transformation applies the standard Box-Cox formula:

y(\lambda) = \begin{cases} \frac{y^\lambda - 1}{\lambda}, & \lambda \neq 0 \\ \log(y), & \lambda = 0 \end{cases}

The inverse transformation reverses this process to recover the original scale:

y = \begin{cases} (y(\lambda) \cdot \lambda + 1)^{1/\lambda}, & \lambda \neq 0 \\ \exp(y(\lambda)), & \lambda = 0 \end{cases}

Note on inverse validity: When \lambda > 0, not all transformed-scale values have a valid inverse. If y(\lambda) \cdot \lambda + 1 \leq 0, the result is undefined and NaN is returned with a warning.

Value

A numeric vector of the same length as newdata, containing either the forward-transformed or back-transformed values.

See Also

f_boxcox

Examples

# Assuming mtcars is available and f_boxcox is loaded
bc <- f_boxcox(mtcars$hp)

# Forward: transform a hypothesis value (mu) to the Box-Cox scale
mu <- 100
mu_transformed <- predict(bc, newdata = mu)

# Inverse: back-transform a confidence interval to the original scale
ci_transformed <- c(5.5, 6.8)
predict(bc, newdata = ci_transformed, inverse = TRUE)

# Round-trip sanity check should return exactly mu (e.g., 100)
predict(bc, newdata = mu_transformed, inverse = TRUE)


rfriend documentation built on July 7, 2026, 1:06 a.m.