A method of controlling a medical device is disclosed for delivering respiratory therapy to a user to treat sleep-disordered breathing, for instance obstructive sleep apnea, Cheyne-Stokes respiration etc. by estimating the user's CO2 percentage or concentration from a dynamic lung model driven by an observed respiration signal. The estimated user's CO2 percentage or concentration can be used to predict breathing events, such as hypopnea and apnea. The predictive capacity can be used for adjusting the respiratory therapy as required or for applying a ramp cycle therapy, in an attempt to reduce the prevalence and adverse effects of the breathing events. In other examples a variable ventilation therapy is provided in which pressure is supplied between first and second pressures, with the pressure being increased over more than one breath, and then dropped relatively rapidly, for example during expiration of a single breath.