Added cpp function for calculating model statistics