get_transformation: Return function of transformed response variables

View source: R/get_transformation.R

get_transformationR Documentation

Return function of transformed response variables

Description

This functions checks whether any transformation, such as log- or exp-transforming, was applied to the response variable (dependent variable) in a regression formula, and returns the related function that was used for transformation.

Usage

get_transformation(x, verbose = TRUE)

Arguments

x

A regression model.

verbose

Logical, if TRUE, prints a warning if the transformation could not be determined.

Value

A list of two functions: ⁠$transformation⁠, the function that was used to transform the response variable; ⁠$inverse⁠, the inverse-function of ⁠$transformation⁠ (can be used for "back-transformation"). If no transformation was applied, both list-elements ⁠$transformation⁠ and ⁠$inverse⁠ just return function(x) x. If transformation is unknown, NULL is returned.

Examples

# identity, no transformation
model <- lm(Sepal.Length ~ Species, data = iris)
get_transformation(model)

# log-transformation
model <- lm(log(Sepal.Length) ~ Species, data = iris)
get_transformation(model)

# log-function
get_transformation(model)$transformation(0.3)
log(0.3)

# inverse function is exp()
get_transformation(model)$inverse(0.3)
exp(0.3)

easystats/insight documentation built on Oct. 2, 2024, 8:19 a.m.