微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

错误: period.indices$post.period[1] 不大于 period.indices$pre.period[2]

如何解决错误: period.indices$post.period[1] 不大于 period.indices$pre.period[2]

我把代码在这里。我相信一些精通 R 的人可以帮助我解决这个问题。

#Causal Impact
#define pre and post period dates
start = "2018-01-01"
treatment = "2020-10-01"
end = "2021-06-10"

#retrieve data
#install.packages("tseries")
library(tseries)

Bitcoin <- get.hist.quote (instrument = "BTC-USD",start = start,end = end,quote = "Close",compression = "d")


Ethereum <- get.hist.quote (instrument = "ETH-USD",compression = "d")


Cordana <- get.hist.quote (instrument = "ADA-USD",compression = "d")




Litecoin <- get.hist.quote (instrument = "LTC-USD",compression = "d")



Tether <- get.hist.quote (instrument = "USDT-USD",compression = "d")



Tran <- get.hist.quote (instrument = "TRX-USD",compression = "d")



EOS <- get.hist.quote (instrument = "EOS-USD",compression = "d")


Dogecoin <- get.hist.quote (instrument = "DOGE-USD",compression = "d")




#plotting the data
#install.packages("ggplot2")

library(ggplot2)

autoplot(Bitcoin) + xlab("time") + ylab("Bitcoin Price (BTC-USD)") + ggtitle("Bitcoin Price between 2020-01-01 and 2021-06-19") + 
  theme_bw() +
  scale_x_date(date_breaks = "2 months") + 
  theme(axis.title.x = element_text(size = 14,face = "bold",vjust = -1),axis.title.y = element_text(size = 20,face = "bold")) + 
  theme(plot.title = element_text(size = 8,face = "bold")) + 
  theme(axis.text = element_text(size = 8,face = "bold")) + 
  theme(axis.text.x = element_text(angle = 90,vjust = 0.5))

autoplot(Ethereum) + xlab("time") + ylab("Ethereum Price (ETH-USD)") + ggtitle("Ethereum Price between 2020-01-01 and 2021-06-19") + 
  theme_bw() +
  scale_x_date(date_breaks = "2 months") + 
  theme(axis.title.x = element_text(size = 14,vjust = 0.5))

autoplot(Cordana) + xlab("time") + ylab("Cordana Price (ADA-USD)") + ggtitle("Cordana Price between 2020-01-01 and 2021-06-19") + 
  theme_bw() +
  scale_x_date(date_breaks = "2 months") + 
  theme(axis.title.x = element_text(size = 14,vjust = 0.5))

autoplot(Litecoin) + xlab("time") + ylab("Litecoin Price (LTC-USD)") + ggtitle("Litecoin Price between 2020-01-01 and 2021-06-19") + 
  theme_bw() +
  scale_x_date(date_breaks = "2 months") + 
  theme(axis.title.x = element_text(size = 14,vjust = 0.5))

autoplot(Tether) + xlab("time") + ylab("Tether Price (USDT-USD)") + ggtitle("Tether Price between 2020-01-01 and 2021-06-19") + 
  theme_bw() +
  scale_x_date(date_breaks = "2 months") + 
  theme(axis.title.x = element_text(size = 14,vjust = 0.5))

autoplot(Tran) + xlab("time") + ylab("Tran Price (TRX-USD)") + ggtitle("Tran Price between 2020-01-01 and 2021-06-19") + 
  theme_bw() +
  scale_x_date(date_breaks = "2 months") + 
  theme(axis.title.x = element_text(size = 14,vjust = 0.5))


autoplot(EOS) + xlab("time") + ylab("EOS Price (EOS-USD)") + ggtitle("EOS Price between 2020-01-01 and 2021-06-19") + 
  theme_bw() +
  scale_x_date(date_breaks = "2 months") + 
  theme(axis.title.x = element_text(size = 14,vjust = 0.5))



series <- cbind(Dogecoin,Bitcoin,Ethereum,Cordana,Litecoin)
series <- na.omit(series)

m <- data.frame(series)

autoplot(series,facets = NULL) + xlab("time") + ylab("Price") + ggtitle("Cryptocurrencies Price between 2020-01-01 and 2021-06-19") + 
  theme_bw() +
  scale_x_date(date_breaks = "2 months") + 
  theme(axis.title.x = element_text(size = 14,vjust = 0.5))

#correlation check
dataset_cor <- window(series,start=start,end=end)
dataset_cor <- as.data.frame(dataset_cor)
cor(dataset_cor)


#create pre and post objects
pre.period <- as.Date(c(start,treatment))
post.period <- as.Date(c(treatment,end))

#running causal impact
#install.packages("CausalImpact")
library(CausalImpact)
impact <- CausalImpact(data = series,pre.period = pre.period,post.period = post.period)

我做贝叶斯因果影响。当我运行代码时,一切运行顺利,但最后出现以下错误Error: period.indices$post.period[1] 不大于 period.indices$pre.period[2]

我不明白为什么我会遇到这个问题。 你能帮我吗?

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。