pca_warper | R Documentation |
This function generates a warper
object based on a principal component
analysis of the features (or more precisely, of selected features xvars
).
pca_warper(
xdata,
xvars,
wvars = "PC",
yvar,
uvars = NULL,
center = TRUE,
scale = TRUE,
positive = TRUE,
title = wvars
)
xdata |
A data frame containing the observations in the original feature space. |
xvars |
A character vector with the column names of features in |
wvars |
A character vector with the names of all transformed predictors, or (more often) a simple character string to which the numbers 1, ... will be appended as needed. |
yvar |
Name of the response variable (not to be transformed) |
uvars |
Names of additional variables that should remain untouched. |
scale, center |
Logical arguments indicating whether the data should
be centered and then scales. Both should be turned on ( |
positive |
Logical argument (default: |
title |
Optional name of the transformation, may be used for printing summaries or for plotting. |
There should be no overlap
between xvars
, uvars
and yvar
.
The rotation matrix $full_rotation
in the results object
is of size length(xvars)+length(uvars)
and includes an
identity transformation diag(length(uvars))
for the
features in uvars
.
An object of class warper
, rotation_warper
and pca_warper
.
### Create principal components warper for Maipo data set:
xvars <- c(paste("ndvi0", 1:8, sep = ""), paste("ndwi0", 1:8, sep = ""),
paste("b", outer(1:8,2:7,paste,sep = ""), sep = ""))
fo <- as.formula(paste("class ~", paste(xvars, collapse=" +" )))
d <- maipofields
wrp <- pca_warper(d, xvars = xvars, yvar = "class")
plot(wrp)
round(wrp$pca$rotation[,1:3], digits = 2)
summary(wrp)
# Create a data frame with transformed data:
wd <- warp(d, warper = wrp)
summary(wd)
# Backtransform it, should be identical to d:
d2 <- unwarp(wd, warper = wrp)
all.equal(d, d2[,colnames(d)])
# Default tolerance works for this data set, but you may have to use
# e.g. tol = 10^(-6) for less well conditioned data sets and
# transformations.
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.