2017-06-01 41 views
1

帮助解决:R错误:非数字参数数学函数从VAR模型

fcst.tmp < - 预测(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) 

PS

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) 
+0

最后,你的错误是不可重现的。我尝试了'预测'功能来确保我获得了'VAR.tmp'的精美图。 – Masoud

回答

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) 
+0

这没有解决这个问题 – mike

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)