Fit of a Two-Way Table

DESCRIPTION:

Returns a list containing estimated row and column effects as well as a grand effect and the residuals. The default is to give estimates from a median polish. This is a generic function with methods for formula (see twoway.formula) and matrices (the default method).

USAGE:

twoway(x, trim=.5, iter=6, eps=<<see below>>, print=F) 
twoway.default(x, trim=.5, iter=6, eps=<<see below>>, print=F) 

REQUIRED ARGUMENTS:

x
matrix representing an unreplicated two-way table to be analyzed. Missing values ( NAs) are allowed. Rows represent the levels of one of the factors and columns represent the levels of the other factor.

OPTIONAL ARGUMENTS:

trim
optional trimming fraction for carrying out the analysis. The default value corresponds to using medians. trim=0 will cause analysis by means, .25 by midmeans, etc.
iter
maximum number of full (both row and column) sweeps.
eps
error tolerance. If eps is given, the algorithm will iterate until the maximum change in row or column effects is less than eps. The default is to iterate until the specified number of iterations or until converged to the accuracy of the machine arithmetic. It is not always possible to converge to a unique answer.
print
logical flag: if TRUE, the maximum change in row/column effects in the last iteration is printed.

VALUE:

list with 4 components, resid, row, col, and grand, such that x[i,j] equals grand + row[i] + col[j] + resid[i,j]
grand
overall location estimate of the data.
row
vector of row effects.
col
vector of column effects.
resid
matrix of residuals from the fit.

DETAILS:

Missing values are omitted in the computations. Results are currently computed to single-precision accuracy only.

With the default trim=.5 a median polish is performed on the table. Median polish is a simple and very useful technique for detecting anomalous behavior in a two-way table. Although not particularly efficient when the errors have the Gaussian (Normal) distribution, median polish has the highest breakdown possible. Outliers in a two-way (or higher dimensional) table can be very hard to detect without a procedure with at least a moderate breakdown point.

There is no guarantee that median polish will converge for a particular table, but in practice convergence is often achieved after 3 or 4 iterations. Even when there is not convergence, the result will be close to the converged result. Although the median is the L1 (Least Absolute Deviations) solution for the location problem, median polish usually has a sum of absolute deviations greater than an L1 solution, however, it has the good robustness properties that L1 enjoys.

When trim=0, a least squares fit is found. If there are no missing values, then this is the fit with which an Analysis of Variance works.

REFERENCES:

Hoaglin, D. C., Mosteller, F. and Tukey, J. W., editors (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, Boston.

SEE ALSO:

. Function produces a graphical display of the fit generated by . To simulate a two-way table, see the example in . fits an ANOVA model.

EXAMPLES:

twoway(cereal.attitude, trim=.25) # analysis by midmeans