Skip to contents

Source: Hedderich, Sachs and Reynarowych, Applied Statistics: Methods Using R, section 8.5, printed page 843, equations (8.80) and (8.81): D = 2 sum [y_i log(y_i / lam_i) - (y_i - lam_i)], printed also as 2 sum y_i log(y_i / lam_i). The two agree only when sum (y_i - lam_i) = 0, which the book states one paragraph above holds exactly when the model carries an intercept. The general form is computed; the third printed line is returned as D_nointercept alongside resid_sum so the identity can be inspected.

Usage

Poisdev(y, lamhat, p = NULL, alpha = 0.05)

Arguments

y

Observed non-negative counts.

lamhat

Fitted Poisson means, strictly positive.

p

Number of predictors excluding the intercept; when given, D is referred to chi-squared on n - p - 1 degrees of freedom.

alpha

Significance level for the decision.

Value

list: statistic, deviance, pearson_chisq, D_nointercept, resid_sum, df, pvalue, reject, n.

Details

BOOK ERRATUM in (8.81): the printed statistic is D ~= sum (y_i - lam_i) / lam_i. That numerator is not squared, so with an intercept it sums to (nearly) zero by the identity just quoted and cannot approximate a positive deviance. The Pearson chi-squared for a Poisson fit is sum (y_i - lam_i)^2 / lam_i, which is what is computed; the literal printed form is not implemented.

0 log 0 is taken as 0.

Examples

Poisdev(c(2, 3, 5), c(2.1, 3.2, 4.7))$deviance
#> [1] 0.03636225