用动物园功能分解(R中的时间序列)

时间:2018-05-20 03:48:32

标签: r

我正在研究谷歌股票价格数据(从2007年1月1日到2017年3月31日)。

我想将它分解为趋势,季节性和随机。

这是我的代码:

library(zoo)
library(fpp)    
setwd("C:\\Users\\Son\\Desktop\\Time series\\Data")
google <- read.table("GOOGL.csv",header=T, sep=',') 

log price
googlets <- zoo(google$Adj.Close, as.Date(as.character(google$Date),format = c("%Y-%m-%d")), frequency = 4)

log price time series
google_logprice <- log(googlets)
google_logprice_num <- coredata(google_logprice)

decompose_google = decompose(google_logprice_num, "additive")

plot(as.ts(decompose_google$seasonal))
plot(as.ts(decompose_google$trend))
plot(as.ts(decompose_google$random))
plot(decompose_google)        

但是当我运行代码时,它会遇到一些错误:

> decompose_google = decompose(google_logprice_num, "additive")
Error in decompose(google_logprice_num, "additive") : 
time series has no or less than 2 periods
> 
> plot(as.ts(decompose_google$seasonal))
Error in plot.window(xlim, ylim, log, ...) : need finite 'ylim' values
In addition: Warning messages:
1: In min(x) : no non-missing arguments to min; returning Inf
2: In max(x) : no non-missing arguments to max; returning -Inf
> plot(as.ts(decompose_google$trend))
Error in plot.window(xlim, ylim, log, ...) : need finite 'ylim' values
In addition: Warning messages:
1: In min(x) : no non-missing arguments to min; returning Inf
2: In max(x) : no non-missing arguments to max; returning -Inf
> plot(as.ts(decompose_google$random))
Error in plot.window(xlim, ylim, log, ...) : need finite 'ylim' values
In addition: Warning messages:
1: In min(x) : no non-missing arguments to min; returning Inf
2: In max(x) : no non-missing arguments to max; returning -Inf
> plot(decompose_google)
Error in plot.window(...) : need finite 'ylim' values
In addition: Warning messages:
1: In cbind(observed = xx, trend = x$trend, seasonal = x$seasonal,  :
number of rows of result is not a multiple of vector length (arg 1)
2: In min(x) : no non-missing arguments to min; returning Inf
3: In max(x) : no non-missing arguments to max; returning -Inf

你能帮我解决一下吗?(?

0 个答案:

没有答案