As informative as all that is it sadly doesn't really answer either of the 2 questions. Not that it really matters that much, I'm sure it'll make it in later on either way. would be nice to know though ^^
I believe the main factor on a dwarf by dwarf basis is personality traits, which have been redone for this release. If you go to a dwarf's info in fort mode it will tell you they "doesn't like people, get frustrated easily" that kind of thing, I believe now it will also tell you how well they handle fear.
So, Manveru, may I take the liberty of breaking up your questions?
Does a dwarf take whether he detests or has a phobia of a certain creature type into account when yielding or running away?
Does a dwarf take the size and/or rarity of a foe into account?
Does he take allies he may have with him into account? What if they are part of his squad, but half the map away en route at the moment?
And how does he actually take it all into account? Are two sets of variables added up and compared, or is there more to it?
1. No idea
2. Rarity isn't tracked currently, size almost certainly will be accounted for but I don't remember it ever being confirmed
3. Yes, the size of the two opposed factions are taken into account
4. Its likely comparing all the variables and then doing a random roll, same as normal. But Toady hasn't talked about specifics on this one yet either.