I'm reading the Introduction to statistical learning with R currently, but I blocked through a Lab about Discriminant analysis. So the thing is that we trying to fit a linear discriminant analysis model to Stock market data in order to predict the direction based on the last two days movement (Lag1&Lag2). So far no problems, we fit the model through a training data set (train):
I used lda from MASS package.
Here, it gets weird for me. When we do the following line of code:
I get this:
First, the plot above indicates that we have negative values of the linear discriminant function for the 'Up' level. While, when I use the model to predict over the training data set, and subset it to only have the observations for we which we have Up as a prediction, I get that the minimum value doesn't reach the values in the plot above.
So what I hope to know is:
1- What are the x and y axis?
2- In case the x axis is the value of the LD function for an observation from the training data set, and the y axis is the number of its occurrence inside a given level (Up or Down). Why when I do it using predict function, I get contradicting results to the given plot. (Min of LD function for the 'Up' level is: -0.37 while on the plot it suggests arround -4 values.)
After I saw this in another time I discovered what I was missing and the solution is as follows, the plots that plot(ldam) provides are actually based on the training data set. In a broad way the training data set is used to generate LD coefficients $\alpha_1$ and $\alpha_2$. Using these coefficients on the training data set in the form: $\alpha_1*Lag1+\alpha_2*Lag2$ and plot histograms based on which class they belong to (Up/Down).