porthogonalize.listR Documentation

Takes a list of projectors and constructs a pstructure.object that includes projectors, each of which has been orthogonalized to all projectors preceding it in the list.

Description

Constructs a pstructure.object that includes a set of mutually orthogonal projectors, one for each of the projectors in the list. These specify a structure, or an orthogonal decomposition of the data space. This function externalizes the process previously performed within pstructure.formula to orthogonalize projectors. There are three methods available for carrying out orthogonalization: differencing, eigenmethods or the default hybrid method.

It is possible to use this function to find out what sources are associated with the terms in a model and to determine the marginality between terms in the model. The marginality matrix can be saved.

Usage

## S3 method for class 'list'
porthogonalize(projectors, formula = NULL, keep.order = TRUE, 
               grandMean = FALSE, orthogonalize = "hybrid", labels = "sources", 
               marginality = NULL, check.marginality = TRUE, 
               omit.projectors = FALSE, 
               which.criteria = c("aefficiency","eefficiency","order"), 
               aliasing.print = TRUE, ...)

Arguments

projectors

A list each of whose components is a projector.

formula

An object of class formula from which the projectors have been obtained. If NULL, then the differencing option of orthogonalize is not available.

keep.order

A logical indicating whether the terms should keep their position in the expanded formula projector, or reordered so that main effects precede two-factor interactions, which precede three-factor interactions and so on.

grandMean

A logical indicating whether the projector for the grand mean is to be included in the set produced.

orthogonalize

A character vector indicating the method for orthogonalizing a projector to those for terms that occurred previously in the formula. Three options are available: hybrid; differencing; eigenmethods, unless formula is NULL in which case differencing is not available. The hybrid option is the most general and uses the relationships between the projection operators for the terms in the formula to decide which projectors to substract and which to orthogonalize using eigenmethods. The differencing option subtracts, from the current projector, those previously orthogonalized projectors for terms whose factors are a subset of the current projector's factors. The eigenmethods option recursively orthogonalizes the projectors using an eigenanalysis of each projector with previously orthogonalized projectors.

labels

