有间隙的日期 - 使用双小波包在 R 中进行小波分析 [英] Date with Gaps - Wavelet Analysis in R Using Biwavelet Package

查看:40
本文介绍了有间隙的日期 - 使用双小波包在 R 中进行小波分析的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 R 中的 biwavelet 包执行小波分析.日期变量没有连续的日期,但有间隙.当我尝试创建图表时,出现以下错误.

I am performing Wavelet Analysis using biwavelet package in R. The date variable does not have continuous dates but with gaps. When I try to create the graph, I get the following error.

check.datum(d) 中的错误:步长必须是恒定的(请参阅内插的近似函数)

下面给出了一个 MWE:

An MWE is given below:

   library(foreign)
   library(biwavelet)
   library(xts)
   library(labelled)
   library(zoo)

   date =c("2020-02-13", "2020-02-14", "2020-02-17", "2020-02-18", "2020-02-19", "2020-02-20", "2020-02-21", "2020-02-24", "2020-02-25", "2020-02-26", "2020-02-27", "2020-02-28", "2020-03-02", "2020-03-03", "2020-03-04", "2020-03-05", "2020-03-06", "2020-03-09", "2020-03-10", "2020-03-11", "2020-03-12", "2020-03-13")
   rdate = as.Date(date)
   date <- as.Date(date, format = "%Y-%m-%d")
   date
   class(date)
   var = c(-0.077423148, -0.083293147, -0.089214072, -0.095185943, -0.101208754, -0.107282504, -0.113407195, -0.119582824, -0.125809386, -0.125806898, -0.132149309, -0.138584509,  -0.145112529, -0.151733354, -0.158446968, -0.165253401, -0.172152638, -0.179144681, -0.186229542, -0.193407193, -0.200677648, -0.208040923)
   data = data.frame(date, var)
   View(data)
   X <- as.xts(data[,-1], order.by = date)
   ABC <- data.frame(date, var)
   wt.t1=plot(wt(ABC), form = "%b-%d")

我该如何解决这个问题?

How can I resolve this issue?

推荐答案

您可以按照错误消息中的说明插入缺失的天数:

You can interpolate missing days by following the instructions in the error message:

alldates <- seq(min(date), max(date), by = 1)
interpdata <- approx(date, var, xout = alldates)
ABC <- data.frame(date = alldates, var = interpdata$y)
wt.t1 <- plot(wt(ABC, form = "%b-%d")

但是,我认为您错过某些日子的原因是它们是星期六或星期日;我只在数据集中看到工作日.

However, I think the reason you are missing some days is that they are Saturday or Sunday; I only see weekdays in the dataset.

对于许多数据集(例如股票市场交易等),插入周六的价格是多少?"是没有意义的,因为交易从未发生在周六或周日.在这种情况下,我建议将日期"替换为日期".具有简单增量的变量,例如

For many datasets (e.g. stock market trading, etc.) it doesn't make sense to interpolate "what would the price have been on Saturday?", because trades never occur on Saturday or Sunday. In that case, I'd suggest replacing the "date" variable with a simple increment, e.g.

date <- 1:length(date)
ABC <- data.frame(date, var)
wt.t1=plot(wt(ABC), form = "%b-%d")

这篇关于有间隙的日期 - 使用双小波包在 R 中进行小波分析的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