我有一个数据框,并对其应用了 changepoint.np 包。现在,我想计算中间值或在这些变化点位置之间显示一条趋势线(红线)。
任何想法如何做到这一点?
我的数据框df1
date amount
2012-07-01 20.0000000
2012-08-01 11.1111111
2012-09-01 0.0000000
2012-10-01 0.0000000
2012-11-01 4.7619048
2012-12-01 4.7619048
2013-01-01 7.8947368
2013-02-01 0.0000000
2013-03-01 0.0000000
2013-04-01 1.8181818
2013-05-01 0.0000000
2013-06-01 0.0000000
2013-07-01 0.0000000
2013-08-01 0.0000000
2013-09-01 1.7543860
2013-10-01 0.6410256
2013-11-01 3.0534351
2013-12-01 2.6143791
2014-01-01 7.6023392
2014-02-01 2.7777778
2014-03-01 5.2884615
2014-04-01 2.7237354
2014-05-01 2.3255814
2014-06-01 2.6627219
2014-07-01 2.0710059
2014-08-01 2.7522936
2014-09-01 4.6413502
2014-10-01 4.4077135
2014-11-01 3.4759358
2014-12-01 4.3333333
2015-01-01 8.0128205
2015-02-01 9.3632959
2015-03-01 4.3771044
2015-04-01 4.0650407
2015-05-01 3.7500000
2015-06-01 4.6189376
2015-07-01 3.6764706
2015-08-01 2.4561404
2015-09-01 2.9090909
2015-10-01 2.1084337
我的变更点代码:
library(changepoint.np)
out <- cpt.np(df1$amount, method = 'PELT')
plot(out)