R 应用Box-Cox转换,在TSIBLE数据帧中对列进行变异

R 应用Box-Cox转换,在TSIBLE数据帧中对列进行变异,r,time-series,forecast,tsibble,fable,R,Time Series,Forecast,Tsibble,Fable,我是Hyndman软件包的忠实粉丝,但却被Box-Cox转换绊倒了 我有一个数据帧 class(chicago_sales) [1] "tbl_ts" "tbl_df" "tbl" "data.frame" 我正在尝试修改一个额外的列,其中Mean\u price变量将被转换 foo <- chicago_sales %>% mutate(bc = BoxCox(x =

我是Hyndman软件包的忠实粉丝,但却被Box-Cox转换绊倒了

我有一个数据帧

class(chicago_sales)
[1] "tbl_ts"     "tbl_df"     "tbl"        "data.frame"
我正在尝试修改一个额外的列,其中
Mean\u price
变量将被转换

foo <- chicago_sales %>% 
mutate(bc = BoxCox(x = chicago_sales$Median_price, lambda = 
BoxCox.lambda(chicago_sales$Median_price)))
foo%
变异(bc=BoxCox(x=chicago_销售额$Medium_价格,λ=
BoxCox.lambda(芝加哥销售价格中位数)
给我一些结果(可能也错了),无法应用
autoplot

我还尝试应用来自的代码,但失败了

我做错了什么?谢谢

更新:


问题,在TSibles内部,当使用dplyr时,您不会调用
芝加哥销售$Median\u price
,而只调用
Median\u price
。在使用TSibles时,我建议您使用fable和fabletools,但如果您使用的是forecast,它应该是这样工作的:

library(tsibble)
library(dplyr)
library(forecast)

pedestrian %>% 
  mutate(bc = BoxCox(Count, BoxCox.lambda(Count)))
# A tsibble: 66,037 x 6 [1h] <Australia/Melbourne>
# Key:       Sensor [4]
   Sensor         Date_Time           Date        Time Count    bc
   <chr>          <dttm>              <date>     <int> <int> <dbl>
 1 Birrarung Marr 2015-01-01 00:00:00 2015-01-01     0  1630 11.3 
 2 Birrarung Marr 2015-01-01 01:00:00 2015-01-01     1   826  9.87
 3 Birrarung Marr 2015-01-01 02:00:00 2015-01-01     2   567  9.10
 4 Birrarung Marr 2015-01-01 03:00:00 2015-01-01     3   264  7.65
 5 Birrarung Marr 2015-01-01 04:00:00 2015-01-01     4   139  6.52
 6 Birrarung Marr 2015-01-01 05:00:00 2015-01-01     5    77  5.54
 7 Birrarung Marr 2015-01-01 06:00:00 2015-01-01     6    44  4.67
 8 Birrarung Marr 2015-01-01 07:00:00 2015-01-01     7    56  5.04
 9 Birrarung Marr 2015-01-01 08:00:00 2015-01-01     8   113  6.17
10 Birrarung Marr 2015-01-01 09:00:00 2015-01-01     9   166  6.82
# ... with 66,027 more rows
库(tsible)
图书馆(dplyr)
图书馆(预测)
行人%>%
突变(bc=BoxCox(计数,BoxCox.lambda(计数)))
#一个TSIBLE:66037 x 6[1h]
#键:传感器[4]
传感器日期\时间日期时间计数bc
1比拉朗马尔2015-01-01 00:00:00 2015-01-01 0 1630 11.3
2比拉朗马尔2015-01-01 01:00:00 2015-01-01 1826 9.87
3比拉朗马尔2015-01-01 02:00:00 2015-01-01 2567 9.10
4比拉朗马尔2015-01-01 03:00:00 2015-01-01 326 7.65
5比拉朗马尔2015-01-01 04:00:00 2015-01-01 4139 6.52
6比拉朗马尔2015-01-01 05:00:00 2015-01-01 5 77 5.54
7比拉朗马尔2015-01-01 06:00:00 2015-01-01 6 44 4.67
8比拉朗马尔2015-01-01 07:00:00 2015-01-01 7 56 5.04
9比拉朗马尔2015-01-01 08:00:00 2015-01-01 8 113 6.17
10比拉朗马尔2015-01-01 09:00:00 2015-01-01 9 166 6.82
# ... 还有66027行

我使用了
tsibble
软件包中的内置数据集,因为您没有提供
chicago\u sales

的dput。谢谢,我确实这样做了,但是这些数字真的让我非常害怕。请看我的打印屏幕。“我觉得它太高了。”阿纳金斯基沃克,检查一下兰巴。看起来好像太高了。检查
BoxCox.lambda(芝加哥销售$Median\u价格)
查看lambda使用的是什么。对于我使用的示例,lambda返回0.108。但从结果来看,它更接近2,这将在bc转换中产生更高的值。如果您选中,您可以看到bc如何与forecast一起使用。my lambda为1.484661。我检查了所有可能的资源,不确定出了什么问题。我的数据有很强的季节性趋势