Structural and magnetic phase transitions in mixed-valence cobalt oxides REBaCo4O7 (RE=Lu, Yb, Tm)