princomp                 package:mva                 R Documentation

_P_r_i_n_c_i_p_a_l _C_o_m_p_o_n_e_n_t_s _A_n_a_l_y_s_i_s

_D_e_s_c_r_i_p_t_i_o_n:

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

_U_s_a_g_e:

     princomp(x, data = NULL, subset, na.action, ...)
     princomp(x, cor = FALSE, scores = TRUE, covmat = NULL,
              subset = rep(TRUE, nrow(as.matrix(x))), ...)

_A_r_g_u_m_e_n_t_s:

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

    data: an optional data frame containing the variables in the
          formula `x'. By default the variables are taken from
          `environment(x)'.

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

na.action: a function which indicates what should happen when the data
          contain `NA's.  The default is set by the `na.action' setting
          of `options', and is `na.fail' if that is unset. The
          ``factory-fresh'' default is `na.omit'.

     cor: a logical value indicating whether the calculation should use
          the correlation matrix or the covariance matrix.

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

  covmat: a covariance matrix, or a covariance list as returned by
          `cov.wt', `cov.mve' or `cov.mcd'. If supplied, this is used
          rather than the covariance matrix of `x'.

     ...: arguments passed to or from other methods. If `x' is a
          formula one might specify `cor' or `scores'.

_D_e_t_a_i_l_s:

     `princomp' is a generic function with `"formula"' and `"default"'
     methods.

     The calculation is done using `eigen' on the correlation or
     covariance matrix, as determined by `cor'.  This is done for
     compatibility with the S-PLUS result.  A preferred method of
     calculation is to use svd on `x', as is done in `prcomp'.

     Note that the default calculation uses divisor `N' for the
     covariance matrix.

     The `print' method for the these objects prints the results in a
     nice format and the `plot' method produces a scree plot
     (`screeplot').  There is also a `biplot' method.

     If `x' is a formula then the standard NA-handling is applied to
     the scores (if requested): see `napredict'.

_V_a_l_u_e:

     `princomp' returns a list with class `"princomp"' containing the
     following components: 

    sdev: the standard deviations of the principal components.

loadings: the matrix of variable loadings (i.e., a matrix whose columns
          contain the eigenvectors).  This is of class `"loadings"':
          see `loadings' for its `print' method.

  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.

na.action: If relevant.

_R_e_f_e_r_e_n_c_e_s:

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

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

_S_e_e _A_l_s_o:

     `summary.princomp', `screeplot', `biplot.princomp', `prcomp',
     `cor', `cov', `eigen'.

_E_x_a_m_p_l_e_s:

     ## The variances of the variables in the
     ## USArrests data vary by orders of magnitude, so scaling is appropriate
     data(USArrests)
     (pc.cr <- princomp(USArrests))  # inappropriate
     princomp(USArrests, cor = TRUE) # =^= prcomp(USArrests, scale=TRUE)
     ## Similar, but different:
     ## The standard deviations differ by a factor of sqrt(49/50)

     summary(pc.cr <- princomp(USArrests, cor = TRUE))
     loadings(pc.cr)  ## note that blank entries are small but not zero
     plot(pc.cr) # shows a screeplot.
     biplot(pc.cr)

     ## Formula interface
     princomp(~ ., data = USArrests, cor = TRUE)
     # NA-handling
     USArrests[1, 2] <- NA
     pc.cr <- princomp(~ ., data = USArrests, na.action=na.exclude, cor = TRUE)
     pc.cr$scores

