将双逻辑函数拟合到时间序列

问题描述 投票:0回答:2

对于以下时间序列数据:

#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 这里有一个例子 - 使用 dplyr 运行函数时出现索引重叠错误

但是,给出的示例仅考虑年度时间序列。 我尝试将函数拟合为:

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)

但是,这个函数似乎并不适合整个时间序列。如何运行该函数以适应整个时间序列?另外,我注意到不同运行时的输出是不同的,我不确定是什么导致了这种情况发生。

r time-series non-linear-regression
2个回答
1
投票

FitDoubleLogBeck
只能处理1年的数据,所以需要逐年分析数据。为此,只需
window
一年,然后分别拟合每年的数据。

对于不同运行的不同结果,算法随机选择初始参数。双Logistic曲线的图形是钟形的。然而,您将该算法应用于类似“正弦”的数据,但该算法期望有“钟声”。然后它将

water
数据视为点云,因此结果毫无意义,并且对初始参数设置非常有意义。

代码:

set.seed(123)
par(mfrow = c(1, 3))
# water vector taken from question above
x <- ts(water, start = c(2016,17), end = c(2020, 16), frequency = 24)

res <- sapply((2017:2019), function(year) { 
  x2 <- as.vector(window(x, start=c(year, 1), end=c(year, 24)))
  smooth.water2 = FitDoubleLogBeck(x2, weighting = T, hessian = F, plot = T, ninit = 10)
  title(main = year)
  c(year = year, smooth.water2$params)
})

t(res)

输出:

     year         mn          mx       sos        rsp       eos        rau
[1,] 2017 -0.7709318  0.17234293 16.324163 -0.6133117  6.750885 -0.7618376
[2,] 2018 -0.8900971  0.09398673  7.529345  0.6701200 17.319465  0.8277409
[3,] 2019 -4.7669470 -0.34648434 15.930455 -0.2570877 10.690043 -0.2267284

0
投票

@Artem,您的示例输出中的参数不是很不现实吗?第三年的最小含水量值 (mn) 为 -4.76,最大含水量值 (mx) 显然不是最大值(当您查看图表时)。我目前也在使用 FitDoubleLogBeck 函数,也遇到了 mx 和 mn 值不切实际的问题。

© www.soinside.com 2019 - 2024. All rights reserved.