data("wafers")
fit <- fitme(y ~X1+(1|batch) ,data=wafers, init=list(phi=NaN)) # : this 'init'
# implies that standardized deviance residuals are saved in the
# fit result, allowing the following comparison:
r1 <- residuals(fit, type="std_dev_res") # gets stored value
r2 <- residuals(fit, type="std_dev_res", force=TRUE) # forced recomputation
if (diff(range(r1-r2))>1e-14) stop()
#####
if (FALSE) {
glmfit <- glm(I(y/1000)~X1, family=gaussian(), data=wafers)
deviance(glmfit) # 3... (a)
sum(residuals(glmfit)^2) # 3... (b)
# Same model, with different parametrization of residual variance
glmfit2 <- glm(I(y/1000)~X1, family=gaussian(), data=wafers, weights=rep(2,198))
deviance(glmfit2) # 6... (c)
sum(residuals(glmfit2)^2) # 6... (d)
# Same comparison but for HLfit objects:
spfit <- fitme(I(y/1000)~X1, family=gaussian(), data=wafers)
deviance(spfit) # 3... (e)
sum(residuals(spfit)^2) # 3... (f)
sum(dev_resids(spfit)) # 3...
spfit2 <- fitme(I(y/1000)~X1, family=gaussian(), data=wafers, prior.weights=rep(2,198))
deviance(spfit2) # 6... (g) ~ (c,d) # post v4.2.0
sum(residuals(spfit2)^2) # 6... (h) ~ (c,d)
sum(dev_resids(spfit2)) # 3...
# Unscaled residuals should no depend on arbitrarily fixed residual variance:
spfit3 <- fitme(I(y/1000)~X1, family=gaussian(), data=wafers, fixed=list(phi=2),
prior.weights=rep(2,198))
deviance(spfit3) # 6... (i) ~ (g)
sum(residuals(spfit3)^2) # 6... (k) ~ (h)
sum(dev_resids(spfit3)) # 3...
}
Run the code above in your browser using DataLab