对于以下时间序列数据:
1. 15天频率的日期:
dates = seq(as.Date("2016-09-01"), as.Date("2020-07-30"), by=15) #96 times observation
2.对应于给定时间的作物中的含水量。
water <- c(0.5702722, 0.5631781, 0.5560839, 0.5555985, 0.5519783, 0.5463459,
0.5511598, 0.546652, 0.5361545, 0.530012, 0.5360571, 0.5396569,
0.5683526, 0.6031535, 0.6417821, 0.671358, 0.7015542, 0.7177007,
0.7103561, 0.7036985, 0.6958607, 0.6775161, 0.6545367, 0.6380155,
0.6113306, 0.5846186, 0.5561815, 0.5251135, 0.5085149, 0.495352,
0.485819, 0.4730029, 0.4686458, 0.4616468, 0.4613918, 0.4615532,
0.4827496, 0.5149105, 0.5447824, 0.5776764, 0.6090217, 0.6297454,
0.6399422, 0.6428941, 0.6586344, 0.6507473, 0.6290631, 0.6011123,
0.5744375, 0.5313527, 0.5008027, 0.4770338, 0.4564025, 0.4464508,
0.4309046, 0.4351668, 0.4490393, 0.4701232, 0.4911582, 0.5162941,
0.5490387, 0.5737573, 0.6031149, 0.6400073, 0.6770058, 0.7048311,
0.7255012, 0.739107, 0.7338938, 0.7265202, 0.6940718, 0.6757214,
0.6460862, 0.6163091, 0.5743775, 0.5450822, 0.5057753, 0.4715266,
0.4469859, 0.4303232, 0.4187793, 0.4119401, 0.4201316, 0.426369,
0.4419331, 0.4757525, 0.5070846, 0.5248457, 0.5607567, 0.5859825,
0.6107531, 0.6201754, 0.6356589, 0.6336177, 0.6275579, 0.6214981)
我想用双对数函数曲线拟合数据。我找到了一些例子和软件包,可能会有帮助。
https://greenbrown.r-forge.r-project.org/man/FitDoubleLogElmore.html,此处示例为Indexes overlap error when using dplyr to run a function。
然而,给出的例子只考虑了年时间序列,我试图将函数拟合为:
x <- ts(water, start = c(2016,17), end = c(2020, 16), frequency = 24)
smooth.water = FitDoubleLogBeck(x, weighting = T, hessian = F, plot = T, ninit = 10)
plot(water)
plot(smooth.water$predicted)
plot(water- smooth.water$predicted)
然而,这个函数似乎不适合整个时间序列。我如何运行这个函数才能适合整个时间序列呢?另外,我注意到在不同的运行中输出是不同的,我不确定是什么原因导致了这种情况。
1条答案
按热度按时间g6ll5ycj1#
FitDoubleLogBeck
只能处理1年的数据,因此您需要逐年分析数据。要做到这一点,只需取window
为1年,然后分别拟合每一年的数据。对于不同运行的不同结果,该算法随机选择初始参数。双对数曲线的图形是钟形的。然而,当您将该算法应用于"正弦"类数据时,该算法期望具有"钟形"。然后,它将
water
数据视为点云,因此结果是无意义的,并且对初始参数设置非常敏感。代码:
输出: