function for fitting a model from model builder