Become an expert in R — Interactive courses, Cheat Sheets, certificates and more!
Get Started for Free

pc1

First Principal Component


Description

Given a numeric matrix which may or may not contain NAs, pc1 standardizes the columns to have mean 0 and variance 1 and computes the first principal component using prcomp. The proportion of variance explained by this component is printed, and so are the coefficients of the original (not scaled) variables. These coefficients may be applied to the raw data to obtain the first PC.

Usage

pc1(x, hi)

Arguments

x

numeric matrix

hi

if specified, the first PC is scaled so that its maximum value is hi and its minimum value is zero

Value

The vector of observations with the first PC. An attribute "coef" is attached to this vector. "coef" contains the raw-variable coefficients.

Author(s)

Frank Harrell

See Also

Examples

set.seed(1)
x1 <- rnorm(100)
x2 <- x1 + rnorm(100)
w <- pc1(cbind(x1,x2))
attr(w,'coef')

Hmisc

Harrell Miscellaneous

v4.5-0
GPL (>= 2)
Authors
Frank E Harrell Jr <fh@fharrell.com>, with contributions from Charles Dupont and many others.
Initial release
2021-02-27

We don't support your browser anymore

Please choose more modern alternatives, such as Google Chrome or Mozilla Firefox.