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:

enter image description here

Well, what I understood that this is a histogram for the linear discriminant function values for each of the 2 levels. But with further investigations I found this: enter image description here

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.)

Thank you.


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).


closed as unclear what you're asking by whuber Nov 19 '18 at 18:33

Please clarify your specific problem or add additional details to highlight exactly what you need. As it's currently written, it’s hard to tell exactly what you're asking. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.

  • $\begingroup$ Unfortunately, you haven't provided anything--certainly not a counterexample. There is no apparent relationship between the response object, the arguments to the lda command, or the plot. The contorted code is also of concern: what is the reason you have not directly computed response$x[response$class=='Up']? This suggests the problem might be due to issues in undisclosed software commands you used to produce the example. $\endgroup$ – whuber Nov 19 '18 at 18:36
  • $\begingroup$ Okay, I apologize for not mentioning what response is. I edited the question. My question is -since I couldn't provide a counter example- is simply: What's the output of the plot(ldam) command. I don't want the interpretation of the result. I just want to know what's on the x axis and what's on the y axis. That's all. Thank you. $\endgroup$ – Youssef Esseddiq Nov 19 '18 at 18:48
  • $\begingroup$ At the very least you need to tell us what package you are using! $\endgroup$ – whuber Nov 20 '18 at 14:07
  • $\begingroup$ Well it's the lda { MASS } for linear discriminant analysis. $\endgroup$ – Youssef Esseddiq Nov 20 '18 at 15:24