It is a number of factors, and no one knows the exact algorithm, that's the secret sauce or holy grail everyone wants.
obviously the title tag is the main source for onpage SEO, the title of a page is meant to be descriptive of its contents.
Then there is the copy text, but it has nothing to do with occurrences otherwise know as 'keyword density', but it's not a measurable metric to use, the only time you need to worry about kwd density is if you use a keywrod or phrase too much, then it's considered keyword spamming and will have a detrimental affect on your site.
Copy writing is an art, and no matter how much you understand the SE's, sometimes only professionaly written content by those with SE copy text skills will cut the mustard.
If only there was a fomular you could apply, i'd be using it in a shot, so try to write good content aimed at real visitors , use normal flowing english and you will usually find you've done all you need to do with the copy text.