I am quite newbie in R but I am trying to manage to get through. I am working with time series dataset that I have set up via this code:
myts <- as.xts(df[,-1], order.by = as.POSIXct(df$DATE_3, format="%Y-%m-%d %H:%M:%S"))
=> my data series are hourly data that goes from 2006 to 2017
I have done simple lm regressions without any troubles. Then I started to test the statistical assumptions, I had no problems testing stationary of series and heteroscedasticity, however, on serial correlation, I tried to use following code:
library(car)
dwt(didreg6) 'didreg6 is the name of one of my regressions
but I received this error.
Error in if (ncol(x) == 1) { : argument is of length zero
I have tried to traceback() whether I mange to find any clue how to solve the error. I have received:
1: dwt(didreg6)
2: durbinWatsonTest(...)
3: durbinWatsonTest.lm(...)
4: matrix(sample(residuals, n * reps, replace = TRUE), n, reps)
5: as.vector(data)
6: as.vector(x, mode)
7: as.vector.zoo(x, mode)
8: as.vector(as.matrix(x), mode = mode)
9: as.matrix(x)
10: as.matrix.xts(x)
As I was not able to identify where the problem is, I have tried Ljung-Box because I though, maybe it would work.
Res<-residuals(didreg6)
Box.test(Res, lag = 1, type = "Ljung-Box")
However, I received another error, that I would guess relates to time series.
Error in if (frequency > 1 && abs(frequency - round(frequency)) < ts.eps) frequency
<- round(frequency) :
missing value where TRUE/FALSE needed
After, because I found out that my data series error is heteroscedastic, I wanted to use HAC errors instead of standard. I typed in this code:
library(estimatr)
didreg6_robust <- lm_robust(lnEL ~ sum of my explanatory variables, data = myts,
se_type = "stata")
summary(didreg6_robust)
But the same error showed up again:
Error in if (ncol(x) == 1) { : argument is of length zero
Eventually, I tried to use different coding for HAC errors:
didreg6 <- lm(lnEL ~ sum of my explanatory variables, data = myts)
summary(didreg6)
library(lmtest)
library(sandwich)
coeftest(didreg6, df = Inf, vcov = vcovHC(didreg6, type = "HC0"))
However still received an Error in if (ncol(x) == 1) { : argument is of length zero Follows the traceback():
1: coeftest(didreg7_coef, df = Inf, vcov = vcovHC(didreg7_coef, type = "HC0"))
2: coeftest.default(didreg7_coef, df = Inf, vcov = vcovHC(didreg7_coef, type = "HC0"))
3: vcovHC(didreg7_coef, type = "HC0")
4: vcovHC.default(didreg7_coef, type = "HC0")
5: meatHC(x, type = type, omega = omega)
6: estfun(x, ...)
7: estfun.lm(x, ...)
8: as.vector(res)
9: as.vector(x, mode)
10: as.vector.zoo(x, mode)
11: as.vector(as.matrix(x), mode = mode)
12: as.matrix(x)
13: as.matrix.xts(x)
I have read many articles about this error, however, neither of them deals with the issue, that the error is probably related time series. I have no missing data in whole dataset. ("Error in 1:ncol(x) : argument of length 0" when using Amelia in R) But I think, the error is in the first column, hence the column where I store the date and time.
Here is a preview of my dataset, maybe it will help in solving the issue: Data preview
Moreover I am getting really desperate, because I have no clue what is the reason for this error that still popups and how to deal with it.
Where is the mistake I made?