Custom R fit function with algebras - possible?