This is a convenience function to fit an ordination model to a data object, wrap the result as a tbl_ord, and annotate this output with metadata from the model and possibly from the data.

ordinate(x, model, ...)

# Default S3 method
ordinate(x, model, ...)

# S3 method for class 'array'
ordinate(x, model, ...)

# S3 method for class 'table'
ordinate(x, model, ...)

# S3 method for class 'data.frame'
ordinate(x, model, cols, augment, ...)

# S3 method for class 'dist'
ordinate(x, model, ...)

Arguments

x

A data object to be passed to the model, such as an array, table, data.frame, or stats::dist.

model

An ordination function whose output is coercible to class 'tbl_ord', or a symbol or character string (handled by match.fun()). Alternatively, a formula ~ fun(., ...) where fun is such a function and other arguments are explicit, which will be evaluated with x in place of ..

...

Additional arguments passed to model.

cols

<tidy-select> If x is a data frame, columns to pass to model. If missing, all columns are used.

augment

<tidy-select> If x is a data frame, columns to augment to the row data of the ordination. If missing, all columns not included in cols will be augmented.

Value

An augmented tbl_ord.

Details

The default method fits the specified model to the provided data object, wraps the result as a tbl_ord, and augments this output with any intrinsic metadata from the model via augment_ord().

The default method is used for most classes, though this may change in future. The data.frame method allows the user to specify what columns to include in the model and what columns with which to annotate the output.

Examples

# LRA of arrest data
ordinate(USArrests, cols = c(Murder, Rape, Assault), lra)
#> # A tbl_ord of class 'lra': (50 x 2) x (3 x 2)'
#> # 2 coordinates: LRSV1 and LRSV2
#> # 
#> # Rows (standard): [ 50 x 2 | 3 ]
#>    LRSV1  LRSV2 |   name       weight UrbanPop
#>                 |   <chr>       <dbl>    <int>
#> 1 -0.680  0.930 | 1 Alabama    0.0271       58
#> 2  0.930 -0.625 | 2 Alaska     0.0318       48
#> 3 -0.330 -1.31  | 3 Arizona    0.0333       80
#> 4 -0.351  0.277 | 4 Arkansas   0.0219       50
#> 5  0.552 -1.00  | 5 California 0.0326       91
#> # ℹ 45 more rows
#> # 
#> # Columns (standard): [ 3 x 2 | 2 ]
#>    LRSV1  LRSV2 |   name    weight
#>                 |   <chr>    <dbl>
#> 1  0.283  4.96  | 1 Murder  0.0390
#> 2  2.88  -0.366 | 2 Rape    0.106 
#> 3 -0.371 -0.181 | 3 Assault 0.855 

# CMDS of inter-city distance data
ordinate(UScitiesD, cmdscale_ord, k = 3L)
#> # A tbl_ord of class 'cmds_ord': (10 x 3) x (10 x 3)'
#> # 3 coordinates: PCo1, PCo2, PCo3
#> # 
#> # Rows (symmetric): [ 10 x 3 | 1 ]
#>      PCo1   PCo2   PCo3 |    name         
#>                         |    <chr>        
#>  1  -719.  143.  -35.1  |  1 Atlanta      
#>  2  -382. -341.  -29.6  |  2 Chicago      
#>  3   482.  -25.3 -53.4  |  3 Denver       
#>  4  -161.  573.   -1.45 |  4 Houston      
#>  5  1204.  390.   18.6  |  5 LosAngeles   
#>  6 -1134.  582.   32.3  |  6 Miami        
#>  7 -1072. -519.   34.3  |  7 NewYork      
#>  8  1421.  113.    7.75 |  8 SanFrancisco 
#>  9  1342. -580.   23.7  |  9 Seattle      
#> 10  -980. -335.    2.90 | 10 Washington.DC
#> # 
#> # Columns (symmetric): [ 10 x 3 | 1 ]
#>      PCo1   PCo2   PCo3 |    name         
#>                         |    <chr>        
#>  1  -719.  143.  -35.1  |  1 Atlanta      
#>  2  -382. -341.  -29.6  |  2 Chicago      
#>  3   482.  -25.3 -53.4  |  3 Denver       
#>  4  -161.  573.   -1.45 |  4 Houston      
#>  5  1204.  390.   18.6  |  5 LosAngeles   
#>  6 -1134.  582.   32.3  |  6 Miami        
#>  7 -1072. -519.   34.3  |  7 NewYork      
#>  8  1421.  113.    7.75 |  8 SanFrancisco 
#>  9  1342. -580.   23.7  |  9 Seattle      
#> 10  -980. -335.    2.90 | 10 Washington.DC

