plotfit(fit, w=0, c=-1, rowlab=<<see below>>, collab=<<see below>>, grid=T)
row
,
col
,
grand
, and
resid
,
reflecting a two-way fit to a matrix.
This is usually the output of function
twoway
.
Missing values (
NA
s) are allowed in components of
fit
.
c
will be displayed. If
c<0, no residuals will be displayed; if
c=0
, all residuals
will be displayed.
resid
component,
if present, or else
"Row i"
. To omit labels, use
rowlab=""
.
resid
component,
if present, or else
"Col i"
. To omit labels, use
collab=""
.
w
is not zero)
fit with the vertical direction representing the estimated response.
Residuals may also be shown on the plot.
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]
.
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.
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")