There are some interesting additional complexities to add to this, because there are three types of keywords:
Exact match: "red apples"
Partial match: "red" ... "apples" ... "apple"
LSI keywords: "red delicious", "pink lady", "braeburn", "gala"
Another question is how different tools measure exact match keywords - for example, a complete sentence: "We grow the greatest apples in shades of red and green." might be measured by one keyword tool as an exact match query because it contains both red and apples, whereas another might measure only exact phrases, and count it differently, as partial matches.
We can't be sure exactly how Google is measuring keywords but we can make a guess by careful study of our competitors and through experimentation.
But the bottom line is that this metric is used to determine relevance, there is absolutely no measure of "quality". In fact if one is missing a three occurrences of "red socks" in the document to be considered a sports document one could simply add a "sentence" to the end of the document "red socks, red socks, red socks!".
Google has separate measures for quality, so to rank well you must cover all of your bases, you can't rank on a minority of factors. Unfortunately Google seems to be favouring keywords quite strongly at the moment. Keywords aren't incompatible with quality though, if they make you think about the depth of your topic and rewrite on that basis.
Though I can't confirm it, I suspect writing "red socks, red socks, red socks" in one sentence could well only count for one mention of red socks, or might even trigger a penalty score for that sentence. I learned the hard way that accidentally duplicating words in the url or page title can cause a penalty, even if they're part of your brand name, so I don't see why they wouldn't be doing the same trick on the body text, even down to paragraph and sentence.
Regarding keyword placement - you have to treat each element on the page separately, as well as look at the overall frequency. As I've said before, don't go much over 1.5x the serp top 10 average (removing anything that looks like query deserves diversity first). You will get a spam penalty for going too high. Try to mimic the location of the keywords used by your competitors in heading tags and body text. You can use partial match keywords much more liberally than exact match, and you can fill your page with plenty of LSI keywords without penalty *at the moment* (the competitor at the top of my niche has pages covered in almost pure LSI keyword spam, not even in sentences). That's not to say to repeat the same LSI keywords, just add all the variety you can think of.
Google seems to pick up LSI keywords from looking at the web pages already ranking and finding additional *meaningful* words in common. I have an anecdote about this too: I've been having real trouble ranking for the short tail in my niche. I'm in a niche where all of my page titles necessarily contain the short tail keyword along with long tail specific keywords, and one of my pages in particular was causing keyword cannibalisation issues. I recently managed to confirm to myself that Google really really loves to reward LSI keywords, and that the page causing a conflict contained an LSI keyword in the title. Everyone else in my niche was using that keyword on many pages, whereas I had a specific page dealing with that topic, and Google was trying to rank that page instead of my home page, even though it had less overall relevancy! I had to move the copy from it to my home page and 301 redirect it to get my home page to appear on the short tail.