# PCA of iris data
ordinate(iris, princomp, cols = -Species, augment = c(Sepal.Width, Species))
#> # 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 | 3 ]
#>   Comp.1 Comp.2  Comp.3 ... |   .element Sepal.Width Species
#>                             |   <chr>          <dbl> <fct>  
#> 1  -2.68  0.319  0.0279     | 1 score            3.5 setosa 
#> 2  -2.71 -0.177  0.210  ... | 2 score            3   setosa 
#> 3  -2.89 -0.145 -0.0179     | 3 score            3.2 setosa 
#> 4  -2.75 -0.318 -0.0316     | 4 score            3.1 setosa 
#> 5  -2.73  0.327 -0.0901     | 5 score            3.6 setosa 
#> # ℹ 145 more rows
#> # 
#> # Columns (standard): [ 4 x 4 | 4 ]
#>    Comp.1  Comp.2  Comp.3 ... |   name         center scale .element
#>                               |   <chr>         <dbl> <dbl> <chr>   
#> 1  0.361   0.657   0.582      | 1 Sepal.Length   5.84     1 active  
#> 2 -0.0845  0.730  -0.598  ... | 2 Sepal.Width    3.06     1 active  
#> 3  0.857  -0.173  -0.0762     | 3 Petal.Length   3.76     1 active  
#> 4  0.358  -0.0755 -0.546      | 4 Petal.Width    1.20     1 active  
ordinate(iris, cols = 1:4, ~ prcomp(., center = TRUE, scale. = TRUE))
#> # A tbl_ord of class 'prcomp': (150 x 4) x (4 x 4)'
#> # 4 coordinates: PC1, PC2, ..., PC4
#> # 
#> # Rows (principal): [ 150 x 4 | 1 ]
#>     PC1    PC2     PC3 ... |   Species
#>                            |   <fct>  
#> 1 -2.26 -0.478  0.127      | 1 setosa 
#> 2 -2.07  0.672  0.234  ... | 2 setosa 
#> 3 -2.36  0.341 -0.0441     | 3 setosa 
#> 4 -2.29  0.595 -0.0910     | 4 setosa 
#> 5 -2.38 -0.645 -0.0157     | 5 setosa 
#> # ℹ 145 more rows
#> # 
#> # Columns (standard): [ 4 x 4 | 3 ]
#>      PC1     PC2    PC3 ... |   name         center scale
#>                             |   <chr>         <dbl> <dbl>
#> 1  0.521 -0.377   0.720     | 1 Sepal.Length   5.84 0.828
#> 2 -0.269 -0.923  -0.244 ... | 2 Sepal.Width    3.06 0.436
#> 3  0.580 -0.0245 -0.142     | 3 Petal.Length   3.76 1.77 
#> 4  0.565 -0.0669 -0.634     | 4 Petal.Width    1.20 0.762

# CA of hair & eye color data
haireye <- as.data.frame(rowSums(HairEyeColor, dims = 2L))
ordinate(haireye, MASS::corresp, cols = everything())
#> # A tbl_ord of class 'correspondence': (4 x 1) x (4 x 1)'
#> # 1 coordinate: Can1
#> # 
#> # Rows (standard): [ 4 x 1 | 1 ]
#>     Can1 |   name 
#>          |   <chr>
#> 1 -1.10  | 1 Black
#> 2 -0.324 | 2 Brown
#> 3 -0.283 | 3 Red  
#> 4  1.83  | 4 Blond
#> # 
#> # Columns (standard): [ 4 x 1 | 1 ]
#>     Can1 |   name 
#>          |   <chr>
#> 1 -1.08  | 1 Brown
#> 2  1.20  | 2 Blue 
#> 3 -0.465 | 3 Hazel
#> 4  0.354 | 4 Green

