Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Error in round(frequency): non-numeric argument to math function from VAR model

Help solve:

fcst.tmp <- forecast(VAR.tmp) Error in round(frequency) : non-numeric argument to mathematical function

From code:

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.

The tmp.matrix needs to be converted to a time series though:

ts.matrix <- as.ts(tmp.matrix)
VAR.tmp <- VAR(ts.matrix, p=1, type = "const")
fcst.tmp <- forecast(VAR.tmp)
plot(fcst.tmp)
like image 493
user8098814 Avatar asked Nov 16 '25 01:11

user8098814


1 Answers

the tmp.matrix needs to be converted to a time series through:

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

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

fcst.tmp <- forecast(VAR.tmp)

plot(fcst.tmp)
like image 169
user8098814 Avatar answered Nov 18 '25 19:11

user8098814



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!