1 year ago
#237528
dufei
How to apply inverse hyperbolic sine using the repices package in R?
I am exploring the recipes
package to prepare my data for linear regression. But even a simple transformation of two variables using inverse hyperbolic sine does not yield the results I am expecting. What am I getting wrong here?
library(tidyverse)
library(recipes)
set.seed(1)
df <- tibble(
x = runif(4) * 10,
y = runif(4) * 10
)
# manual transformation
df %>%
mutate(x = asinh(x),
y = asinh(y))
#> # A tibble: 4 × 2
#> x y
#> <dbl> <dbl>
#> 1 1.70 1.45
#> 2 2.02 2.89
#> 3 2.45 2.94
#> 4 2.90 2.59
# transformation using recipes
rec_obj <- recipe(y ~ x, data = df)
rec_obj %>%
step_hyperbolic(x, y, func = "sin", inverse = TRUE) %>%
prep() %>%
bake(new_data = NULL)
#> Warning in func(getElement(new_data, col_names[i])): NaNs produced
#> Warning in func(getElement(new_data, col_names[i])): NaNs produced
#> # A tibble: 4 × 2
#> x y
#> <dbl> <dbl>
#> 1 NaN NaN
#> 2 NaN NaN
#> 3 NaN NaN
#> 4 NaN NaN
Created on 2022-03-01 by the reprex package (v2.0.1)
r
r-recipes
0 Answers
Your Answer