llrplot <-
function(x, y)
{
# Makes ESSP, the weighted forward response and residual plots for loglinear regression.
#
# If q is changed, change the formula in the glm statement.
q <- 5 # change formula to x[,1]+ ... + x[,q] with q
out <- glm(y ~ x[, 1] + x[, 2] + x[, 3] + x[, 4] + x[, 5], family =
poisson)
ESP <- x %*% out$coef[-1] + out$coef[1]
Y <- y
par(mfrow = c(2, 2))
plot(ESP, Y)
abline(mean(y), 0)
Ehat <- exp(ESP)
indx <- sort.list(ESP)
lines(ESP[indx], Ehat[indx])
lines(lowess(ESP, y), type = "s")
title("a) ESSP")
Vhat <- (y - Ehat)^2
plot(Ehat, Vhat)
abline(0, 1)
#abline(lsfit(Ehat, Vhat)$coef)
title("b)")
Z <- y
Z[y < 1] <- Z[y < 1] + 0.5
MWRES <- sqrt(Z) * (log(Z) - x %*% out$coef[-1] - out$coef[1])
MWFIT <- sqrt(Z) * log(Z) - MWRES
plot(MWFIT, sqrt(Z) * log(Z))
abline(0, 1)
#abline(lsfit(MWFIT, sqrt(Z) * log(Z))$coef)
title("c) WFRP Based on MLE")
plot(MWFIT, MWRES)
title("d) WRP Based on MLE")
}
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.