Description Usage Arguments Details Value Author(s) See Also Examples

These functions reverse the outcome of the `predict`

function
when the class of the first argument is either `prcomp`

or `princomp`

.
These functions are used to transform data where the variables are principal components of a dataset
of original variables, given the `object`

.

1 2 3 | ```
backPredict(object, newdata)
backPredictVar(object, new.vardata, only.var = TRUE)
``` |

`object` |
Object of class inheriting from |

`newdata` |
A matrix of principal components which is to be converted back to the original output variables.
An important feature here is that |

`new.vardata` |
A matrix of variances where each column represents the variances of one principal component's prediction for many observations, and each row represents the variances of multiple principal components of one observation. |

`only.var` |
This parameter lets the user choose how the output of the function |

`backPredict`

defines a function to reverse the outcome of the `predict.prcomp`

or `predict.princomp`

function.
It is used to transform data (typically values predicted using regressions) where the variables are principal components of a dataset of original variables, given in the `object`

.

`backPredictVar`

defines a similar function to reverse the outcome of the `predict.prcomp`

or `predict.princomp`

function.
It is used to transform data that represents variances of principal components of an original dataset given in the `object`

.
It uses the linear variance transformation property.

`backPredict`

returns a matrix of data in terms of the original output variables.

`backPredictVar`

returns a matrix of variances (and covariances if `only.var = FALSE`

) of each observation with the original output variable

Sajni Malde

`princomp`

, `prcomp`

, `predict.prcomp`

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 | ```
library(mvtnorm)
#defining data
Sigma <- matrix(c(10.3, 3.6,3.6,2.4),2,2)
out <- rmvnorm(n=100000, c(1.2,2.4), Sigma); colnames(out) <- c('Y1', 'Y2')
cov(out)
new.out <- rmvnorm(n=100000, c(1.2,2.4), Sigma); colnames(new.out) <- c('Y1', 'Y2')
# using the 'princomp' function to convert the data
out.pca <- princomp(out) # converting the data to principal components
# predicting principal components for a new data set
new.out.pca<- predict(out.pca, new.out)
# applying backPredict and comparing values
backpredict <- backPredict(out.pca, new.out.pca)
head(backpredict) # should be quite similar to head(new.out)
# reducing the dimensions # only 1 components used to 'backPredict'
backpredict2 <- backPredict(out.pca, new.out.pca[, 1, drop = FALSE])
# applying backPredictVar and comparing values
# check to see if assuming off diagonals are equal to zero is a reasonable assumption
cov(new.out.pca)
(backpredict.var <- backPredictVar(out.pca, new.vardata = matrix(diag(cov(new.out.pca)),
ncol = 2), only.var = FALSE)[1,,])
# backpredict.var should be very close to cov(out)
``` |

Embedding an R snippet on your website

Add the following code to your website.

For more information on customizing the embed code, read Embedding Snippets.