| predict.f_boxcox | R Documentation |
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.
## S3 method for class 'f_boxcox'
predict(object, newdata, inverse = FALSE, ...)
object |
An object of class |
newdata |
A numeric vector of values to transform. For the forward
transform ( |
inverse |
Logical. If |
... |
Further arguments passed to or from other methods (currently unused). |
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.
A numeric vector of the same length as newdata, containing
either the forward-transformed or back-transformed values.
f_boxcox
# 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)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.