I get an error when I try to use the VAR model in R.

Asked 2 years ago, Updated 2 years ago, 36 views

Using the VARselect function in the vars package of R results in the following error:

Error in lm.fit(x=ys.lagged,y=yendog): NA/NaN/Inf is in x

Addition:Warning messages:1:Inlm.fit(x=ys.lagged,y=yendog):NAs introduced by coercion

2:Inlm.fit(x=ys.lagged,y=yendog):NAs introduced by coercion

There are no missing values in the data. Why do I get errors?
I am a beginner in programming, so I would appreciate it if you could let me know if it is a basic error.

r

2022-09-30 19:11

1 Answers

How to write a good sample code will give you a better answer.

library(vars)

VARselect (Canada)# No Error
VARselect(iris)# Error (because non-numeric information is included)

is.numeric(Canada)#[1]TRUE
is.numeric(iris)#[1]FALSE

# If you do the following three things, you may know why.
is.numeric(xxx)# Is it all numeric data? (FALSE is bad)
any(is.na(xxx))#NA included or not (TRUE is bad)
any(is.infinite(as.matrix(xxx)))#Inf included (TRUE is bad)


2022-09-30 19:11

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.