Yates's algorithm
yates.Rd
Implementations of Yates's method for obtaining factor effects; and reverse Yates's method for recovering response values; and a generalization for balanced unreplicated experiments having other than two-level factors.
Arguments
- y
Numeric vector of response values or effects, in standard order. See Details.
- labels
Character labels for 2-level factors to use when
y
contains resoponse values. The first \(log_2(n)\) are used, where \(n\) islength(y).
- sep
Character to use between labels for interaction effects.
- nlevels
Numeric vector of numbers of levels. The number of observations is assumed to be
prod(nlevels).
- basis
Character value or vector specifying what method to use to generate orthonormal contrasts. Built-in ones include
"poly"
and"helmert"
, but the user may create others. The elements ofbasis
are recycled cyclically as needed.
Details
These functions implement a method for computing factor effects for balanced, unreplicated designs without need for a matrix of predictor levels. Instead, the responses must be arranged in standard order. The method is described in Yates (1937) for the case where all factors have two levels (as implemented in yates
), and its generalization (gyates
) can be found in Good (1958). Both are described in Drum (2005). In this implementation, gyates()
uses orthonormal (unitary) matrices, rather than keeping track of needed divisors.
Standard order (also called Yates order) is that in which the first factor varies the fastest and the last varies the slowest. The expand.grid
function creates factor combinations in standard order. The yates
function is for experiments with all factors having two levels. The returned effects are also in standard order: with the default labels in yates
, the order of the returned effects is (intercept), A, B, AB, C, AC, BC, ABC, D, etc.: note that absence or presence of each factor proceeds in standard order.
In both yates
and gyates
, if the length of y
is one less than expected, y
is assumed to be a set of effects, without the intercept. In that instance, the algorithm is reversed and the response values are recovered from the effects. Since the intercept is absent, the mean is arbitrary. If y
has a "mean"
attribute, the mean is adjusted to that value; otherwise, the recovered responses have a mean of zero.
In gyates
, the values of nlevels
and basis
are saved as attributes. In a subsequent call on the returned effects, these values are used and will override the nlevels
and basis
arguments supplied by the user.
Effects are scaled to all have the same variance. In yates
, we apply the same convention as in most design texts, e.g., Box et al. (2005): effect = (mean at "+" level) - (mean at "-" level), which is twice the regression coefficient one obtains by regressing y
on predictors of -1s and +1s. In gyates
, effects are computed using orthonormal contrasts, making the squared effects equal to their ANOVA sums of squares. When effects are reversed, the same scaling is assumed. Also, if the elements of y
are independent, so are the effects.
The two basis functions supplied are "poly"
and "helmert"
, which are based on contr.poly
and contr.helmert
respectively. Users may create a custom basis, say "foo"
, by writing a function foo_gyb = function(k) {...}
, and supplying basis = "foo"
in the call. The function should return a k
by k
matrix having its first column equal to 1/sqrt(k)
and orthonormal contrasts in the remaining columns.
Value
If length(y)
is a power of two (in yates
) or the product of nlevels
(in gyates
), a vector of length(y) - 1
effects is returned (the intercept is omitted). In addition, the returned value has a "mean"
attribute set equal to mean(y)
. The effects from yates
are named in standard order using the labels provided. The effects from gyates
are labeled using patterns of the characters .123456789
. Any .
in a label indicates a factor whose effect is out of play. For illustration, with 3 factors, the effect named .1.
is the first-order effect of the second factor, and the one named 23.
is the interaction of the second-order effect of the first factor and the third-order effect of the second factor.
If length(y)
is one less than a power of two or the product of levels, then a vector one longer of response values is returned. The names of the returned responses are symbol combinations from -+
for yates
, and 123456789
from gyates
. For example, in yates
with length(y) = 7
, the returned values are labeled ---, +--, -+-, ++-, --+, +-+, -++, +++
; and gyates
with 5 effects and nlevels = c(3, 2)
, the returned effects are labeled 11, 21, 31, 12, 22, 32
.
References
Box, GEP, Hunter, JS, and Hunter, WG (2005) Statistics for Experimenters (2nd ed) New York: John Wiley & Sons
Drum, M (2005) Yates's Algorithm. Encyclopedia of Biostatistics, 8. Wiley.
Good, IJ (1958) The interaction algorithm and practical Fourier analysis. Journal of the Royal Statistical Society, Series B 20, 361-372.
Yates, F (1937) The design and analysis of factorial experiments. Technical Communication of the Commonwealth Bureau of Soils, 35, Commonwealth Agricultural Bureau, Farnham Royal
Examples
require("unrepx")
# pilot-plant example, BH^2 p. 177
yates(c(60, 72, 54, 68, 52, 83, 45, 80), labels = c("T", "C", "K"))
#> T C TC K TK CK TCK
#> 23.0 -5.0 1.5 1.5 10.0 0.0 0.5
#> attr(,"mean")
#>
#> 64.25
# recover shrinkage data
yates(shnkEff)
#> ---- +--- -+-- ++-- --+- +-+- -++- +++- ---+ +--+ -+-+ ++-+ --++ +-++ -+++ ++++
#> 48.5 57.5 8.8 17.5 18.5 14.5 22.5 17.5 12.5 12.0 45.5 53.5 17.0 27.5 34.2 58.2
# A 3 x 2 x 4 example
y <- c( 214, 193, 207, 193, 178, 188,
225, 206, 213, 221, 214, 216,
227, 213, 221, 231, 215, 225,
228, 203, 206, 190, 178, 195 )
yeff <- gyates(y, c(3,2,4), basis = "helmert")
head(eff.test(yeff)) ## Show the largest few effects
#> effect Zahn_PSE t.ratio p.value simult.pval
#> ..1 35.21837 8.766567 4.017 0.0006 0.0126
#> ..2 32.66667 8.766567 3.726 0.0011 0.0218
#> 1.. -32.25000 8.766567 -3.679 0.0012 0.0247
#> ..3 -23.57023 8.766567 -2.689 0.0122 0.2092
#> .1. -22.86190 8.766567 -2.608 0.0146 0.2483
#> .13 -21.68461 8.766567 -2.474 0.0190 0.3075