Skip to contents

Predict the projection of new individuals/rows or variables/columns.

Usage

# S4 method for CA
predict(object, newdata, margin = 1)

# S4 method for PCA
predict(object, newdata, margin = 1)

Arguments

object

A CA or PCA object.

newdata

An object of supplementary points coercible to a matrix for which to compute principal coordinates.

margin

A length-one numeric vector giving the subscript which the data will be predicted: 1 indicates individuals/rows (the default), 2 indicates variables/columns.

Value

A data.frame of coordinates.

See also

Other multivariate analysis: ca(), pca()

Author

N. Frerebeau

Examples

## Create a matrix
A <- matrix(data = sample(1:10, 100, TRUE), nrow = 10, ncol = 10)

## Compute correspondence analysis
X <- ca(A, sup_row = 8:10, sup_col = 7:10)

## Predict new row coordinates
Y <- matrix(data = sample(1:10, 120, TRUE), nrow = 20, ncol = 6)
predict(X, Y, margin = 1)
#>             F1          F2            F3           F4           F5
#> 1   0.26537515  0.38952779  2.751045e-01  0.167021712  0.049673965
#> 2  -0.38291567  0.33192718 -1.039264e-01  0.065142897  0.471848665
#> 3   0.15909332 -0.04878874 -1.269940e-01 -0.108145112 -0.438485457
#> 4   0.05056052 -0.34561213  3.684817e-01 -0.078266078  0.160237440
#> 5   0.16147773  0.17479993 -2.240285e-01  0.187752867  0.272329800
#> 6   0.24271123 -0.01922505  6.457606e-02 -0.031903837  0.243817930
#> 7   0.11272592 -0.14108534 -6.843560e-02  0.101192259  0.019921941
#> 8   0.11223811 -0.17476258  3.999361e-01  0.146547913  0.214472276
#> 9   0.23501076 -0.37402172 -1.954058e-02 -0.144174562  0.105560307
#> 10  0.09097496 -0.01123157 -1.349008e-01  0.170939040  0.304515395
#> 11 -0.25491128 -0.21491700  4.821574e-02 -0.078303279  0.060933216
#> 12 -0.29091205  0.34312319 -7.651157e-02  0.103141965  0.064829965
#> 13  0.18337746  0.19106609 -3.035282e-01  0.215603429 -0.016524652
#> 14  0.13891584 -0.15740085  1.671563e-01  0.137558763 -0.094471189
#> 15  0.13387375 -0.04014952 -2.802286e-01  0.058294624  0.151286392
#> 16  0.07708776  0.19054102 -4.544388e-03 -0.129302375  0.004684898
#> 17  0.04673067 -0.84971022  4.697247e-07  0.093779535 -0.055205889
#> 18  0.29831486 -0.01697459 -1.296309e-01  0.003600986 -0.257760536
#> 19  0.05958225  0.07827655  7.493912e-02  0.043425215  0.141321539
#> 20  0.08995072  0.04284973  7.633691e-02 -0.138832146  0.339980548

## Predict new column coordinates
Z <- matrix(data = sample(1:10, 140, TRUE), nrow = 7, ncol = 20)
predict(X, Z, margin = 2)
#>              F1           F2            F3           F4          F5
#> 1  -0.165843046  0.321194530 -2.367059e-01 -0.302586631 -0.01050897
#> 2  -0.085467558  0.209230395  3.678932e-01 -0.028892103 -0.11460931
#> 3   0.657830755  0.169253264 -1.765485e-01  0.007804920  0.24959723
#> 4  -0.162325449 -0.151375438  7.566869e-02  0.030984111 -0.25788431
#> 5   0.294629965  0.326479300  2.540340e-01  0.076753113 -0.34572497
#> 6  -0.155923698  0.140083433 -7.114223e-02 -0.116372335 -0.23237200
#> 7  -0.492429945  0.237445670 -3.526466e-01 -0.123618240  0.24999753
#> 8   0.009631388 -0.209424920  2.392178e-01  0.037897695  0.00493662
#> 9   0.268489565  0.171238699  1.754170e-01 -0.071244813  0.45842796
#> 10 -0.087724092 -0.134932270 -3.373045e-02 -0.121169930 -0.02807452
#> 11  0.141758640  0.116210684  2.228880e-01 -0.192868519  0.18100529
#> 12  0.209469356  0.105863036  4.960747e-01  0.327834512 -0.39497794
#> 13  0.180260372  0.356719587  2.660949e-01 -0.003751829 -0.43912968
#> 14  0.369791034  0.006009517  6.585158e-02 -0.164572233 -0.31487156
#> 15 -0.207165492 -0.102954464  2.907125e-01 -0.160161163 -0.28668019
#> 16 -0.063899351  0.083442616  6.460950e-02  0.105433554 -0.59042893
#> 17 -0.208543345 -0.063038148  2.399970e-01  0.201234201 -0.57971339
#> 18  0.315334342 -0.081623585  4.800067e-01 -0.023590763 -0.15593569
#> 19 -0.032083868 -0.094410193  8.384391e-05  0.039105374  0.30792365
#> 20 -0.345183752  0.125995270 -1.883245e-01 -0.342679782 -0.03609059