Alternative Goodness-of-fit Measure (Reading: Faraway (2006), section 2.9)
¡@
We now use the Bliss insect data studied in the previous lab, to demonstrate how to calculate the Perason's X^{2} statistic:
> bliss <- read.table("bliss.txt")
> modl <- glm(cbind(dead,alive) ~ conc, family=binomial, data=bliss)
> sum(residuals(modl,type="pearson")^2)
[1] 0.3672674
The Perason's X^{2} statistic is typically close in size to the deviance:
> deviance(modl)
[1] 0.3787483
As can be seen, there is little difference here between the X^{2} and the deviance.
¡@
For the Bliss insect data, the generalized R^{2 }can be calculated by:
> (1-exp((modl$dev-modl$null)/150))/(1-exp(-modl$null/150))
[1] 0.9953178
Notice that
the generalized R^{2} is very close to 1, which indicates this is a very good fit.
in the calculation of the generalized R^{2}, we have use K=150 as there are 5 covariate classes (i.e., k=5) each with 30 Bernoulli observations (i.e., n_{i}=30 for i=1,...,k).