Having the error "Error in copy_msts(y, fitted) : x and y should have the same number of observations"

huangapple go评论98阅读模式
英文:

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.

huangapple
  • 本文由 发表于 2023年6月18日 23:52:50
  • 转载请务必保留本文链接:https://go.coder-hub.com/76501363.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定