Learn R Programming

performance (version 0.1.0)

principal_components: Principal Components Analysis

Description

This function performs a principal component analysis and returns the loadings (of the unrotated matrix) as data frame, or returns a rotated matrix of the loadings (if rotation is not NULL).

Usage

principal_components(x, rotation = NULL, n_comp = NULL)

Arguments

x

A data frame or a prcomp-object.

rotation

Rotation of the factor loadings. May be one of "varimax", "quartimax", "promax", "oblimin", "simplimax", "cluster" or "none". If rotatoin = NULL, loadings for the principal components from the unrotated matrix are returned.

n_comp

Number of components to extract. If rotation = "varmiax" and n_comp = NULL, number of components is based on the Kaiser-criteria.

Value

If rotation = NULL, a data frame with all loadings of principal components. Else, a rotated loadings matrix, as data frame. Details on the variance components are saved as attributes.

Details

The print()-method has a cutoff-argument, which is a scalar between 0 and 1, indicating which (absolute) values from the rotated loadings (i.e. when rotation is not NULL) should be blank in the output. By default, all loadings between -.1 and .1 are not shown.

Examples

Run this code
# NOT RUN {
data(iris)
principal_components(iris[, 1:4])

data(iris)
principal_components(iris[, 1:4], rotation = "varimax", n_comp = 2)

pr <- principal_components(iris[, 1:4], rotation = "varimax", n_comp = 2)

# show all
print(pr, cutoff = .001)

# show only some
print(pr, cutoff = .5)

# }

Run the code above in your browser using DataLab