Calculate the distance of points from the center of a cluster
Source:R/0.7_equations2.R
machine_learning.Rd
This function operates on multivariate data and calculates the distance of points from the centroid of one or more clusters.
Function utility
Used to generate the computations needed to model pair-distance measures in three dimensions
More information about this function
The pairDist function is used to quantify how far each data point (row) is from the overall mean across all columns. It’s commonly used in multivariate statistics, machine learning, and data analysis to assess the variability or similarity of data points relative to their mean. More specifically, the function is used in outlier detection and cluster analysis to evaluate the dispersion of data. Used in conjunction with other calculations, pairDist output can also be used to model data in three dimensions.
References
the current function was adapted from one of the examples in the svgViewR package,
https://cran.r-project.org/web/packages/svgViewR/svgViewR.pdf
Examples
data = attenu[,1:2]
#basic example using data.frame
pairDist(data)
#> [1] 13.7722494 12.8095310 12.8095310 12.8095310 12.8095310 12.8095310
#> [7] 12.8095310 12.8095310 12.8095310 12.8095310 12.8095310 11.7679075
#> [13] 10.7417701 10.7417701 10.7417701 10.7417701 10.7417701 10.7417701
#> [19] 10.7417701 10.7417701 10.7417701 9.7554109 9.7554109 9.7554109
#> [25] 9.7554109 9.7554109 9.7554109 9.7554109 9.7554109 9.7554109
#> [31] 9.7554109 9.7554109 8.7551503 7.7512791 6.7871985 6.7871985
#> [37] 6.7871985 6.7871985 6.7871985 5.7648916 5.7648916 5.7648916
#> [43] 5.7648916 5.7648916 5.7648916 5.7648916 5.7648916 5.7648916
#> [49] 5.7648916 5.7648916 5.7648916 5.7648916 5.7648916 5.7648916
#> [55] 5.7648916 5.7648916 5.7648916 5.7648916 5.7648916 5.7648916
#> [61] 5.7648916 4.8061451 4.0757818 4.0757818 4.0757818 2.7442083
#> [67] 1.8077726 1.8077726 1.1540268 1.1540268 1.1540268 1.1540268
#> [73] 0.2715804 0.2715804 0.2715804 0.2715804 1.5973597 1.5973597
#> [79] 1.5973597 2.7198735 2.7198735 2.7198735 3.2706013 3.2706013
#> [85] 3.2706013 3.2706013 3.2706013 3.2706013 3.2706013 3.2706013
#> [91] 3.2706013 3.2706013 3.2706013 4.2785072 4.2785072 4.2785072
#> [97] 4.2785072 4.2785072 4.2785072 4.2785072 4.2785072 4.2785072
#> [103] 4.2785072 4.2785072 4.2785072 4.2785072 4.2785072 4.2785072
#> [109] 4.2785072 4.2785072 4.2785072 4.2785072 4.2785072 4.2785072
#> [115] 4.2785072 4.2785072 4.2785072 4.2785072 4.2785072 4.2785072
#> [121] 4.2785072 4.2785072 4.2785072 4.2785072 4.2785072 4.2785072
#> [127] 4.2785072 4.2785072 4.2785072 4.2785072 4.2785072 5.3688272
#> [133] 5.3688272 5.3688272 5.3688272 5.3688272 5.3688272 5.3688272
#> [139] 5.3688272 5.3688272 5.3688272 5.3688272 5.3688272 5.3688272
#> [145] 5.3688272 5.3688272 5.3688272 6.2646854 6.2646854 6.2646854
#> [151] 6.2646854 6.2646854 6.2646854 6.2646854 7.2817035 7.2817035
#> [157] 7.2817035 7.2817035 7.2817035 7.2817035 7.2817035 7.2817035
#> [163] 7.2817035 7.2817035 8.2953792 8.2953792 8.2953792 8.2953792
#> [169] 8.2953792 8.2953792 8.2953792 8.2953792 8.2953792 8.2953792
#> [175] 8.2953792 8.2953792 8.2953792 8.2953792 8.2953792 8.2953792
#> [181] 8.2953792 8.2953792
#basic example using as.matrix
pairDist(as.matrix(data))
#> [1] 13.7722494 12.8095310 12.8095310 12.8095310 12.8095310 12.8095310
#> [7] 12.8095310 12.8095310 12.8095310 12.8095310 12.8095310 11.7679075
#> [13] 10.7417701 10.7417701 10.7417701 10.7417701 10.7417701 10.7417701
#> [19] 10.7417701 10.7417701 10.7417701 9.7554109 9.7554109 9.7554109
#> [25] 9.7554109 9.7554109 9.7554109 9.7554109 9.7554109 9.7554109
#> [31] 9.7554109 9.7554109 8.7551503 7.7512791 6.7871985 6.7871985
#> [37] 6.7871985 6.7871985 6.7871985 5.7648916 5.7648916 5.7648916
#> [43] 5.7648916 5.7648916 5.7648916 5.7648916 5.7648916 5.7648916
#> [49] 5.7648916 5.7648916 5.7648916 5.7648916 5.7648916 5.7648916
#> [55] 5.7648916 5.7648916 5.7648916 5.7648916 5.7648916 5.7648916
#> [61] 5.7648916 4.8061451 4.0757818 4.0757818 4.0757818 2.7442083
#> [67] 1.8077726 1.8077726 1.1540268 1.1540268 1.1540268 1.1540268
#> [73] 0.2715804 0.2715804 0.2715804 0.2715804 1.5973597 1.5973597
#> [79] 1.5973597 2.7198735 2.7198735 2.7198735 3.2706013 3.2706013
#> [85] 3.2706013 3.2706013 3.2706013 3.2706013 3.2706013 3.2706013
#> [91] 3.2706013 3.2706013 3.2706013 4.2785072 4.2785072 4.2785072
#> [97] 4.2785072 4.2785072 4.2785072 4.2785072 4.2785072 4.2785072
#> [103] 4.2785072 4.2785072 4.2785072 4.2785072 4.2785072 4.2785072
#> [109] 4.2785072 4.2785072 4.2785072 4.2785072 4.2785072 4.2785072
#> [115] 4.2785072 4.2785072 4.2785072 4.2785072 4.2785072 4.2785072
#> [121] 4.2785072 4.2785072 4.2785072 4.2785072 4.2785072 4.2785072
#> [127] 4.2785072 4.2785072 4.2785072 4.2785072 4.2785072 5.3688272
#> [133] 5.3688272 5.3688272 5.3688272 5.3688272 5.3688272 5.3688272
#> [139] 5.3688272 5.3688272 5.3688272 5.3688272 5.3688272 5.3688272
#> [145] 5.3688272 5.3688272 5.3688272 6.2646854 6.2646854 6.2646854
#> [151] 6.2646854 6.2646854 6.2646854 6.2646854 7.2817035 7.2817035
#> [157] 7.2817035 7.2817035 7.2817035 7.2817035 7.2817035 7.2817035
#> [163] 7.2817035 7.2817035 8.2953792 8.2953792 8.2953792 8.2953792
#> [169] 8.2953792 8.2953792 8.2953792 8.2953792 8.2953792 8.2953792
#> [175] 8.2953792 8.2953792 8.2953792 8.2953792 8.2953792 8.2953792
#> [181] 8.2953792 8.2953792
# round results to 2 decimal points
pairDist(data, 2)
#> [1] 13.77 12.81 12.81 12.81 12.81 12.81 12.81 12.81 12.81 12.81 12.81 11.77
#> [13] 10.74 10.74 10.74 10.74 10.74 10.74 10.74 10.74 10.74 9.76 9.76 9.76
#> [25] 9.76 9.76 9.76 9.76 9.76 9.76 9.76 9.76 8.76 7.75 6.79 6.79
#> [37] 6.79 6.79 6.79 5.76 5.76 5.76 5.76 5.76 5.76 5.76 5.76 5.76
#> [49] 5.76 5.76 5.76 5.76 5.76 5.76 5.76 5.76 5.76 5.76 5.76 5.76
#> [61] 5.76 4.81 4.08 4.08 4.08 2.74 1.81 1.81 1.15 1.15 1.15 1.15
#> [73] 0.27 0.27 0.27 0.27 1.60 1.60 1.60 2.72 2.72 2.72 3.27 3.27
#> [85] 3.27 3.27 3.27 3.27 3.27 3.27 3.27 3.27 3.27 4.28 4.28 4.28
#> [97] 4.28 4.28 4.28 4.28 4.28 4.28 4.28 4.28 4.28 4.28 4.28 4.28
#> [109] 4.28 4.28 4.28 4.28 4.28 4.28 4.28 4.28 4.28 4.28 4.28 4.28
#> [121] 4.28 4.28 4.28 4.28 4.28 4.28 4.28 4.28 4.28 4.28 4.28 5.37
#> [133] 5.37 5.37 5.37 5.37 5.37 5.37 5.37 5.37 5.37 5.37 5.37 5.37
#> [145] 5.37 5.37 5.37 6.26 6.26 6.26 6.26 6.26 6.26 6.26 7.28 7.28
#> [157] 7.28 7.28 7.28 7.28 7.28 7.28 7.28 7.28 8.30 8.30 8.30 8.30
#> [169] 8.30 8.30 8.30 8.30 8.30 8.30 8.30 8.30 8.30 8.30 8.30 8.30
#> [181] 8.30 8.30