R舍入错误(频率):VAR模型中数学函数的非数字参数

时间:2017-06-01 16:06:05

标签: r rounding frequency var

帮助解决:

  

fcst.tmp< - forecast(VAR.tmp)   回合错误(频率):数学函数的非数字参数

来自代码:

library(vars)

tmp.matrix <- matrix(data = c(0,                     -0.0018674142,                     0.0046620131,
                     0.0037140247,                     -0.0009272138,                     0.0064725145,
                     -0.000922084,                     -0.0046232167,                     0.0210920245,
                     -0.0100320039,                     0.0136551962,                     -0.00725956,
                     0.0251811866,                     -0.0089206658,                     -0.000896459,
                     0.0035810244,                     0.0159577854,                     -0.0097216851,
                     0.0176060886,                     0.0034843241,                     -0.0017406445,
                     0.0198367867,                     -0.0034217313,                     -0.0225312824,
                     -0.0043917506,                     0.0157208478,                     -0.0148409533,
                     0.0234691345,                     -0.0401374128,                     -0.0132217389,
                     0.0269124178,                     -0.006590583,                     0.0255472708,
                     0.003401652,                     0.0052493174,                     -0.0011235182,
                     -0.0033622663,                     -0.0193530068,                     -0.0302611445,
                     -0.0076587663,                     -0.0023782155,                     -0.026358019,
                     0.0161200327,                     0.0171822796,                     0.0193783756,
                     0.0091528136,                     -0.0101419116,                     -0.0013561094,
                     0.000172569,                     -0.0071663343,                     -0.0119922952,
                     0.0044839696,                     0.0029657989,                     -0.0114150402,
                     -0.0018366463,                     0.0116721141),ncol = 2)

colnames(tmp.matrix) <- c("Col1","Col2")

VAR.tmp <- VAR(tmp.matrix, p=1, type = "const")

fcst.tmp <- forecast(VAR.tmp)

P.S。

tmp.matrix需要转换为时间序列:

ts.matrix <- as.ts(tmp.matrix)

VAR.tmp <- VAR(ts.matrix, p=1, type = "const")

fcst.tmp <- forecast(VAR.tmp)

plot(fcst.tmp)

2 个答案:

答案 0 :(得分:2)

需要通过以下方式将tmp.matrix转换为时间序列:

ts.matrix <- as.ts(tmp.matrix)

VAR.tmp <- VAR(ts.matrix, p=1, type = "const")

fcst.tmp <- forecast(VAR.tmp)

plot(fcst.tmp)

答案 1 :(得分:0)

我有同样的问题。如果您使用predict()而不是forecast(),则可以解决此问题。

ts.matrix <- as.ts(tmp.matrix)

VAR.tmp <- VAR(ts.matrix, p=1, type = "const")

fcst.tmp <- predict(VAR.tmp)

plot(fcst.tmp)