Lattice dynamical methods used to predict phase transformations in crystals typically deal with harmonic phonon spectra and are therefore not applicable in important situations where one of the competing crystal structures is unstable in the harmonic approximation, such as the bcc structure involved in the hcp to bcc martensitic phase transformation in Ti, Zr and Hf. Here we present an expression for the free energy that does not suffer from such shortcomings, and we show by self consistent {it ab initio} lattice dynamical calculations (SCAILD), that the critical temperature for the hcp to bcc phase transformation in Ti, Zr and Hf, can be effectively calculated from the free energy difference between the two phases. This opens up the possibility to study quantitatively, from first principles theory, temperature induced phase transitions.