Calculates R-squared values for each population. Can also compute modified total R-squared values, with data centered and/or scaled within populations. This can provide a more useful total fit estimate if the populations have very different local means.

getR2pop(obs, pred, pop, type = c("within", "centered", "scaled"))

Arguments

obs

Vector of observed values.

pred

Vector of predicted values.

pop

Vector of pop identifiers.

type

The type of R-squared to calculate: "within" (default) gets within-population, "centered" gets across-population but with local means removed, "scaled" get across-population but with local scaling (local means removed and rescaled to unit variance).

Value

If type="within", a list of 2 named vectors with R-squared and rmse for each populaiton. Otherwise a scalar (the R-squared).

Details

Returned R-squared might be negative. This indicates that the prediction is worse than using the mean.

See also