Monitor a model: actual against expected by period
actual_vs_expected.RdFor a stored model's predictions on new data, the actual and expected
totals of each period, A = sum(w * y) and E = sum(w * mu), with the
z-score (A - E) / sqrt(dispersion * sum(w * V(mu))) under the model's
variance function V: about standard normal while the model holds. The
trend is the slope of A / E - 1 per period step (periods in sorted
order), weighted by each period's precision, with its standard error;
trend_z beyond about 2 suggests drift.
Usage
actual_vs_expected(
periods,
actual,
expected,
family,
weights = NULL,
dispersion = 1,
theta = NULL,
power = NULL
)Arguments
- periods
One period label per row (numbers or strings).
- actual
Observed responses.
- expected
The model's predicted means for the same rows, e.g.
predict(model, newdata).- family
As in
glm_fit().- weights
Optional prior weights as fitted (exposure for a rate); leave out for counts with exposure in the offset.
- dispersion
The model's dispersion, e.g.
model@dispersion.- theta, power
Negative binomial
theta, Tweediepower.