merging formula and dfm model fitting functions