5
$\begingroup$

I have real daily market data which I'm looking at to create a model for forecasting. The model that I created (below) used autoregressive terms within a linear regression.

I was sharing this with a colleague and he said "autoregressive variables are correlated with the other variables in multiple linear setting which creates multicollinarity problem, creating unreliable result."

So I'm turning to the group for help. Here is the data and the analysis that I performed in R.

#Read in Data
MarketData = read.table('http://sharp-waterfall-3397.herokuapp.com/MarketCategories6.txt', header=TRUE,na.strings = "NA", sep=",")
MarketData$Month <- as.factor(MarketData$Month)
MarketData$Weekday <- as.factor(MarketData$Weekday)

str(MarketData)

I'm using the PERregress library to help with the autoregression using the back() function and to help with the residual diagnostics:

library(PERregress)
descStat(MarketData)

Subsetting the data for model building and prediction purposes:

Total = MarketData
MarketData = MarketData[1:268,]
attach(MarketData)

Here is a regression with everything that I can think of. Note you can have higher autoregressive terms but this will start to mask events since R will ignore the first several rows. Also just an FYI for some reason the residual analysis is breaking which I liked to look for points with undue leverage.

#Market1Category1 Regression for the markets with everything that I can think of it
Market1Category1Output=lm(Market1Category1 ~ Trend+Month2+Month3+Month4+
                          Month5+Month6+Month7+Month8+Month9+Monday+
                          Tuesday+Wednesday+Thursday+Friday+Saturday+
                          Holiday1+Holiday2+Holiday3+Holiday4+
                          Event1+Event2+Event3+Event4+Event5+Event6+Event7+
                          Event8+Event9+Event10+Event11+Event12+Event13+
                          Event14+Event15+Event16+Event17+Event18+Event19+
                          Event20+Event21+Event22+Event23+Event24+Event25+
                          Event26+Event27+Event28+
                          back(Market1Category1)+back(Market1Category1, 2))
summary(Market1Category1Output)
acf(Market1Category1Output$residuals)
residualPlots(Market1Category1Output)

Here is the final equation. I'd like to say that I reduced the variables using partial f-test but I couldn't find an easy way to do this so if you know a function please let me know. Basically I looked at the change in adjusted $R^2$.

#Final regression equation 
Market1Category1Output=lm(Market1Category1 ~ Month5+Month6+Month7+
                          Tuesday+Wednesday+Thursday+Friday+Saturday+
                          Holiday1+Holiday3+Event2+Event7+Event10+
                          Event13+Event16+Event25+Event28+
                          back(Market1Category1)+back(Market1Category1, 6))
summary(Market1Category1Output)
acf(Market1Category1Output$residuals)
residualPlots(Market1Category1Output)

Here is a plot of the actuals in green vs the predictions in blue but there's a problem:

plot(Time, Market1Category1, col='green')
points(Time, predict(Market1Category1Output, MarketData), col='blue', pch=20)

The issue is that predict will use the data values instead of it's predicted values for the autoregressive terms. In order to make it use predicted terms I created this loop. If you know a better way let me know.

dataSet2 <- Total
dataSet2[8:length(dataSet2$Time),"Market1Category1"] <- NA
    for (i in (1:(length(dataSet2$Time)-7))) {
  dataSet2[6+i+1,"Market1Category1"] <- 1
  dataSet2[6+i+1,"Market1Category1"] <- predict(Market1Category1Output, 
                                                dataSet2[0:6+i+1,])[6+1] 
}

Here is the plot again with the results in blue using the predicted results for the autoregressive terms (with the exception of the first 7 since the model needs those to predict):

plot(Total$Time, Total$Market1Category1, col='green')
points(dataSet2$Time, dataSet2$Market1Category1, col='blue', pch=20)

So here are my questions in order of importance:

  1. Does using autoregressive and linear terms violate any fundamental assumptions?
  2. What issues can this cause and what analysis/steps should I do take to avoid these problems?
  3. Is there a better approach to modeling this timeseries?
  4. Is there a more efficient approach?
  5. Given the residuals what steps would you take?

Finally two questions which is just causing me more work than possibly necessary:

  1. As you can see instead of using the factors for weekday and month I'm using separate conditional variables. I'm doing this because if I use the factor and a level turns out to be insignificant (e.g., Monday for days of the week). I can't remove it. Perhaps there's a way?
  2. Is there a quick way to run a partial F-statistic to understand whether removing a variable makes sense?
$\endgroup$

put on hold as off-topic by mkt, Michael Chernick, StatsStudent, kjetil b halvorsen, Peter Flom 11 hours ago

This question appears to be off-topic. The users who voted to close gave this specific reason:

  • "This question appears to be off-topic because EITHER it is not about statistics, machine learning, data analysis, data mining, or data visualization, OR it focuses on programming, debugging, or performing routine operations within a statistical computing platform. If the latter, you could try the support links we maintain." – mkt, Michael Chernick, StatsStudent, Peter Flom
If this question can be reworded to fit the rules in the help center, please edit the question.