我正在探索该recipes
软件包以准备我的数据以进行线性回归。但即使是使用反双曲正弦对两个变量进行简单变换也不会产生我所期望的结果。我在这里做错了什么?
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
由reprex 包创建于 2022-03-01 (v2.0.1)