I wondered about this problem too, so I looked into the maths and made this demo. (It needs auto download of Wolfram computable document format (CDF) Player.) :-
https://www.facebook.com/mortgagedilemma
If you try it out you can see what conditions favour renting vs buying. My own conclusion was to aim to buy a property outright upon reaching retirement age, if not sooner.