In battles it all about speed, unless they have run away. in the safarri Zone i think it's set based on Rarity. damn kagnaskahns and chansey's always run right away on me. the odds change with bait and rocks of course.
Oh yeh, it's also determined by whether your opponent is a Golbat, in which case you'll only be able to escape with about 12 Hp, after having flinched/hurt yourself in confusion at least once.
Those things are so annoying. Hax Attax your pokemon, then leave them so weak they die on the next.
I think that its determined by how the pokemons speed are different ,the closer the speeds stats are the same,the less chance of running successfully Did u use agility or sumthing den ran? i dun think the stat changing moves count