Learn R Programming

vcdExtra (version 0.5-2)

meanResiduals: Average Residuals within Factor Levels

Description

Computes the mean working residual from a model fitted using Iterative Weighted Least Squares for each level of a factor or interaction of factors.

Usage

meanResiduals(object, by, standardized=TRUE, as.table=TRUE, ...)

Arguments

object
model object for which object$residuals gives the working residuals and object$weights gives the working weights.
by
a list of factors.
standardized
logical: if TRUE, the mean residuals are standardized to be approximately standard normal.
as.table
logical: if TRUE the result is returned as a table cross-classified by the factors passed to by.
...
currently ignored

Value

  • If as.table == TRUE, the mean residuals cross-classified by the factors passed to by, otherwise a vector of mean residuals. In either case the returned object has a single attribute, "weights" which gives the weight associated with each grouped residual.

Examples

Run this code
data(yaish)
## Fit a conditional independence model, leaving out
## the uninformative subtable for dest == 7:
CImodel <- gnm(Freq ~ educ*orig + educ*dest, family = poisson,
               data = yaish, subset = (dest != 7))

## compute mean residuals over origin and destination
meanResiduals(CImodel, model.frame(CImodel)[c("orig", "dest")])

## display mean residuals for origin and destination
mosaic(CImodel, ~orig+dest)

## non-aggregated residuals
res1 <- meanResiduals(CImodel,
                      model.frame(CImodel)[c("educ", "orig", "dest")])

res2 <- residuals(CImodel, type = "pearson")

all.equal(res1[,,], res2[,,])

Run the code above in your browser using DataLab