
Return function of transformed response variables
Source:R/get_transformation.R
get_transformation.Rd
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.
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)
#> $transformation
#> function (x)
#> x
#> <bytecode: 0x55a39f6368a0>
#> <environment: 0x55a39f639c50>
#>
#> $inverse
#> function (x)
#> x
#> <bytecode: 0x55a39f6368a0>
#> <environment: 0x55a39f639c50>
#>
# log-transformation
model <- lm(log(Sepal.Length) ~ Species, data = iris)
get_transformation(model)
#> $transformation
#> function (x, base = exp(1)) .Primitive("log")
#>
#> $inverse
#> function (x) .Primitive("exp")
#>
# log-function
get_transformation(model)$transformation(.3)
#> [1] -1.203973
log(.3)
#> [1] -1.203973
# inverse function is exp()
get_transformation(model)$inverse(.3)
#> [1] 1.349859
exp(.3)
#> [1] 1.349859