

   proj {base}                                  R Documentation

   PPrroojjeeccttiioonnss ooff MMooddeellss

   DDeessccrriippttiioonn::

        `proj' returns a matrix or list of matrices giving the
        projections of the data onto the terms of a linear
        model.  It is most frequently used for `aov' models.

   UUssaaggee::

        proj       (object, ...)
        proj.aov    (object, onedf = FALSE, unweighted.scale = FALSE)
        proj.aovlist(object, onedf = FALSE, unweighted.scale = FALSE)
        proj.default(object, onedf = TRUE, ...)
        proj.lm     (object, onedf = FALSE, unweighted.scale = FALSE)

   AArrgguummeennttss::

     object: An object of class `"lm"' or a class inheriting
             from it, or an object with a similar structure
             including in particular components `qr' and
             `effects'.

      onedf: A logical flag. If `TRUE', a projection is
             returned for all the columns of the model matrix.
             If `FALSE', the single-column projections are col-
             lapsed by terms of the model (as represented in
             the analysis of variance table).

   unweighted.scale: If the fit producing `object' used
             weights, this determines if the projections corre-
             spond to weighted or unweighted observations.

        ...: Swallow and ignore any other arguments.

   DDeettaaiillss::

        A projection is given for each stratum of the object,
        so for `aov' models with an `Error' term the result is
        a list of projections.

   VVaalluuee::

        A projection matrix or (for multi-stratum objects) a
        list of projection matrices.

        Each projection is a matrix with a row for each obser-
        vations and either a column for each term (`onedf =
        FALSE') or for each coefficient (`onedf = TRUE'). Pro-
        jection matrices from the default method have orthogo-
        nal columns representing the projection of the response
        onto the column space of the Q matrix from the QR
        decomposition.  The fitted values are the sum of the
        projections, and the sum of squares for each column is
        the reduction in sum of squares from fitting that col-
        umn (after those to the left of it).

        The methods for `lm' and `aov' models add a column to
        the projection matrix giving the residuals (the projec-
        tion of the data onto the orthogonal complement of the
        model space).

        Strictly, when `onedf = FALSE' the result is not a pro-
        jection, but the columns represent sums of projections
        onto the columns of the model matrix corresponding to
        that term. In this case the matrix does not depend on
        the coding used.

   AAuutthhoorr((ss))::

        B.D. Ripley

   SSeeee AAllssoo::

        `aov', `lm', `model.tables'

   EExxaammpplleess::

        N <- c(0,1,0,1,1,1,0,0,0,1,1,0,1,1,0,0,1,0,1,0,1,1,0,0)
        P <- c(1,1,0,0,0,1,0,1,1,1,0,0,0,1,0,1,1,0,0,1,0,1,1,0)
        K <- c(1,0,0,1,0,1,1,0,0,1,0,1,0,1,1,0,0,0,1,1,1,0,1,0)
        yield <- c(49.5,62.8,46.8,57.0,59.8,58.5,55.5,56.0,62.8,55.8,69.5,
        55.0, 62.0,48.8,45.5,44.2,52.0,51.5,49.8,48.8,57.2,59.0,53.2,56.0)

        npk <- data.frame(block=gl(6,4), N=factor(N), P=factor(P),
                          K=factor(K), yield=yield)
        npk.aov <- aov(yield ~ block + N*P*K, npk)
        proj(npk.aov)

        ## as a test, not particularly sensible
        options(contrasts=c("contr.helmert", "contr.treatment"))
        npk.aovE <- aov(yield ~  N*P*K + Error(block), npk)
        proj(npk.aovE)

