

   princomp {mva}                               R Documentation

   PPrriinncciippaall CCoommppoonneennttss AAnnaallyyssiiss

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

        `princomp' performs a principal components analysis on
        the given data matrix and returns the results as an
        object of class `princomp'.

        `loadings' extracts the loadings.

        `screeplot' plots the variances against the number of
        the principal component. This is also the `plot'
        method.

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

        princomp(x, cor = FALSE, scores = TRUE,
                 subset = rep(TRUE, nrow(as.matrix(x))))
        loadings(x)
        plot(x, npcs = min(10, length(x$sdev)),
                  type = c("barplot", "lines"), ...)
        screeplot(x, npcs = min(10, length(x$sdev)),
                  type = c("barplot", "lines"), ...)

        print(x,...)  summary(object)  predict(object,...)

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

          x: a matrix (or data frame) which provides the data
             for the principal components analysis.

        cor: a logical value indicating whether the calculation
             should use the correlation matrix or the covari-
             ance matrix.

      score: a logical value indicating whether the score on
             each principal component should be calculated.

     subset: a vector used to select rows (observations) of the
             data matrix `x'.

   x, object: an object of class `"princomp"', as from `prin-
             comp()'.

       npcs: the number of principal components to be plotted.

       type: the type of plot.

        ...: graphics parameters.

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

        The calculation is done using `eigen' on the correla-
        tion or covariance matrix, as determined by `cor'.
        This is done for compatibility with the S-PLUS result
        (even though alternate forms for `x'-e.g., a covariance
        matrix-are not supported as they are in S-PLUS).  A
        preferred method of calculation is to use svd on `x',
        as is done in `prcomp'.

        Note that the scaling of results is affected by the
        setting of `cor'.  If `cor' is `TRUE' then the divisor
        in the calculation of the sdev is N-1, otherwise it is
        N.  This has the effect that the result is slightly
        different depending on whether scaling is done first on
        the data and cor set to `FALSE', or done automatically
        in `princomp' with `cor = TRUE'.

        The `print' method for the these objects prints the
        results in a nice format and the `plot' method produces
        a scree plot.

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

        `princomp' returns a list with class `"princomp"' con-
        taining the following components:

       sdev: the standard deviations of the principal compo-
             nents (i.e., the square roots of the eigenvalues,
             rescaled by `(N-1)/N')

   loadings: the matrix of variable loadings (i.e., a matrix
             whose columns contain the eigenvectors).

     center: the means that were subtracted.

      scale: the scalings applied to each variable.

      n.obs: the number of observations.

     scores: if `scores = TRUE', the scores of the supplied
             data on the principal components.

       call: the matched call.

   RReeffeerreenncceess::

        Mardia, K. V., J. T. Kent and J. M. Bibby (1979).  Mul-
        tivariate Analysis, London: Academic Press.

        Venables, W. N. and B. D. Ripley (1997, 9).  Modern
        Applied Statistics with S-PLUS, Springer-Verlag.

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

        `prcomp', `cor', `cov', `eigen'.

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

        ## the variances of the variables in the
        ## USArrests data vary by orders of magnitude
        data(USArrests)
        (pc.cr <- princomp(USArrests))
        princomp(USArrests, cor = TRUE)
        princomp(scale(USArrests, scale = TRUE, center = TRUE), cor = FALSE)

        summary(pc.cr <- princomp(USArrests))
        loadings(pc.cr)
        plot(pc.cr) # does a screeplot.
        biplot(pc.cr)

