R/methods-stats-princomp.r
methods-princomp.Rd
These methods extract data from, and attribute new data to,
objects of class "princomp"
as returned by stats::princomp()
.
# S3 method for princomp
as_tbl_ord(x)
# S3 method for princomp
recover_rows(x)
# S3 method for princomp
recover_cols(x)
# S3 method for princomp
recover_inertia(x)
# S3 method for princomp
recover_coord(x)
# S3 method for princomp
recover_conference(x)
# S3 method for princomp
recover_aug_rows(x)
# S3 method for princomp
recover_aug_cols(x)
# S3 method for princomp
recover_aug_coord(x)
An ordination object.
The recovery generics recover_*()
return core model components, distribution of inertia,
supplementary elements, and intrinsic metadata; but they require methods for each model class to
tell them what these components are.
The generic as_tbl_ord()
returns its input wrapped in the 'tbl_ord'
class. Its methods determine what model classes it is allowed to wrap. It
then provides 'tbl_ord' methods with access to the recoverers and hence to
the model components.
Other methods for singular value decomposition-based techniques:
methods-cancor
,
methods-correspondence
,
methods-lda
,
methods-lra
,
methods-mca
,
methods-prcomp
,
methods-svd
Other models from the stats package:
methods-cancor
,
methods-cmds
,
methods-factanal
,
methods-kmeans
,
methods-lm
,
methods-prcomp
# data frame of Anderson iris species measurements
class(iris)
#> [1] "data.frame"
head(iris)
#> Sepal.Length Sepal.Width Petal.Length Petal.Width Species
#> 1 5.1 3.5 1.4 0.2 setosa
#> 2 4.9 3.0 1.4 0.2 setosa
#> 3 4.7 3.2 1.3 0.2 setosa
#> 4 4.6 3.1 1.5 0.2 setosa
#> 5 5.0 3.6 1.4 0.2 setosa
#> 6 5.4 3.9 1.7 0.4 setosa
# compute unscaled row-principal components of scaled measurements
iris[, -5] %>%
princomp() %>%
as_tbl_ord() %>%
print() -> iris_pca
#> # A tbl_ord of class 'princomp': (150 x 4) x (4 x 4)'
#> # 4 coordinates: Comp.1, Comp.2, ..., Comp.4
#> #
#> # Rows (principal): [ 150 x 4 | 0 ]
#> Comp.1 Comp.2 Comp.3 ... |
#> |
#> 1 -2.68 0.319 0.0279 |
#> 2 -2.71 -0.177 0.210 ... |
#> 3 -2.89 -0.145 -0.0179 |
#> 4 -2.75 -0.318 -0.0316 |
#> 5 -2.73 0.327 -0.0901 |
#>
#> #
#> # Columns (standard): [ 4 x 4 | 0 ]
#> Comp.1 Comp.2 Comp.3 ... |
#> |
#> 1 0.361 0.657 0.582 |
#> 2 -0.0845 0.730 -0.598 ... |
#> 3 0.857 -0.173 -0.0762 |
#> 4 0.358 -0.0755 -0.546 |
# recover observation principal coordinates and measurement standard coordinates
head(get_rows(iris_pca))
#> Comp.1 Comp.2 Comp.3 Comp.4
#> [1,] -2.684126 0.3193972 0.02791483 0.002262437
#> [2,] -2.714142 -0.1770012 0.21046427 0.099026550
#> [3,] -2.888991 -0.1449494 -0.01790026 0.019968390
#> [4,] -2.745343 -0.3182990 -0.03155937 -0.075575817
#> [5,] -2.728717 0.3267545 -0.09007924 -0.061258593
#> [6,] -2.280860 0.7413304 -0.16867766 -0.024200858
get_cols(iris_pca)
#> Comp.1 Comp.2 Comp.3 Comp.4
#> Sepal.Length 0.36138659 0.65658877 0.58202985 0.3154872
#> Sepal.Width -0.08452251 0.73016143 -0.59791083 -0.3197231
#> Petal.Length 0.85667061 -0.17337266 -0.07623608 -0.4798390
#> Petal.Width 0.35828920 -0.07548102 -0.54583143 0.7536574
# augment measurement coordinates with names and scaling parameters
(iris_pca <- augment_ord(iris_pca))
#> # A tbl_ord of class 'princomp': (150 x 4) x (4 x 4)'
#> # 4 coordinates: Comp.1, Comp.2, ..., Comp.4
#> #
#> # Rows (principal): [ 150 x 4 | 0 ]
#> Comp.1 Comp.2 Comp.3 ... |
#> |
#> 1 -2.68 0.319 0.0279 |
#> 2 -2.71 -0.177 0.210 ... |
#> 3 -2.89 -0.145 -0.0179 |
#> 4 -2.75 -0.318 -0.0316 |
#> 5 -2.73 0.327 -0.0901 |
#>
#> #
#> # Columns (standard): [ 4 x 4 | 3 ]
#> Comp.1 Comp.2 Comp.3 ... | name center scale
#> | <chr> <dbl> <dbl>
#> 1 0.361 0.657 0.582 | 1 Sepal.Length 5.84 1
#> 2 -0.0845 0.730 -0.598 ... | 2 Sepal.Width 3.06 1
#> 3 0.857 -0.173 -0.0762 | 3 Petal.Length 3.76 1
#> 4 0.358 -0.0755 -0.546 | 4 Petal.Width 1.20 1