| predict.princomp.BData | R Documentation |
Projects new distributional data onto the principal component space defined by a fitted PCA model. This allows new distributions to be positioned relative to the original dataset without re-running the entire PCA.
## S3 method for class 'princomp.BData'
predict(object, newdata, ...)
object |
A 'princomp.BData' object containing the fitted PCA model. |
newdata |
A BData object containing the new distributions to project. Can be any BData subclass; it will be converted to splines using the same basis as the original PCA. |
... |
Additional arguments (currently unused). |
The prediction process:
Converts 'newdata' to spline coefficients using the same basis as the original PCA.
**For non-orthonormal bases:** Applies the same Gram matrix transformation
that was used during fitting (see princomp.BData details).
Centers the (transformed) coefficients using the center from the original PCA.
Projects the centered coefficients onto the loading vectors to obtain scores.
The resulting scores can be compared directly to the scores from the original analysis. New observations with scores similar to original observations have similar distribution shapes.
**Note:** For non-orthonormal bases, the function automatically applies the same transformation that was used during fitting. This ensures consistency between training and prediction.
A matrix of principal component scores with observations in rows and components in columns. Each row contains the coordinates of one new distribution in the PC space.
Matthias Templ
princomp.BData for fitting the PCA model.
plot.princomp.BData with 'type="scores"' for visualizing scores.
Other PCA:
biplot.princomp.BData(),
plot.princomp.BData(),
plot.princomp.BData.grouped(),
plot.princomp.BData.multivariate(),
princomp.BData(),
screeplot.princomp.BData(),
summary.princomp.BData()
## Fit PCA on training data
meanDist <- BDataPDFs(list(dunif), basis = B2Unif01Basis7)
gaussProc <- B2GaussianDistribution(meanDist, function(x,y) exp(-4*abs(x-y)^1.7))
trainData <- as.BDataSplines(simulate(gaussProc, 30, seed = 42))
pcaModel <- princomp(trainData)
## Generate new data and predict scores
newData <- as.BDataSplines(simulate(gaussProc, 5, seed = 999))
newScores <- predict(pcaModel, newData)
print(newScores)
## Compare: new observations vs training data
trainScores <- pcaModel$scores
plot(trainScores[,1], trainScores[,2], pch = 19, col = "gray50",
xlab = "PC1", ylab = "PC2", main = "Training (gray) vs New (red)")
points(newScores[,1], newScores[,2], pch = 17, col = "red", cex = 1.5)
legend("topright", c("Training", "New"), pch = c(19, 17),
col = c("gray50", "red"))
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.