A character nominating the type of labels to be used in labelling the projectors, and which will be used also in the output tables, such the tables of the aliasing in the structure. The two alternatives are terms and sources. Terms have all factors/variables in it separated by colons (:). Sources have factors/variables in them that represent interactions separated by hashes (#); if some factors are nested within others, the nesting factors are surrounded by square brackets ([ and ]) and separated by colons (:). If some generalized, or combined, factors have no marginal terms, the constituent factors are separated by colons (:) and if they interact with other factors in the source they will be parenthesized.

marginality

A square matrix that can be used to supply the marginality matrix when it is desired to overwrite the calculated marginality matrix or when it is not being calculated. It should consist of zeroes and ones that gives the marginalites of the terms in the formula. It must have the row and column names set to the terms from the expanded formula, including being in the same order as these terms.

The entry in the ith row and jth column will be one if the ith term is marginal to the jth term i.e. the column space of the ith term is a subspace of that for the jth term and so the source for the jth term is to be made orthogonal to that for the ith term. Otherwise, the entries are zero. A row and column should not be included for the grand mean even if grandMean is TRUE.

check.marginality

A logical indicating whether the marginality matrix, when it is supplied, is to be checked against that computed by porthogonalize.list. It is ignored when orthogonalize is set to eigenmethods.

omit.projectors

A logical, which, if TRUE, results in the projectors in the Q of the pstructure.object being replaced by their degrees of freedom. These will be the degrees of freedom of the sources. This option is included a device for saving storage when the projectors are not required for further analysis.

which.criteria

A character vector nominating the efficiency criteria to be included in the summary of aliasing between terms. It can be none, all or some combination of aefficiency, mefficiency, sefficiency, eefficiency, xefficiency, order and dforthog – for details see efficiency.criteria. If none, no summary is printed.

aliasing.print

A logical indicating whether the aliasing between sources within the structure is to be printed.

...

further arguments passed to terms.

Details

It is envisaged that the projectors in the list supplied to the projectors argument correspond to the terms in a linear model. One way to generate them is to obtain the design matrix X for a term and then calculate its projector as X(X'X)^-X', There are three methods available for orhtogonalizing the supplied projectors: differencing, eigenmethods or the default hybrid method.

Differencing relies on comparing the factors involved in two terms, one previous to the other, to identify whether to subtract the orthogonalized projector for the previous term from the primary projector of the other. It does so if factors/variables for the previous term are a subset of the factors/variablesfor for the other term. This relies on ensuring that all projectors whose factors/variables are a subset of the current projector occur before it in the expanded formula. It is checked that the set of matrices are mutually orthogonal. If they are not then a warning is given. It may happen that differencing does not produce a projector, in which case eigenmethods must be used.

Eigenmethods forces each projector to be orthogonal to all terms previous to it in the expanded formula. It uses equation 4.10 of James and Wilkinson (1971), which involves calculating the canonical efficiency factors for pairs of primary projectors. It produces a table of efficiency criteria for partially aliased terms. Again, the order of terms is crucial. This method has the disadvantage that the marginality of terms is not determined and so sources names are set to be the same as the term names, unless a marginality matrix is supplied.

The hybrid method is the most general and uses the relationships between the projection operators for the terms in the formula to decide which projectors to subtract and which to orthogonalize using eigenmethods. If Q_i and Q_j are two projectors for two different terms, with i < j, then

  1. if Q_j Q_i != 0 then have to orthogonalize Q_j to Q_i.

  2. if Q_j Q_i = Q_j then, if Q_i = Q_j, they are equal and Q_j will be removed from the list of terms; otherwise they are marginal and Q_i is subtracted from Q_j.

  3. if have to orthogonalize and Q_j Q_i = Q_i then Q_j is aliased with previous terms and will be removed from the list of terms; otherwise Q_i is partially aliased with Q_j and Q_j is orthogonalized to Q_i using eigenmethods.

The order of projections matrices in the list is crucial in this process.

Of the three methods, eigenmethods is least likely to fail, but it does not establish the marginality between the terms. It is often needed when there is nonorthogonality between terms, such as when there are several linear covariates. It can also be more efficeint in these circumstances.

The process can be computationally expensive, particularly for a large data set (500 or more observations) and/or when many terms are to be orthogonalized.

If the error Matrix is not idempotent should occur then, especially if there are many terms, one might try using set.daeTolerance to reduce the tolerance used in determining if values are either the same or are zero; it may be necessary to lower the tolerance to as low as 0.001. Also, setting orthogonalize to eigenmethods is worth a try.

Value

A pstructure.object.

Author(s)

Chris Brien

References

James, A. T. and Wilkinson, G. N. (1971) Factorization of the residual operator and canonical decomposition of nonorthogonal factors in the analysis of variance. Biometrika, 58, 279-294.

See Also

pstructure.formula, proj2.efficiency, proj2.combine, proj2.eigen,
projs.2canon in package dae, eigen.

projector for further information about this class.

Examples

## PBIBD(2) from p. 379 of Cochran and Cox (1957) Experimental Designs. 
## 2nd edn Wiley, New York
PBIBD2.unit <- list(Block = 6, Unit = 4)
PBIBD2.nest <- list(Unit = "Block")
trt <- factor(c(1,4,2,5, 2,5,3,6, 3,6,1,4, 4,1,5,2, 5,2,6,3, 6,3,4,1))
PBIBD2.lay <- designRandomize(allocated = trt, 
                              recipient = PBIBD2.unit, 
                              nested.recipients = PBIBD2.nest)
## manually obtain projectors for units
Q.G <- projector(matrix(1, nrow=24, ncol=24)/24)                         
Q.B <- projector(fac.meanop(PBIBD2.lay$Block))
Q.BU <- projector(diag(1, nrow=24))

## manually obtain projector for trt
Q.T <- projector(fac.meanop(PBIBD2.lay$trt) - Q.G)

##Orthogonalize the projectors using porthogonalize.list
Qs <- list(Mean = Q.G, Block = Q.B, "Block:Unit" = Q.BU)
struct <- porthogonalize(Qs, grandMean = TRUE)
Qs <- struct$Q
(lapply(Qs, degfree))

#Add a linear covariate
PBIBD2.lay <- within(PBIBD2.lay,
                     {
                       cBlock <- as.numfac(Block)
                       cBlock <- cBlock - mean(unique(cBlock))
                     })
X <- model.matrix(~ cBlock, data = PBIBD2.lay)
Q.cB <- projector(X %*% mat.ginv(t(X) %*% X) %*% t(X))
Qs <- list(cBlock = Q.cB, Block = Q.B, "Block:Unit" = Q.BU)
struct <- porthogonalize(Qs, grandMean = FALSE)
Qs <- struct$Q
(lapply(Qs, degfree))