Average Residuals within Factor Levels
Computes the mean working residuals from a model fitted using Iterative Weighted Least Squares for each level of a factor or interaction of factors.
meanResiduals(object, by, standardized=TRUE, as.table=TRUE, ...)
object |
model object for which |
by |
either a formula specifying a factor or interaction of factors (recommended), or a list of factors (the elements of which must correspond exactly to observations in the model frame). When a list of factors is specified, their interaction is used to specify the grouping factor. |
standardized |
logical: if |
as.table |
logical: logical: if |
... |
currently ignored |
For level i of the grouping factor A the mean working residual is defined as
(r_ij * w_ij)/(sum_(j = 1)^(n_i) w_ij)
where r_ij is the j'th residual for level i, w_ij is the corresponding working weight and n_i is the number of observations for level i. The denominator gives the weight corresponding to mean residual.
For non-aggregated residuals, i.e. when the factor has one level per observation, the residuals are the same as Pearson residuals.
An object of class "meanResiduals"
, for which print
and summary
methods are provided. A "meanResiduals"
object is a list containing the following elements:
call |
the call used to create the model object from which the mean residuals are derived. |
by |
a label for the grouping factor. |
residuals |
the mean residuals. |
df |
the degrees of freedom associated with the mean residuals. |
standardized |
the |
weights |
the weights corresponding to the mean residuals. |
Heather Turner
## 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 meanRes <- meanResiduals(CImodel, ~ orig:dest) meanRes summary(meanRes) ## Not run: ## requires vcdExtra package ## display mean residuals for origin and destination library(vcdExtra) mosaic(CImodel, ~orig+dest) ## End(Not run) ## non-aggregated residuals res1 <- meanResiduals(CImodel, ~ educ:orig:dest) res2 <- residuals(CImodel, type = "pearson") all.equal(as.numeric(res1), as.numeric(res2))
Please choose more modern alternatives, such as Google Chrome or Mozilla Firefox.