This does a few things including R squared, gets the fitted values. It appears that running the models "as is" without this wrapper does not work with Cache. The return of the model in a list solves this problem. For Caching, the .specialData should be "omitted" via omitArgs, and uniqueEcoregionGroups should not be omitted.

statsModel(modelFn, uniqueEcoregionGroups, sumResponse, .specialData)

Arguments

modelFn

A quoted expression of type package::model(Y ~ X, ...), omitting the data argument. E.g. lme4::glmer(Y ~ X + (X|G), family = poisson)

uniqueEcoregionGroups

Unique values of ecoregionGroups. This is the basis for the statistics, and can be used to optimize caching, e.g. ignore .specialData in .omitArgs.

sumResponse

a sum of all the response variable values Also to be used to optimize caching, e.g. ignore .specialData in .omitArgs.

.specialData

The custom dataset required for the model.