# FA of Swiss social data
ordinate(swiss, model = factanal, factors = 2L, scores = "Bartlett")
#> # A tbl_ord of class 'factanal': (53 x 2) x (6 x 2)'
#> # 2 coordinates: Factor1 and Factor2
#> # 
#> # Rows (symmetric): [ 53 x 2 | 2 ]
#>   Factor1 Factor2 |   name        .element
#>                   |   <chr>       <chr>   
#> 1  -0.652  0.393  | 1 Fertility   active  
#> 2  -0.631  0.333  | 2 Agriculture active  
#> 3   0.685 -0.510  | 3 Examination active  
#> 4   0.997 -0.0313 | 4 Education   active  
#> 5  -0.124  0.961  | 5 Catholic    active  
#> # ℹ 48 more rows
#> # 
#> # Columns (symmetric): [ 6 x 2 | 3 ]
#>   Factor1 Factor2 |   name           uniqueness .element
#>                   |   <chr>               <dbl> <chr>   
#> 1 -0.652   0.393  | 1 Fertility          0.420  active  
#> 2 -0.631   0.333  | 2 Agriculture        0.492  active  
#> 3  0.685  -0.510  | 3 Examination        0.270  active  
#> 4  0.997  -0.0313 | 4 Education          0.005  active  
#> 5 -0.124   0.961  | 5 Catholic           0.0607 active  
#> 6 -0.0947  0.175  | 6 Infant.Mortal…     0.960  active  

# LDA of iris data
ordinate(iris, ~ lda_ord(.[, 1:4], .[, 5], ret.x = TRUE))
#> # A tbl_ord of class 'lda_ord': (153 x 2) x (4 x 2)'
#> # 2 coordinates: LD1 and LD2
#> # 
#> # Rows (principal): [ 153 x 2 | 4 ]
#>     LD1    LD2 |   name        prior counts .element
#>                |   <chr>       <dbl>  <int> <chr>   
#> 1  7.61  0.215 | 1 setosa      0.333     50 active  
#> 2 -1.83 -0.728 | 2 versicolor  0.333     50 active  
#> 3 -5.78  0.513 | 3 virginica   0.333     50 active  
#> 4  8.06  0.300 | 4 NA         NA         NA score   
#> 5  7.13 -0.787 | 5 NA         NA         NA score   
#> # ℹ 148 more rows
#> # 
#> # Columns (standard): [ 4 x 2 | 2 ]
#>      LD1     LD2 |   name         .element
#>                  |   <chr>        <chr>   
#> 1  0.829  0.0241 | 1 Sepal.Length active  
#> 2  1.53   2.16   | 2 Sepal.Width  active  
#> 3 -2.20  -0.932  | 3 Petal.Length active  
#> 4 -2.81   2.84   | 4 Petal.Width  active  

# CCA of savings data
ordinate(
  LifeCycleSavings[, c("pop15", "pop75")],
  # second data set must be handled as an additional parameter to `model`
  y = LifeCycleSavings[, c("sr", "dpi", "ddpi")],
  model = cancor_ord, scores = TRUE
)
#> # A tbl_ord of class 'cancor_ord': (54 x 2) x (56 x 2)'
#> # 2 coordinates: CanCor1 and CanCor2
#> # 
#> # Rows (standard): [ 54 x 2 | 3 ]
#>    CanCor1 CanCor2 |   name      center .element
#>                    |   <chr>      <dbl> <chr>   
#> 1 -0.00911 -0.0362 | 1 pop15      35.1  active  
#> 2  0.0486  -0.260  | 2 pop75       2.29 active  
#> 3  0.0804   0.0577 | 3 Australia  NA    score   
#> 4  0.210   -0.125  | 4 Austria    NA    score   
#> 5  0.207   -0.147  | 5 Belgium    NA    score   
#> # ℹ 49 more rows
#> # 
#> # Columns (standard): [ 56 x 2 | 3 ]
#>    CanCor1    CanCor2 |   name       center .element
#>                       |   <chr>       <dbl> <chr>   
#> 1 0.00847   0.0334    | 1 sr           9.67 active  
#> 2 0.000131 -0.0000759 | 2 dpi       1107.   active  
#> 3 0.00417  -0.0123    | 3 ddpi         3.76 active  
#> 4 0.171    -0.0232    | 4 Australia   NA    score   
#> 5 0.0735    0.0475    | 5 Austria     NA    score   
#> # ℹ 51 more rows