I am unable to perform any type of analysis with univariate models, such as selectSETAR or even linear function in tsDyn. I get the error "
Error: `x` must be a vector, not a ts object, do you want `stats::lag()`?" even when I have not declared the vector as a time-series object. My work is on time series objects, but below I have generated price variables without declaring them to be time-series. Even then I get the same error message. Below are the codes, and error messages including the output from traceback(). What did I do wrong here?
#generate price variables
NormalPrices = as.data.frame(matrix(rnorm(300*2, mean=50, sd=10), ncol=2))
colnames(NormalPrices) = paste("Price", 1:2, sep="")
mod1 = lm(Price1~Price2, data = NormalPrices)
ehat = residuals(mod1)
#apply the linear function to the residuals
a<-mapply(linear, m=1:15, MoreArgs = list(x=ehat), SIMPLIFY=FALSE)
sapply(a,AIC)
sapply(a,BIC)
Error: `x` must be a vector, not a ts object, do you want `stats::lag()`?
#apply the selectSETAR function to the residuals
TAR.lags <- selectSETAR(ehat,include="const", common="include",
model="TAR", type="ADF", max.iter=500,
m=15, thDelay=1,
nthresh=2, trim=0.15, criterion="AIC", plot=T)
Error: `x` must be a vector, not a ts object, do you want `stats::lag()`?
> traceback()
8: stop(cnd)
7: .abort(text)
6: glubort(fmt_args(args), ..., .envir = .envir)
5: bad_args("x", "must be a vector, not a ts object, do you want `stats::lag()`?")
4: lag(x, lags[1])
3: embedd(x, lags = c((0:(m - 1)) * (-d), steps))
2: nlar.struct(x = x, m = m, d = d, steps = steps, series = series)
1: selectSETAR(ols.res22, include = "const", common = "include",
model = "TAR", type = "ADF", max.iter = 500, m = 15, thDelay = 1,
nthresh = 2, trim = 0.15, criterion = "AIC", plot = T)