# Why is my question about replicating a figure from Hastie et al. not appropriate?

I asked this question earlier today but was quickly put on hold with a generic comment. I can only assume the question is on hold as it has been interpreted as being a coding question. It is clear from the question, however, that I am trying to understand a statistical concept from a textbook. In particular, I am not clear on what the authors mean exactly by the formula on the Y-axis (including code was just a reference explaining my current interpretation and could easily be ignored) and was looking for some guidance on how to interpret it.

The alternative is stack overflow, but my code does exactly what I want it to do, my question involves figuring out what I want it to do statistically. Reading from the help center seems to indicate this is the correct place. Maybe I am missing something but is this not a reasonable question to be asking on this site?

• I don't see a question anywhere in your post. Eg, I don't see a "?", & ctrl-f doesn't find one. If you really want "to understand a statistical concept from a textbook", that should be on topic, but I can't tell that from that post (as opposed to here). Can you edit it to clarify what you're after? – gung - Reinstate Monica Jun 3 '19 at 19:47
• Ok I have added a question to make it explicit. I'm happy to improve my question but how was I to know what the issue was? – Seraf Fej Jun 3 '19 at 19:56
• Thank you for that. There seems to be some concern that the explicit questions are not your primary or only question, but that you also / really want the code debugged. Since you say you aren't after that, it might be less worrying for people if you were to delete the code & your figure, so the only questions were the ones that are explicitly listed. – gung - Reinstate Monica Jun 4 '19 at 14:01

I agree with @whuber's answer, but another issue is that you are implying multiple questions in a single post:

1. What does $$\mathbb{E}||\hat{\beta}(k) - \beta||^2$$ in the y-axis of fig. $$3.6$$ of Elements of Statistical Learning mean?
2. Is my interpretation of how fig. $$3.6$$ of Elements of Statistical Learning was made correct?

And ultimately:

1. Why does my implementation of fig. $$3.6$$ of Elements of Statistical Learning not result in the same plot?

On their own, (1) and (2) are both perfectly on-topic. Once you have the answers to these, (3) might be better suited for SO. This might seem like a hassle, but to understand why a compound question is a problem, keep the goal of SE in mind: Ultimately your post should be useful to future readers with similar issues.

• If someone else also wants to know (1), should their question be marked a duplicate of yours? Should they have to find the relevant piece of information in the context of a larger question? Or the other way around, crippling your ability to gain an answer to (2) and (3)?
• What should the title of your question be, such that others with any of your questions can find it easily?
• If a reader knows the answer to (1), or (2), or (3), but cannot/does not want to answer the other questions, is it okay to have an answer that only partially addresses the question?

There is no limit to the number of questions you can ask here and it is both much easier for others with questions and for anyone interested in answering if you post your questions separately. Plus, you can get more reputation from multiple on-topic questions, perhaps allowing you to put a bounty on a question that you want to receive more attention.

• Thank you for these clarifying remarks--they have helped me better understand the issues. +1 of course. – whuber Jun 4 '19 at 11:57
• Thank you for the detailed feedback, I have added a new question taking this into account stats.stackexchange.com/questions/415420/… – Seraf Fej Jun 30 '19 at 16:45

The question is clear and well formulated, so please don't take anything in this answer to be critical of your craftsmanship. But when code doesn't do what you want it to do, there are two kinds of possibilities: the code is wrong (or there are bugs in the software platform); or the underlying concept is wrong (or the book was incorrect).

We address concepts here--the second kind of possibilities--and will tolerate a certain amount of code in the presentation of question when it's otherwise clear what needs to be addressed. However, this particular question (a) employs a great deal of code--several pages; (b) relies heavily on the code to express itself; (c) has clear coding errors (some of which were addressed in comments); and (d) shows no evidence of having been checked or debugged: it does quite a lot in a few lines, just about any of which could be problematic.

On that basis I think this question would be more suitable for SO. However, it might be closed there if there's a perception that the code does not offer a minimal reproducible example. I find this (hard and fast) criterion to be useful here on CV, too: if we really must rely on code to understand and answer a question, then please make the code be as small, simple, and clear as possible. Show what you have done to assure that its component calculations are correct, so that we can focus on the extent to which it implements the intended procedure.

Another good criterion is this: if an effective answer is, or is likely to be, "read the manual page," then the question is not on topic here. In reviewing the question I note that you are using R's rnorm function to generate Normal random variables in a way that is inconsistent with the ESL terminology: by "$$N(0,6.25)$$" it means a Normal distribution of mean zero and variance $$6.25,$$ as indicated inter alia near Equation $$(3.9)$$ on p. 47, whereas R's rnorm uses the mean and standard deviation as arguments. When the issue is that the function isn't being correctly called, arguably the problem is in the software, not the concepts.

• Note that there are now 2 explicit questions, "What exactly does the formula on the y axis mean? Is it just the kth beta being compared?" I think these can be addressed w/o bothering with the code. Moreover, these questions seem on topic to me. (Otherwise, I agree w/ everything in this answer.) – gung - Reinstate Monica Jun 3 '19 at 20:34
• @gung, I see you have already addressed my answer in a comment. Sorry, I read it after I posted it. – Frans Rodenburg Jun 4 '19 at 3:43
• Thank you for the detailed feedback, I have added a new question taking this into account stats.stackexchange.com/questions/415420/… – Seraf Fej Jun 30 '19 at 16:45