Plot of a Two-Way Fit

DESCRIPTION:

Gives a graphical representation of the fit from a two-way ANOVA table.

USAGE:

plotfit(fit, w=0, c=-1, rowlab=<<see below>>, collab=<<see below>>,  
         grid=T) 

REQUIRED ARGUMENTS:

fit
object with components row, col, grand, and resid, reflecting a two-way fit to a matrix. This is usually the output of function twoway. Missing values ( NAs) are allowed in components of fit.

OPTIONAL ARGUMENTS:

w
interaction term, i.e., the coefficient of the row*col interaction (Tukey's one degree of freedom for non-additivity).
c
residuals larger in magnitude than c will be displayed. If c<0, no residuals will be displayed; if c=0, all residuals will be displayed.
rowlab
vector of character strings giving labels for the rows of the matrix. This defaults to the dimnames of the resid component, if present, or else "Row i". To omit labels, use rowlab="".
collab
vector of character strings giving labels for the columns of the matrix. This defaults to the dimnames of the resid component, if present, or else "Col i". To omit labels, use collab="".
grid
logical flag: should grid of fitted values be drawn?

Graphical parameters may also be supplied as arguments to this function (see ). In addition, the high-level graphics arguments described under and the arguments to may be supplied to this function.

SIDE EFFECTS:

a plot representing a decomposition of a two-way table. A grid is drawn giving the additive (plus interactive if w is not zero) fit with the vertical direction representing the estimated response. Residuals may also be shown on the plot.

DETAILS:

The vertical axis of the plot represents the response; the horizontal axis is arbitrary. In the default configuration when there are no residuals and no interaction, a rectangle will be plotted with parallel lines inside of it. Each intersection of two lines represents the fit at a particular cell of the two-way table. Residuals are plotted as vertical lines starting from such an intersection.

The interaction term w is often estimated as the slope of the residuals versus the comparison values; the comparison value for cell ( i, j) is row[i] * col[j] . (Note that some texts define the comparison value as what is given above divided by grand; if you define the comparison values this way, you will need to divide the slope of the regression line by grand to use as the w argument.) The residuals in fit should NOT reflect this term, i.e., data[i,j] equals grand + row[i] + col[j] + resid[i,j].

REFERENCES:

Hoaglin, D. C., Mosteller, F., and Tukey, J. W. (1983). Understanding Robust and Exploratory Data Analysis. Wiley, New York.

Mosteller, F. and Tukey, J. W. (1977). Data Analysis and Regression. Addison-Wesley, Reading, Mass.

Velleman, P. F. and Hoaglin, D. C. (1981). Applications, Basics, and Computing of Exploratory Data Analysis. Duxbury Press, Boston.

SEE ALSO:

, , .

EXAMPLES:

plotfit(twoway(cereal.attitude)) 
# function to estimate and plot non-additivity 
plotfit.odof <- function(fit, method = "ls", res = -1, grid = T) 
{ 
        compare.val <- outer(fit$row, fit$col, "*") 
        switch(match(method, c("ls", "lms"), nomatch = 0) + 1, 
                stop(paste("invalid method:", method)), 
                ww <- lsfit(as.vector(compare.val), as.vector(fit$resid))$ 
                        coef[ 2], 
                ww <- lmsreg(as.vector(compare.val), as.vector(fit$resid))$ 
                        coef[ 2]) 
        plotfit(fit, w = ww, c = res, grid = grid) 
} 
nw <- c("Idaho", "Montana", "Oregon", "Washington", "Wyoming") 
vr <- twoway(votes.repub[nw, 27:31]) # Northwest states, last 5 years 
plotfit(vr, c=4) 
title(main="Twoway Fit to Republican Votes", 
      sub="Northwest States for 1964 - 1972")