英文:
Having the error "Error in copy_msts(y, fitted) : x and y should have the same number of observations"
问题
"Hi I have current the error:
"Error in copy_msts(y, fitted) :
x and y should have the same number of observations"
after running this line of code tsla_train_forecast= rwf(tsla_train, h=6)
Here is my code:
library(forecast)
library(quantmod)
getSymbols("TSLA",from="2022-09-01", to="2023-06-16")
chartSeries(TSLA, multi.col = TRUE, theme = "white")
summary(TSLA)
Tesla=TSLA$TSLA.Close
plot(Tesla)
Teslamf=meanf(Tesla,h=6)
plot(Teslamf)
Teslamf
Teslamf$fitted
Teslamf$residuals
acf(Teslamf$residuals)
checkresiduals(Teslamf)
tsla_train=TSLA[1:189]
tsla_test=TSLA[190:196]
tsla_test$TSLA.Close
tsla_train_forecast= rwf(tsla_train, h=6)
tsla_train_forecast
tsla_test-tsla_train_forecast$mean
I'm not sure what I am doing wrong, it worked fine when I was using AAPL stock data."
英文:
Hi I have current the error:
"Error in copy_msts(y, fitted) :
x and y should have the same number of observations"
after running this line of code tsla_train_forecast= rwf(tsla_train, h=6)
Here is my code:
library(forecast)
library(quantmod)
getSymbols("TSLA",from="2022-09-01", to="2023-06-16")
chartSeries(TSLA, multi.col = TRUE, theme = "white")
summary(TSLA)
Tesla=TSLA$TSLA.Close
plot(Tesla)
Teslamf=meanf(Tesla,h=6)
plot(Teslamf)
Teslamf
Teslamf$fitted
Teslamf$residuals
acf(Teslamf$residuals)
checkresiduals(Teslamf)
tsla_train=TSLA[1:189]
tsla_test=TSLA[190:196]
tsla_test$TSLA.Close
tsla_train_forecast= rwf(tsla_train, h=6)
tsla_train_forecast
tsla_test-tsla_train_forecast$mean
I'm not sure what I am doing wrong, it worked fine when I was using AAPL stock data.
答案1
得分: 1
问题在于rwf()
是为单变量时间序列设计的,而您正在将其用于多变量时间序列。不幸的是,错误消息并不有用。如果您使用rwf(tsla_train[,1], h=6)
,则可以无错误地生成预测。
第二个问题是您正在使用xts对象,但forecast包是设计用于处理ts对象的。大多数情况下,它会在运行时将xts转换为ts,但偶尔可能会导致错误。
英文:
The problem is that rwf()
is designed for univariate time series, and you are using it with a multivariate time series. Unfortunately, the error message isn't helpful. If you use rwf(tsla_train[,1], h=6)
, the forecasts are produced without error.
A second issue is that you are using xts objects, but the forecast package is designed to handle ts
objects. Mostly, it will convert xts
to ts
on the fly, but occasionally this could cause an error.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论