k means clustering
x <- rbind(matrix(rnorm(1000, sd = 0.3), ncol = 2),
matrix(rnorm(1000, mean = 1, sd = 0.3), ncol = 2))
x
## [,1] [,2]
## [1,] -0.254758350 -0.1197926826
## [2,] -0.144753926 -0.4622138506
## [3,] -0.050539161 -0.1720906786
## [4,] -0.510702995 -0.1621170778
## [5,] 0.043629206 0.0220287938
## [6,] -0.195057201 0.4040089104
## [7,] -0.293887940 0.1546000386
## [8,] -0.166325391 0.2749486940
## [9,] -0.177605907 -0.5048323894
## [10,] -0.001048073 -0.3853409570
## [11,] -0.070159849 -0.0765219335
## [12,] -0.126246948 0.5442939674
## [13,] 0.207261806 0.0504811185
## [14,] -0.410217806 -0.0630421950
## [15,] -0.238139433 0.2541117019
## [16,] 0.057121199 0.5760115438
## [17,] -0.007025833 -0.0934874689
## [18,] -0.051280058 -0.3947327910
## [19,] -0.334558624 0.1400067579
## [20,] 0.246069839 0.2698041183
## [21,] 0.268895751 0.2591580743
## [22,] -0.284753543 0.3340410530
## [23,] 0.144909385 0.2837027149
## [24,] -0.049594650 0.2343268542
## [25,] 0.112780896 -0.0436260093
## [26,] -0.172844651 -0.1088523140
## [27,] 0.281498396 0.0803166265
## [28,] -0.142808161 0.3702658072
## [29,] -0.076147366 -0.0423666787
## [30,] 0.260734271 -0.2028746645
## [31,] -0.281483610 -0.0312102099
## [32,] 0.376730913 0.0432811862
## [33,] -0.460233295 0.0287004144
## [34,] -0.339163313 -0.1850166327
## [35,] -0.592911617 -0.0585219436
## [36,] 0.326172497 -0.4324521058
## [37,] 0.280034482 -0.2457679517
## [38,] -0.175684052 0.0403752450
## [39,] 0.424705107 0.2977497953
## [40,] -0.882528991 0.3525969937
## [41,] -0.164517086 0.5000445469
## [42,] -0.064066824 0.1542083983
## [43,] -0.034556855 -0.3866402142
## [44,] 0.270487823 0.4901065448
## [45,] 0.099364793 0.5046692202
## [46,] -0.012281280 -0.0001764535
## [47,] -0.236680489 -0.4273104346
## [48,] -0.328584909 -0.0375851341
## [49,] -0.380205108 0.2316368823
## [50,] 0.281570867 -0.0564464557
## [51,] 0.282889285 -0.0729487459
## [52,] -0.137658791 -0.2589105970
## [53,] -0.406562096 0.4449727360
## [54,] 0.543041168 0.1701654211
## [55,] -0.425520081 -0.1804540005
## [56,] -0.041478431 0.0114832788
## [57,] 0.016330245 0.6733445650
## [58,] 0.406481625 0.1451740740
## [59,] 0.095162513 -0.0900419236
## [60,] -0.005017739 0.3008827841
## [61,] -0.327702833 -0.3012921033
## [62,] 0.318402053 -0.2547180742
## [63,] -0.162827321 0.1590670231
## [64,] 0.254975669 0.4534636971
## [65,] -0.076462968 -0.5199912942
## [66,] -0.052540710 -0.3002931798
## [67,] 0.635032124 0.1165443221
## [68,] -0.650876945 -0.1173834097
## [69,] 0.423083137 -0.1919813972
## [70,] -0.008134149 0.4693319028
## [71,] -0.065828922 0.1694146544
## [72,] -0.662906383 -0.1767345579
## [73,] -0.424440984 -0.5482567532
## [74,] 0.030487299 -0.0436328261
## [75,] -0.127160956 0.4408570787
## [76,] -0.145028241 0.1010822883
## [77,] -0.037517972 0.0401866511
## [78,] 0.068495742 -0.0145478641
## [79,] 0.620640291 -0.1588489323
## [80,] 0.044935301 0.1410912872
## [81,] -0.086097462 -0.1421595135
## [82,] 0.052891461 -0.0968350681
## [83,] -0.246813571 0.3178981080
## [84,] -0.048039368 0.0858639583
## [85,] 0.116783017 0.5761955485
## [86,] -0.142032761 0.3934339053
## [87,] -0.252012086 -0.1905929593
## [88,] -0.664458158 0.1089020870
## [89,] 0.226916036 0.0881675696
## [90,] -0.149950057 0.2968160203
## [91,] -0.067599088 -0.2137829335
## [92,] 0.068926060 -0.2941427864
## [93,] 0.048485075 -0.2491189224
## [94,] 0.058769076 0.2093498648
## [95,] -0.412736968 -0.1631407924
## [96,] -0.400603880 0.5180534284
## [97,] 0.499620369 -0.3576204302
## [98,] -0.611849024 -0.1404701993
## [99,] -0.406182199 -0.6751443596
## [100,] -0.268107304 -0.6884600134
## [101,] 0.073236680 -0.2023619988
## [102,] 0.072871943 0.0975178021
## [103,] 0.127484294 -0.5427560053
## [104,] 0.107782046 -0.3563609045
## [105,] 0.291986506 0.4817257889
## [106,] -0.135915607 0.1421710607
## [107,] -0.308604451 0.1096679672
## [108,] 0.591024801 -0.2666664578
## [109,] -0.038648348 0.0027279548
## [110,] -0.448309287 0.3223214791
## [111,] 0.349967387 0.4197113174
## [112,] -0.239950977 -0.3343918306
## [113,] -0.263090695 -0.0693695841
## [114,] 0.038648422 0.0916970737
## [115,] 0.478522518 -0.1419946366
## [116,] -0.068722469 -0.1208825966
## [117,] 0.268503721 -0.6196267419
## [118,] 0.190222966 0.0545523909
## [119,] 0.347047482 -0.1113132515
## [120,] 0.103975378 0.4276046345
## [121,] 0.501296532 -0.4700510130
## [122,] -0.105081389 0.2942659385
## [123,] 0.284168668 0.2247719832
## [124,] 0.082631285 -0.0839507497
## [125,] 0.029183191 0.3746700104
## [126,] 0.120151915 -0.4932891344
## [127,] -0.331589171 -0.3373808869
## [128,] -0.371474735 0.0454201159
## [129,] 0.593634314 0.1711063548
## [130,] -0.155049961 -0.0598446738
## [131,] 0.035652139 0.2383998363
## [132,] -0.362457509 -0.4085634113
## [133,] 0.109219949 -0.0519392208
## [134,] -0.047961808 0.3336841264
## [135,] -0.114652326 -0.1364653408
## [136,] 0.255775368 0.0063260220
## [137,] 0.284483778 -0.1825622177
## [138,] -0.049052904 -0.1969353176
## [139,] 0.147850039 0.6032644856
## [140,] 0.536150556 -0.0979589124
## [141,] 0.497972594 -0.0778934966
## [142,] 0.023808510 0.3110833434
## [143,] 0.039181266 0.2617741481
## [144,] -0.553430576 0.0827824468
## [145,] 0.170795883 -0.1648196035
## [146,] 0.060773618 0.4822729203
## [147,] -0.084950180 -0.1495207374
## [148,] 0.637991584 -0.3750732596
## [149,] -0.337487074 -0.0723576266
## [150,] 0.678580430 -0.0273667488
## [151,] 0.248817567 -0.3288299550
## [152,] -0.122004051 0.0399752847
## [153,] -0.225156364 0.1623644238
## [154,] 0.272194245 0.1147823744
## [155,] -0.431393654 -0.0948301643
## [156,] 0.584712044 -0.1412414604
## [157,] 0.576192139 0.3807217219
## [158,] -0.256026849 0.2323908575
## [159,] 0.287080266 0.1835045441
## [160,] 0.049584959 -0.1788614170
## [161,] 0.178671372 -0.1188215682
## [162,] -0.114095073 0.1250920665
## [163,] -0.294826864 0.0900569393
## [164,] 0.290787010 -0.2708057042
## [165,] 0.576701423 -0.2708270982
## [166,] -0.380773223 0.0278669486
## [167,] 0.295345259 -0.2980723123
## [168,] 0.014300260 -0.3046649469
## [169,] -0.296715137 0.1165395168
## [170,] 0.456700784 -0.4461460459
## [171,] 0.136303026 -0.1638451310
## [172,] -0.084700167 0.3366925738
## [173,] 0.056622618 -0.1926132757
## [174,] 0.056746523 0.0702027434
## [175,] 0.018514625 0.3409832455
## [176,] -0.166346327 0.2339706658
## [177,] -0.460607020 -0.1368248770
## [178,] 0.380348801 -0.3427585825
## [179,] 0.327266317 0.8813556623
## [180,] 0.208153183 -0.4677008023
## [181,] 0.034253822 0.4284720849
## [182,] -0.088172283 0.2540153220
## [183,] -0.248594992 -0.0245029646
## [184,] 0.056420403 0.1237100427
## [185,] -0.086140127 0.1636019952
## [186,] -0.062122459 -0.2559300180
## [187,] 0.084147482 -0.5161048043
## [188,] 0.126931922 0.1256153667
## [189,] -0.023755063 -0.1612100065
## [190,] 0.269462637 -0.3589204582
## [191,] 0.267355335 0.2499899345
## [192,] 0.326021157 -0.1749760822
## [193,] 0.220281898 0.7992718728
## [194,] -0.075011237 -0.5918546040
## [195,] -0.220278690 0.1361590520
## [196,] 0.358877983 -0.4296715778
## [197,] -0.014685619 0.2636485354
## [198,] 0.082055011 0.0951141924
## [199,] -0.181440961 -0.2998504774
## [200,] -0.218915452 0.4214526171
## [201,] 0.020640977 -0.1442281881
## [202,] -0.048414150 -0.5203827322
## [203,] 0.280555197 -0.1657695981
## [204,] -0.349124588 -0.1760241810
## [205,] -0.092196037 0.2466862761
## [206,] -0.157562370 -0.0644996808
## [207,] -0.215843510 0.1596152919
## [208,] -0.333811544 0.0363752807
## [209,] -0.171107132 -0.0546807779
## [210,] 0.789359053 0.4910094790
## [211,] -0.406586316 -0.4739786006
## [212,] -0.116407759 0.0793158232
## [213,] -0.115050247 0.1005759412
## [214,] -0.204326486 -0.1984615541
## [215,] 0.179848003 -0.1911948917
## [216,] -0.156139692 -0.0990591363
## [217,] 0.353554663 0.0481188790
## [218,] -0.006349317 0.0553442112
## [219,] -0.701542115 -0.0208015489
## [220,] -0.557592086 -0.1644032207
## [221,] 0.441284193 0.5319350451
## [222,] 0.413165642 -0.5634016514
## [223,] -0.073442413 0.1172812244
## [224,] -0.189111492 -0.4122244151
## [225,] -0.321870754 0.1064997500
## [226,] -0.020042380 0.2214265360
## [227,] -0.297464100 -0.1703362350
## [228,] -0.062300090 -0.0376118285
## [229,] 0.212688422 0.0335058257
## [230,] 0.386383530 -0.5989614035
## [231,] 0.403612774 0.2887854341
## [232,] -0.085764064 0.4141580859
## [233,] 0.392749629 0.0278648078
## [234,] -0.022968659 -0.1778465085
## [235,] -0.094580488 0.1904567535
## [236,] -0.148462548 0.1942418107
## [237,] -0.411364368 0.4309652457
## [238,] 0.433582853 0.0908862163
## [239,] -0.130861497 -0.1855704744
## [240,] 0.276620331 -0.2730753100
## [241,] 0.567439646 0.4672626561
## [242,] -0.067144583 0.0596470386
## [243,] 0.143072691 -0.0743284025
## [244,] 0.010424770 0.2623843044
## [245,] 0.225423642 -0.3838569113
## [246,] -0.365601449 -0.5953423598
## [247,] -0.148387238 -0.4339827117
## [248,] -0.307545076 0.0911188934
## [249,] -0.176359099 -0.2830945106
## [250,] 0.425445268 0.1628501527
## [251,] -0.060572270 0.4345170580
## [252,] 0.063033411 -0.1073129799
## [253,] -0.270718212 0.1308991964
## [254,] 0.220523168 -0.0230725914
## [255,] -0.386845674 0.5350869011
## [256,] -0.517630512 -0.0045670922
## [257,] 0.284980086 -0.3529360341
## [258,] 0.166861427 -0.0059358292
## [259,] 0.354638765 -0.2844338609
## [260,] -0.339015163 0.5632738364
## [261,] 0.048816565 -0.8672021386
## [262,] -0.006171349 -0.3446941367
## [263,] -0.059296196 -0.1103531642
## [264,] -0.686861024 -0.0071598178
## [265,] -0.170313303 0.3706409459
## [266,] -0.206957397 -0.2183941196
## [267,] 0.235609861 0.0045511707
## [268,] 0.276603603 0.2055521880
## [269,] 0.039706290 -0.0056619525
## [270,] 0.197063035 -0.1046051158
## [271,] 0.070269989 -0.0765262035
## [272,] -0.224953417 -0.0204492127
## [273,] 0.114733298 -0.1238943695
## [274,] -0.556732083 0.3662076777
## [275,] 0.815433845 0.0628585206
## [276,] -0.310918189 -0.1684742145
## [277,] -0.279340769 0.0857680372
## [278,] 0.168825329 0.1081412111
## [279,] 0.267606785 -0.4298444344
## [280,] 0.243205435 -0.1205318396
## [281,] 0.102964819 0.1104524786
## [282,] -0.328379831 -0.0548612570
## [283,] -0.304501026 -0.3546747510
## [284,] 0.124629568 -0.4155505254
## [285,] -0.238511359 0.7509247622
## [286,] 0.120336292 0.3226290256
## [287,] -0.520724997 -0.2010286180
## [288,] -0.112570392 0.1360710497
## [289,] 0.190715990 -0.3206328788
## [290,] 0.261061820 -0.3015381489
## [291,] 0.236059365 0.0731127312
## [292,] -0.319593846 0.2443245634
## [293,] -0.202349359 0.2159372349
## [294,] 0.233489486 -0.2751712111
## [295,] -0.065817504 0.1007555916
## [296,] -0.303199167 -0.2787175447
## [297,] -0.101411667 0.0938959672
## [298,] 0.099159229 0.1650266988
## [299,] -0.391653920 -0.4439492692
## [300,] -0.368894618 0.0444030479
## [301,] -0.088183040 0.3977576497
## [302,] -0.250386152 -0.2098296441
## [303,] 0.611603317 0.2168879872
## [304,] 0.508326449 0.2250367798
## [305,] -0.262208809 -0.0969378384
## [306,] -0.635906995 -0.3736894808
## [307,] -0.375355321 0.1257501494
## [308,] -0.037727872 -0.4200592773
## [309,] 0.363163449 -0.0913969273
## [310,] -0.118375597 -0.2198265783
## [311,] 0.255720209 -0.0913562434
## [312,] 0.167187071 0.3941878180
## [313,] 0.092888969 -0.3322345683
## [314,] -0.285995451 -0.2440319306
## [315,] 0.507266018 -0.2378548322
## [316,] 0.415331082 -0.2707725699
## [317,] -0.429328287 -0.3828736219
## [318,] 0.211638098 -0.3726184848
## [319,] 0.174083727 0.1201050528
## [320,] -0.046200036 -0.1418286332
## [321,] 0.108718640 0.0602962527
## [322,] -0.343365386 0.3488424625
## [323,] -0.370766281 0.3555060863
## [324,] 0.174868006 -0.4270821399
## [325,] 0.147046170 0.1400025285
## [326,] -0.168476107 0.1066456625
## [327,] -0.023569137 0.0866802605
## [328,] -0.255252611 0.4880743555
## [329,] -0.543745020 -0.2487752960
## [330,] 0.263946982 0.1648282899
## [331,] -0.185176362 0.2440136586
## [332,] 0.445863041 -0.5206170020
## [333,] -0.285453376 0.2348619557
## [334,] 0.479136695 0.4261691177
## [335,] -0.309781647 -0.0732199774
## [336,] -0.050677421 0.0481066402
## [337,] 0.313020635 -0.1106117337
## [338,] 0.007725061 -0.0207140022
## [339,] 0.312643132 -0.2924721150
## [340,] 0.663233621 0.2715895823
## [341,] 0.097994826 0.7352625944
## [342,] 0.062213636 0.4653435954
## [343,] -0.089216407 0.1864579403
## [344,] -0.027941985 -0.0456375644
## [345,] 0.265497426 0.0322419070
## [346,] 0.104662521 0.4500935883
## [347,] -0.119659463 -0.0826295913
## [348,] -0.506185572 0.1099362290
## [349,] -0.088511929 -0.3419547960
## [350,] -0.209906642 -0.4158861149
## [351,] -0.285957964 -0.0587314671
## [352,] 0.339115214 0.5475412648
## [353,] 0.101439302 -0.0571516884
## [354,] -0.196176875 0.0830084898
## [355,] -0.432643749 -0.5602271499
## [356,] -0.098198978 0.1998712810
## [357,] -0.402624060 -0.3811092680
## [358,] 0.065225496 -0.1264226345
## [359,] 0.504142189 -0.2113568631
## [360,] 0.335450946 0.5183165574
## [361,] 0.114604023 -0.2182858785
## [362,] 0.059290083 -0.3151004137
## [363,] 0.635529025 -0.2841886063
## [364,] 0.066684133 0.5121258549
## [365,] 0.197024543 0.3519072655
## [366,] 0.134397204 -0.1186631515
## [367,] 0.265081096 -0.0322084607
## [368,] 0.114147121 0.3988156423
## [369,] -0.519282401 -0.0391693943
## [370,] -0.173082627 0.2444949662
## [371,] 0.289030679 -0.2391033792
## [372,] 0.051265946 0.1690771538
## [373,] -0.328231113 -0.1201236963
## [374,] -0.143357197 0.3066061580
## [375,] -0.515746180 -0.3437147393
## [376,] 0.390839975 0.1366856956
## [377,] -0.021494357 0.0028183211
## [378,] 0.014597419 0.0335184096
## [379,] 0.310192898 0.3786921037
## [380,] -0.094167542 -0.5025286745
## [381,] -0.072329774 0.1968773229
## [382,] 0.246945436 -0.0110557054
## [383,] -0.353884011 -0.4217873240
## [384,] -0.009234097 0.4198030168
## [385,] -0.503640123 0.5028973172
## [386,] -0.512072257 -0.0999408981
## [387,] 0.383891688 0.5554746341
## [388,] -0.296726858 0.1333268012
## [389,] -0.056540920 -0.1254533478
## [390,] 0.422064985 0.2351699615
## [391,] 0.416493106 -0.0730844197
## [392,] -0.398185538 0.0284585751
## [393,] -0.634485345 0.6371012340
## [394,] -0.105917579 -0.0523383807
## [395,] 0.112333090 -0.2354679130
## [396,] -0.315342357 -0.1674314930
## [397,] 0.058223302 -0.1635815398
## [398,] 0.538259154 0.1885851622
## [399,] -0.155280215 0.2670381326
## [400,] -0.095601098 -0.0990445959
## [401,] 0.016004619 0.2341399058
## [402,] 0.507011339 0.2087545260
## [403,] 0.228159256 -0.1719488070
## [404,] 0.121002048 0.4323363132
## [405,] 0.034082669 -0.3353278684
## [406,] 0.074465833 -0.4226045979
## [407,] -0.134476679 -0.4896535426
## [408,] -0.032128672 0.4014414204
## [409,] 0.434063498 0.0717503375
## [410,] -0.047453872 0.3000336939
## [411,] 0.252061708 -0.5018403605
## [412,] 0.118431482 0.1737835856
## [413,] -0.377495010 -0.6896643983
## [414,] 0.031685754 0.1098396381
## [415,] -0.003677829 0.1269314053
## [416,] -0.164860304 -0.1864826426
## [417,] -0.003728184 -0.1932548062
## [418,] -0.204459970 0.0234972006
## [419,] 0.235478778 0.1206289029
## [420,] -0.093256334 0.2845872481
## [421,] -0.040750669 -0.0979938215
## [422,] 0.100881347 0.2764630950
## [423,] 0.020543580 0.4963434584
## [424,] 0.049311656 -0.2145658973
## [425,] -0.347136939 0.3980700904
## [426,] -0.531997595 -0.0214536058
## [427,] 0.031681218 -0.3473950814
## [428,] 0.312939411 0.2479979725
## [429,] 0.039669699 0.6569841686
## [430,] 0.254856050 0.4526087629
## [431,] -0.143119764 -0.1342960449
## [432,] -0.063176724 -0.0892919357
## [433,] -0.145211895 0.1204684536
## [434,] -0.041244143 -0.1512480491
## [435,] 0.221315532 0.3479415306
## [436,] -0.228137330 0.2113678495
## [437,] -0.231858134 0.1775993418
## [438,] -0.203928884 -0.3858630975
## [439,] 0.416964783 -0.3485732240
## [440,] -0.232423435 -0.0948758612
## [441,] -0.357411824 -0.1379559203
## [442,] -0.285814018 0.3512966294
## [443,] 0.116301580 0.1538175560
## [444,] -0.083665529 0.1335668080
## [445,] 0.195287174 0.1807255166
## [446,] 0.087853534 -0.0702374368
## [447,] -0.103759164 -0.1522886058
## [448,] -0.325475752 -0.0903932341
## [449,] -0.135591056 0.3287495487
## [450,] 0.186815626 0.3144457021
## [451,] 0.194444957 0.1955131286
## [452,] 0.695129349 -0.2459043536
## [453,] -0.403192831 -0.1399753914
## [454,] 0.294832896 -0.1014741729
## [455,] -0.027641774 0.4365789374
## [456,] 0.393258387 -0.1212928775
## [457,] 0.356715332 0.1744649015
## [458,] -0.555344811 0.0661218829
## [459,] -0.399578383 -0.3823342576
## [460,] 0.116290520 0.3979135471
## [461,] 0.295191541 0.2356174190
## [462,] 0.201256400 0.4793473403
## [463,] -0.401432330 0.0551089799
## [464,] 0.111345568 -0.3901903222
## [465,] -0.581478309 -0.4725578161
## [466,] 0.030764514 0.3890948675
## [467,] 0.195313200 0.2595052363
## [468,] -0.338907947 -0.3248096279
## [469,] -0.294420418 -0.0887622808
## [470,] 0.103252543 0.1763840071
## [471,] -0.649769257 -0.1324350202
## [472,] 0.160303204 -0.0189960231
## [473,] 0.065132954 -0.0039553299
## [474,] -0.015719467 0.1720263189
## [475,] -0.242494094 -0.2984594795
## [476,] -0.607227386 0.1821261302
## [477,] 0.012599563 -0.1649849935
## [478,] 0.211496795 -0.3011933522
## [479,] 0.091440452 -0.2324562957
## [480,] -0.211578806 0.0377570126
## [481,] 0.026210564 0.2176739654
## [482,] -0.102231047 0.0044283453
## [483,] 0.797611119 0.4070337487
## [484,] 0.148032667 0.2790513587
## [485,] -0.232495091 0.4576454137
## [486,] -0.519770017 -0.1266575632
## [487,] 0.026115140 0.6267901474
## [488,] 0.253130258 0.0444572303
## [489,] -0.035362588 0.0778232590
## [490,] 0.581104611 0.1235024821
## [491,] 0.412056708 -0.1478684199
## [492,] 0.093300666 -0.1722153326
## [493,] 0.050539025 0.3480705289
## [494,] -0.016152197 -1.0863986253
## [495,] 0.247125815 -0.3573891500
## [496,] -0.324877461 0.4524803874
## [497,] -0.583387819 -0.2537207509
## [498,] -0.014380883 0.4978213805
## [499,] -0.246758086 0.0923173488
## [500,] 0.336983663 -0.2970412094
## [501,] 1.041849979 1.3290179115
## [502,] 0.837457921 0.9968485507
## [503,] 1.174918898 1.3196249553
## [504,] 1.141096885 0.8999731935
## [505,] 1.399559432 0.9317175041
## [506,] 0.900335941 0.8867685565
## [507,] 0.977845767 1.4124285469
## [508,] 0.980718828 0.9386936106
## [509,] 0.866272705 1.1291978968
## [510,] 0.836291586 0.4813548355
## [511,] 1.039239860 0.8599673006
## [512,] 0.760137775 0.6796417125
## [513,] 1.492698504 0.8837078357
## [514,] 1.269695140 1.4723691636
## [515,] 0.710196731 0.8232343403
## [516,] 1.386823955 0.3185727100
## [517,] 0.892748500 1.4328241436
## [518,] 0.252670392 0.8663952436
## [519,] 0.832009713 1.0562520521
## [520,] 0.724785315 0.3454169384
## [521,] 1.162955886 0.6905122997
## [522,] 1.011095516 1.3553705163
## [523,] 1.023659122 0.6517235583
## [524,] 1.042930485 0.6879223364
## [525,] 1.013768544 1.0937451616
## [526,] 1.276903311 1.1076863793
## [527,] 0.906813960 0.9257348496
## [528,] 1.086721375 0.6965718227
## [529,] 0.546094343 1.4824382116
## [530,] 1.587999816 1.1904953849
## [531,] 1.045944111 0.8708028118
## [532,] 1.478834586 0.5311021956
## [533,] 1.448653600 1.0655288046
## [534,] 0.958877657 0.9477241535
## [535,] 0.898273808 0.8361765976
## [536,] 0.482126848 1.0915020493
## [537,] 1.166128286 1.1604482930
## [538,] 1.025230446 0.6429466062
## [539,] 1.092257236 0.5593625445
## [540,] 1.219285948 0.9899437704
## [541,] 1.304618043 1.4429606395
## [542,] 1.232646154 0.9179333571
## [543,] 1.462628925 1.1792142222
## [544,] 0.967470080 0.7131357984
## [545,] 1.048716173 1.3763661224
## [546,] 1.647398697 1.1638965407
## [547,] 0.431800222 1.2525385034
## [548,] 1.324910862 1.2539098986
## [549,] 0.942595789 1.1835399528
## [550,] 1.431359719 1.2046581153
## [551,] 0.458560720 1.2335514287
## [552,] 1.002669743 0.3559174772
## [553,] 0.806957850 1.1764648149
## [554,] 0.793838629 1.5499984397
## [555,] 0.946813988 1.4995368392
## [556,] 0.986455610 0.8760432334
## [557,] 1.142224077 1.1562374817
## [558,] 1.097412460 1.5000997618
## [559,] 0.706173684 0.5261927353
## [560,] 1.118951285 1.4265740033
## [561,] 0.920839060 1.1546009317
## [562,] 1.269612376 0.7089224769
## [563,] 1.169365991 0.7724357597
## [564,] 1.041348744 1.0598752946
## [565,] 1.320079402 0.8193342539
## [566,] 0.975260309 1.3413058489
## [567,] 0.726041610 0.3714185821
## [568,] 0.983292744 0.9728445264
## [569,] 1.718522725 1.1123822658
## [570,] 1.057370295 0.7582020375
## [571,] 0.923142876 1.8518170366
## [572,] 1.215129682 0.3442943613
## [573,] 1.025590670 0.9556078739
## [574,] 0.671074471 1.3217561601
## [575,] 1.063034657 1.0151857227
## [576,] 0.929591879 0.9892856488
## [577,] 1.152313854 1.2911918170
## [578,] 0.705198969 0.8653311411
## [579,] 0.818259938 1.5223300638
## [580,] 1.356300084 1.0334826487
## [581,] 0.877139825 0.6726587585
## [582,] 1.170782498 1.2869736017
## [583,] 1.449948472 1.4841670705
## [584,] 1.030849156 0.9122465099
## [585,] 1.408558427 1.5205725084
## [586,] 0.962972284 1.0107074275
## [587,] 1.028298126 0.6934701941
## [588,] 0.667853255 0.6299864605
## [589,] 1.178188072 0.6431724515
## [590,] 0.898212734 1.2880031479
## [591,] 0.992375030 1.4165832884
## [592,] 0.596285140 0.8716316914
## [593,] 1.101048315 1.2132784486
## [594,] 1.334433959 1.0284652065
## [595,] 1.341896762 1.4872015239
## [596,] 1.072438277 0.6946773894
## [597,] 1.109530514 1.0343386539
## [598,] 0.460163647 0.3820151396
## [599,] 0.949738176 1.5267490332
## [600,] 1.134024272 1.2315657489
## [601,] 1.087807338 1.1087987923
## [602,] 1.509657495 0.7362222666
## [603,] 0.808475802 0.7703595823
## [604,] 1.040562739 1.1681763967
## [605,] 0.959029052 0.9873815796
## [606,] 1.399185154 0.9102104295
## [607,] 1.023274601 0.8838580238
## [608,] 1.045255319 1.0973706976
## [609,] 0.699338581 0.6305261278
## [610,] 0.969041732 1.2412336126
## [611,] 0.891268965 0.6529783888
## [612,] 1.478530760 0.9943809699
## [613,] 1.262507575 1.2598578921
## [614,] 1.350712464 0.8693479801
## [615,] 0.675477001 1.0658012153
## [616,] 0.719876194 0.7443403610
## [617,] 1.667988365 1.0254067480
## [618,] 0.891744756 1.0519054495
## [619,] 1.624331490 1.0063963373
## [620,] 0.956452877 1.0192237394
## [621,] 0.865800928 1.2419269697
## [622,] 1.001271287 1.3115536526
## [623,] 1.012893917 1.2026606193
## [624,] 0.817697363 0.9591081909
## [625,] 1.027872471 1.3769945946
## [626,] 0.837628640 0.7074727001
## [627,] 0.706230683 1.0617073259
## [628,] 1.285125346 0.7566626064
## [629,] 1.087869142 1.3247448974
## [630,] 1.269122647 0.8472094359
## [631,] 1.512119437 0.9903664254
## [632,] 0.856539151 0.8677636115
## [633,] 0.746971093 0.8385520942
## [634,] 0.589558859 0.4061781025
## [635,] 0.994235746 0.6388079877
## [636,] 1.175030845 1.1286003098
## [637,] 1.054505530 0.8051278951
## [638,] 1.393055885 0.9135565585
## [639,] 0.419577629 0.6742636500
## [640,] 1.200542231 1.3050827360
## [641,] 0.778961348 1.0508550139
## [642,] 0.912775741 0.6745765840
## [643,] 1.065559133 0.6051632295
## [644,] 1.044742214 1.0911133599
## [645,] 0.817330869 0.9328911895
## [646,] 1.787097155 1.1573233789
## [647,] 0.952604039 1.2118666526
## [648,] 1.038099241 0.9751043665
## [649,] 1.137647016 1.0619998505
## [650,] 0.863104627 0.6254363847
## [651,] 1.411895336 1.2234618900
## [652,] 0.932203210 0.5803409086
## [653,] 0.784234577 1.1182772705
## [654,] 0.764412022 0.9030511766
## [655,] 0.952639774 0.9156219656
## [656,] 1.006258489 0.5496299065
## [657,] 1.192770046 1.1904399503
## [658,] 1.396698867 1.1966056339
## [659,] 1.641548647 0.8995476995
## [660,] 1.757812654 0.1782623771
## [661,] 1.227701377 0.8344746397
## [662,] 1.035749326 0.9689419906
## [663,] 1.646543807 0.9870057275
## [664,] 0.875210812 0.4791151073
## [665,] 0.654110030 1.1167521871
## [666,] 0.380453650 0.9520048268
## [667,] 1.245440599 0.8987512330
## [668,] 1.191020560 0.8658427237
## [669,] 1.117918217 1.2124917095
## [670,] 1.172056475 1.1211961798
## [671,] 0.868162557 0.6912120449
## [672,] 0.618880867 0.9276046977
## [673,] 1.464358304 1.3634128323
## [674,] 0.890359037 1.0547580781
## [675,] 0.877694953 1.3657806568
## [676,] 0.653989176 1.1836790317
## [677,] 1.143675535 1.7106873426
## [678,] 1.114299410 0.8792628520
## [679,] 0.914892015 1.4301237633
## [680,] 0.857457872 1.1171919295
## [681,] 0.839628066 0.9946301779
## [682,] 0.699446689 0.8534435682
## [683,] 0.712790476 0.8400576991
## [684,] 1.387453300 0.8083915376
## [685,] 1.223629584 0.8436532587
## [686,] 1.006706347 1.2950779840
## [687,] 1.005754751 0.7759787675
## [688,] 0.879490943 1.1160145333
## [689,] 0.586933665 0.4517917113
## [690,] 1.349176991 1.1385271166
## [691,] 0.542032797 1.1871563669
## [692,] 0.879006838 0.7886721493
## [693,] 1.482267066 1.6390261749
## [694,] 0.669848777 0.7971424422
## [695,] 1.000678569 0.3913261261
## [696,] 1.312955737 1.1846382787
## [697,] 1.547684298 1.3587187646
## [698,] 0.940070250 1.2526880452
## [699,] 0.645296175 0.9016159145
## [700,] 0.986418125 0.9591994423
## [701,] 1.376687693 1.2788233673
## [702,] 1.034982255 0.5564160777
## [703,] 1.267304280 1.4190414079
## [704,] 1.006123774 0.8027234497
## [705,] 0.632544496 0.9461439870
## [706,] 0.729970732 1.2461152772
## [707,] 1.554841667 1.2730993953
## [708,] 1.067851336 0.6644141703
## [709,] 0.319784865 0.7976241517
## [710,] 0.141737357 1.2820148525
## [711,] 1.702402775 1.5140372219
## [712,] 0.804091476 0.9796696335
## [713,] 0.454926309 0.8028108964
## [714,] 1.478322609 1.3345468119
## [715,] 1.121099642 1.0012969101
## [716,] 1.162548817 1.5944106997
## [717,] 1.086920933 1.5781615095
## [718,] 0.854545572 0.7965333619
## [719,] 1.528287941 0.9470322292
## [720,] 1.054770515 0.9841033222
## [721,] 0.986013243 0.4615379624
## [722,] 0.666382693 1.0279090971
## [723,] 1.427742419 1.0169729198
## [724,] 1.463297024 0.7964931204
## [725,] 1.003691228 0.8619905478
## [726,] 1.342168154 0.9426205875
## [727,] 0.795337881 0.7382419644
## [728,] 1.250296216 0.7262324527
## [729,] 1.408833863 1.0432960545
## [730,] 1.187584800 0.6006625333
## [731,] 0.836740609 1.3407125381
## [732,] 1.132980288 0.7060982207
## [733,] 0.714446335 0.9297431247
## [734,] 1.039580558 0.4331678994
## [735,] 0.707377196 0.8559601433
## [736,] 1.402445730 0.9572214737
## [737,] 1.094463814 0.6090950170
## [738,] 0.618651500 1.1760425788
## [739,] 1.434373461 0.8388271963
## [740,] 0.838503465 0.9529826695
## [741,] 1.020947895 0.7613910614
## [742,] 1.137648556 0.6887841783
## [743,] 0.886076376 0.6097060344
## [744,] 0.925304859 0.8648079313
## [745,] 0.745248564 1.0116844147
## [746,] 0.964240517 1.5801016008
## [747,] 1.213809616 1.1126097528
## [748,] 1.536317604 1.2049050278
## [749,] 1.354823973 0.7729062179
## [750,] 0.649053020 1.3983695252
## [751,] 1.006614220 0.9240649417
## [752,] 1.378260473 0.9069845699
## [753,] 0.759033374 1.5078390700
## [754,] 0.722583330 1.1155302080
## [755,] 0.854250297 1.2178608908
## [756,] 1.006900995 0.3686271237
## [757,] 0.462425913 0.8640917524
## [758,] 0.658668598 0.7530935832
## [759,] 1.589181103 0.7959809309
## [760,] 0.930207477 1.1926286953
## [761,] 0.887470520 0.7566999121
## [762,] 1.331026011 1.1087842254
## [763,] 0.992746525 1.1542313196
## [764,] 0.408121150 0.7261494071
## [765,] 0.756583989 1.1433450220
## [766,] 0.990261240 1.2600969042
## [767,] 0.781109248 1.0625794441
## [768,] 1.034861779 0.7673970174
## [769,] 1.483836475 0.4718721115
## [770,] 0.875955384 0.9594728709
## [771,] 0.420175059 1.1220199907
## [772,] 1.453555364 0.9058057076
## [773,] 1.387930556 1.0917245353
## [774,] 1.238802868 0.9548333433
## [775,] 0.893111392 0.4095377517
## [776,] 0.743930308 1.2100112090
## [777,] 0.822559741 1.4178411375
## [778,] 1.139721264 0.8942446868
## [779,] 0.778160643 1.1527284148
## [780,] 0.964198201 0.5010203998
## [781,] 1.094706604 0.9983872357
## [782,] 0.751649706 1.3101153593
## [783,] 1.013581245 1.2372707270
## [784,] 0.883075513 0.5403084831
## [785,] 0.710712518 1.2936318225
## [786,] 0.941425917 1.0318042669
## [787,] 1.369243695 1.2401491515
## [788,] 0.778767104 0.9516728842
## [789,] 0.661500463 1.0805232785
## [790,] 0.661306682 1.5648896586
## [791,] 0.649836528 1.0701170106
## [792,] 0.549550448 0.8764026880
## [793,] 1.223413726 1.4297115155
## [794,] 1.011462051 1.9711548993
## [795,] 0.812377722 1.2368879765
## [796,] 1.065313444 0.5785001731
## [797,] 1.478080201 0.9681529209
## [798,] 0.625660138 1.5844144592
## [799,] 1.181494695 1.1091329020
## [800,] 1.112526812 0.7041027367
## [801,] 0.728956498 0.7020253101
## [802,] 1.049357746 0.7879769590
## [803,] 0.771362958 1.3434890459
## [804,] 1.199931093 0.9221673778
## [805,] 1.430091479 0.3762938613
## [806,] 1.257513988 0.4325145667
## [807,] 0.754867054 1.2956258602
## [808,] 0.934062638 0.9561049521
## [809,] 0.938726361 0.2081227187
## [810,] 0.519795764 0.6320344686
## [811,] 0.561015037 0.6633562975
## [812,] 0.620592325 0.7738696799
## [813,] 0.829262584 1.3617911033
## [814,] 1.105737248 1.3140820491
## [815,] 0.922675237 1.0790878226
## [816,] 1.247587825 0.6817779754
## [817,] 1.019454567 1.1133193937
## [818,] 1.054429648 0.6944558209
## [819,] 1.507155204 0.6733863635
## [820,] 1.705081562 0.8692543658
## [821,] 0.545029848 1.1554825217
## [822,] 1.377059616 1.1105259628
## [823,] 1.262092135 0.8217577322
## [824,] 0.857488905 1.5127306822
## [825,] 0.738293682 0.8604481612
## [826,] 1.117513727 1.2664270034
## [827,] 1.100471091 1.0470350291
## [828,] 1.070073007 1.1747398993
## [829,] 1.234772239 0.9158328837
## [830,] 1.025595913 0.6582218319
## [831,] 1.633596142 0.8723137844
## [832,] 0.795704991 1.4202248911
## [833,] 0.140004009 1.4033839012
## [834,] 1.056591628 1.4576219601
## [835,] 1.359839818 1.0582658342
## [836,] 0.772676830 1.2452445184
## [837,] 1.102860919 0.8662879638
## [838,] 1.132790956 1.0859687323
## [839,] 1.103191383 1.2703469212
## [840,] 0.980945876 0.7908440723
## [841,] 0.839554724 0.7722663235
## [842,] 1.095215012 1.1188761148
## [843,] 0.759163663 0.8342165692
## [844,] 0.596677709 0.6445655542
## [845,] 1.659349285 1.0961304330
## [846,] 0.655497809 0.6963000952
## [847,] 0.866390322 1.2288110127
## [848,] 0.995248801 1.1007130584
## [849,] 0.960405167 0.9270639669
## [850,] 1.285316799 1.0744032208
## [851,] 0.790223336 1.0354050081
## [852,] 1.329583944 0.9961064587
## [853,] 0.592599297 0.3651359760
## [854,] 0.783263437 0.9904663785
## [855,] 1.692486074 1.2857184423
## [856,] 0.649806201 0.6415688223
## [857,] 1.081756964 0.7167710939
## [858,] 0.961179088 1.2375956243
## [859,] 0.676775718 1.3397205721
## [860,] 1.232658949 1.2094537499
## [861,] 1.239194366 1.4107983103
## [862,] 0.914292823 0.9818598504
## [863,] 0.604661346 0.9351242636
## [864,] 1.076290226 0.8198238562
## [865,] 0.938150954 0.8448760607
## [866,] 1.230759962 0.6277322757
## [867,] 1.086165592 0.8705419495
## [868,] 1.201138404 1.1266489243
## [869,] 1.342504482 0.9239955262
## [870,] 0.872230739 1.3845552796
## [871,] 0.915909977 0.7415628193
## [872,] 1.329015742 1.4775344047
## [873,] 1.150426511 1.2747953276
## [874,] 1.355564207 1.0855568541
## [875,] 1.004250329 0.9846981903
## [876,] 0.361436341 1.2716487222
## [877,] 0.160580601 0.5444551201
## [878,] 1.236908662 1.1454781423
## [879,] 0.602607758 0.3664381454
## [880,] 0.951062163 0.4322666261
## [881,] 1.041594286 1.0041388889
## [882,] 0.962772230 0.9280047329
## [883,] 1.049312171 1.1434736470
## [884,] 0.973391523 1.1957922208
## [885,] 0.902079476 1.0160317955
## [886,] 0.074073759 1.6154583700
## [887,] 1.664260696 0.7685139388
## [888,] 1.489200491 0.5838939566
## [889,] 1.040827844 0.5950039861
## [890,] 0.479040202 0.8049609704
## [891,] 1.155253066 0.8112350695
## [892,] 0.820413630 1.0653657951
## [893,] 0.940541297 0.4144157902
## [894,] 0.337309729 1.1878533955
## [895,] 1.202376268 1.0545077863
## [896,] 0.571783480 1.0089418229
## [897,] 0.644180632 0.5917247240
## [898,] 1.525087867 1.4673843290
## [899,] 0.781689024 1.2198277925
## [900,] 1.065973494 0.8829454542
## [901,] 1.013408051 1.0849573045
## [902,] 1.107603020 1.2963566103
## [903,] 0.687056698 1.3571579421
## [904,] 0.907360903 1.0296068992
## [905,] 0.984518347 0.9416036486
## [906,] 1.193464445 1.2600371878
## [907,] 1.175111802 1.3517065272
## [908,] 0.966541761 0.9980599352
## [909,] 1.251351741 1.4533382840
## [910,] 1.536326467 0.8684969734
## [911,] 1.142868032 0.4813177105
## [912,] 1.131675211 1.4814475619
## [913,] 1.083731676 1.0791103269
## [914,] 0.976929084 0.9375829693
## [915,] 0.762072830 0.5938904431
## [916,] 0.677101342 1.5405447335
## [917,] 1.365105959 0.8687579118
## [918,] 0.529873908 0.6680537171
## [919,] 0.853113460 1.1908973829
## [920,] 0.901135789 1.2255536105
## [921,] 1.411284155 1.6372846416
## [922,] 0.618475322 1.4360446577
## [923,] 0.873535642 1.0492699789
## [924,] 1.477427999 1.3467622930
## [925,] 0.696343936 1.0561452466
## [926,] 1.099899559 1.4080294393
## [927,] 1.258750165 1.0436548573
## [928,] 0.931187578 0.7673618525
## [929,] 0.947768765 0.5050333124
## [930,] 1.496285987 1.2719892003
## [931,] 1.051584980 0.8116216327
## [932,] 0.615205034 0.9174881814
## [933,] 1.294901519 1.8343055117
## [934,] 0.647102968 1.0146316195
## [935,] 0.781795871 1.0138506465
## [936,] 1.400493173 0.5902349184
## [937,] 1.061676904 1.1227213367
## [938,] 0.522151409 0.9326362547
## [939,] 0.777976817 0.8382053874
## [940,] 1.079873083 0.9654750875
## [941,] 1.412563279 0.6650130218
## [942,] 1.381152909 0.6128031132
## [943,] 1.121097172 0.7929502375
## [944,] 0.221384680 1.0056066049
## [945,] 1.279092288 0.6397285479
## [946,] 1.627814119 1.1611927215
## [947,] 0.989328316 1.3448083488
## [948,] 1.163257911 0.8917931747
## [949,] 0.862953220 0.4885873011
## [950,] 0.879238448 0.5019810065
## [951,] 1.150984503 0.6785876538
## [952,] 1.343005483 1.3247302541
## [953,] 1.466190325 0.8176502651
## [954,] 0.888798899 1.4723581019
## [955,] 0.974095468 1.2470125122
## [956,] 0.797005947 1.2232223243
## [957,] 0.594030171 1.2220606480
## [958,] 0.940114213 0.8896223861
## [959,] 0.755573658 1.1903738869
## [960,] 1.475931845 0.8068701663
## [961,] 1.144975936 1.1067035869
## [962,] 1.426092606 0.4596544189
## [963,] 1.325043834 0.7957416951
## [964,] 1.131486629 0.9350425683
## [965,] 1.106404465 0.8498018051
## [966,] 1.187590989 0.8113037381
## [967,] 1.427600018 0.8532040407
## [968,] 1.046010689 1.3019106481
## [969,] 1.099485857 0.9673669973
## [970,] 0.947902233 1.6237788678
## [971,] 1.092367998 0.6808943682
## [972,] 1.426739447 1.2484748795
## [973,] 1.398441389 0.7986984891
## [974,] 1.455360873 1.4913132523
## [975,] 0.403436571 0.3708279843
## [976,] 1.227301037 0.9566303233
## [977,] 1.101938974 1.3407837597
## [978,] 0.227691282 0.9143315697
## [979,] 0.601999387 0.9417849501
## [980,] 1.186159999 1.1639765571
## [981,] 0.825447841 0.7245679624
## [982,] 1.453252662 1.4072111929
## [983,] 1.211721323 1.0033417258
## [984,] 1.009508789 1.0759145159
## [985,] 0.735862977 0.6596884623
## [986,] 0.958768736 1.1307803929
## [987,] 1.450956399 1.3930882187
## [988,] 1.166834000 0.8263049482
## [989,] 0.805427599 0.5325897092
## [990,] 1.247356771 0.4696895970
## [991,] 0.390662039 0.1431184189
## [992,] 0.624241171 1.0796027496
## [993,] 1.318209943 1.3264344523
## [994,] 1.090644960 1.5405509848
## [995,] 1.015038254 1.2304717623
## [996,] 0.865590263 0.8042089024
## [997,] 1.144665502 1.0144559132
## [998,] 0.971495458 0.8896675702
## [999,] 1.112000256 1.3418343682
## [1000,] 1.076301086 1.0546752971
fit <- kmeans(x,100)
fit
## K-means clustering with 100 clusters of sizes 11, 12, 10, 6, 12, 5, 15, 15, 8, 14, 4, 9, 8, 8, 12, 6, 11, 6, 18, 14, 7, 8, 2, 9, 16, 6, 9, 16, 7, 5, 10, 9, 13, 7, 18, 11, 10, 4, 7, 12, 11, 8, 10, 11, 14, 7, 9, 13, 15, 11, 7, 8, 15, 5, 5, 17, 11, 12, 7, 1, 12, 4, 12, 5, 2, 19, 14, 10, 13, 12, 4, 3, 12, 10, 8, 9, 10, 9, 7, 12, 11, 10, 13, 8, 17, 13, 15, 14, 7, 18, 15, 11, 7, 7, 20, 8, 1, 14, 10, 7
##
## Cluster means:
## [,1] [,2]
## 1 -0.26617934 -0.35191003
## 2 1.09359832 1.01237158
## 3 1.38265531 0.91302182
## 4 0.57264339 1.16932053
## 5 0.11484482 0.45743047
## 6 0.40185641 1.21352241
## 7 0.01410535 -0.35210310
## 8 1.13916255 1.29837023
## 9 1.49039124 1.34360359
## 10 0.28274764 -0.12562970
## 11 1.09329550 1.84199120
## 12 0.98698528 1.24490087
## 13 1.65712318 1.17150552
## 14 1.28345229 0.81146748
## 15 -0.26028874 0.21639235
## 16 -0.37907845 -0.62618251
## 17 0.17341002 -0.44916672
## 18 1.44489994 0.60940559
## 19 0.09446360 0.12399304
## 20 1.18432309 1.13367160
## 21 1.65476439 0.91834837
## 22 0.39462047 -0.51011594
## 23 0.01633218 -0.97680038
## 24 0.57569401 0.18801918
## 25 0.23573400 0.03942821
## 26 0.77576590 1.32422762
## 27 0.47182125 -0.13385250
## 28 0.02282255 0.27766418
## 29 0.86446875 1.23284871
## 30 0.66048705 1.37060977
## 31 -0.44792440 -0.40845578
## 32 0.87043995 1.07989373
## 33 0.09492996 -0.19841447
## 34 0.57063829 0.40909963
## 35 -0.02607655 0.02338085
## 36 1.20251734 0.67201919
## 37 0.39608258 0.10441947
## 38 1.21571712 0.43195406
## 39 0.48176429 0.71023277
## 40 0.85902652 0.75492996
## 41 0.97011375 0.40736120
## 42 -0.11240996 -0.50317997
## 43 0.67038088 1.06887199
## 44 -0.19174853 -0.22682232
## 45 1.04825088 0.68129398
## 46 -0.52058639 0.03176441
## 47 0.81076875 0.45538963
## 48 1.03281677 0.80568057
## 49 -0.15564042 0.09260577
## 50 0.69150527 0.63601004
## 51 0.07169488 0.63540758
## 52 1.07795171 1.15781954
## 53 0.99722398 0.94381593
## 54 1.49693143 0.36093110
## 55 0.42279662 0.31490966
## 56 0.23443497 0.25023629
## 57 0.93179682 0.99813991
## 58 -0.57635903 -0.15684905
## 59 1.49070138 1.53625503
## 60 -0.23851136 0.75092476
## 61 -0.01760782 0.42999916
## 62 -0.66502217 0.06576671
## 63 0.85333872 1.45967859
## 64 -0.45291804 0.55128254
## 65 0.74700714 0.01774589
## 66 -0.04426906 -0.15607786
## 67 -0.06963209 0.16298911
## 68 0.92761237 0.87970828
## 69 -0.12316446 -0.08460701
## 70 1.02753970 1.36674524
## 71 0.62754063 1.54307177
## 72 0.11860504 1.43361904
## 73 1.36973694 1.24341317
## 74 0.77067836 1.19256105
## 75 0.59548786 -0.27462300
## 76 1.02960741 1.08845768
## 77 -0.37796815 0.38047038
## 78 1.05418610 1.54254689
## 79 1.05709460 0.57902442
## 80 1.33349045 1.07309861
## 81 0.58370761 0.92031511
## 82 -0.17747996 0.43907175
## 83 -0.37240953 -0.14643306
## 84 1.27831122 1.44911941
## 85 -0.32868189 0.08585790
## 86 0.70972317 0.82137655
## 87 1.13616189 0.85666441
## 88 -0.28411435 -0.06664638
## 89 1.46889260 1.00367576
## 90 0.09643342 -0.07338241
## 91 0.79152910 0.98436257
## 92 1.47101372 0.81859480
## 93 0.27850473 0.88808428
## 94 0.89223489 0.62228651
## 95 0.29571401 -0.30071027
## 96 1.22623766 0.94492925
## 97 -0.88252899 0.35259699
## 98 -0.13478414 0.27193764
## 99 0.32322084 0.48295757
## 100 0.95302188 1.17477717
##
## Clustering vector:
## [1] 88 42 66 58 35 82 15 98 42 7 69 82 25 83 15 51 66
## [18] 7 85 56 56 77 56 67 90 69 25 82 69 10 88 37 46 83
## [35] 58 22 95 49 55 97 82 67 7 99 5 35 1 88 15 10 10
## [52] 44 77 24 83 35 51 37 90 28 1 95 49 99 42 7 24 58
## [69] 27 61 67 58 16 90 82 49 35 90 75 19 66 90 15 35 51
## [86] 82 44 62 25 98 66 7 33 28 83 64 75 58 16 16 33 19
## [103] 17 7 99 49 85 75 35 77 99 1 88 19 27 66 22 25 10
## [120] 5 22 98 56 90 61 17 1 85 24 69 28 31 90 28 69 25
## [137] 10 66 51 27 27 28 28 46 33 5 66 75 88 65 95 49 15
## [154] 25 83 27 34 15 56 33 90 49 85 95 75 85 95 7 85 22
## [171] 33 98 33 19 28 98 83 95 93 17 61 98 88 19 67 66 17
## [188] 19 66 95 56 10 93 42 49 22 28 19 44 82 66 42 10 83
## [205] 98 69 15 85 69 47 31 49 49 44 33 69 37 35 62 58 99
## [222] 22 67 1 85 28 83 35 25 22 55 61 37 66 67 98 77 37
## [239] 44 95 34 35 90 28 17 16 42 85 44 37 61 90 85 25 64
## [256] 46 95 25 95 64 23 7 66 62 82 44 25 56 35 10 90 88
## [273] 90 77 65 83 85 19 17 10 19 88 1 17 60 28 58 67 95
## [290] 95 25 15 15 95 67 1 49 19 31 85 61 44 24 24 88 31
## [307] 85 7 10 44 10 5 7 44 75 95 31 17 19 66 19 77 77
## [324] 17 19 49 35 82 58 56 98 22 15 34 88 35 10 35 95 24
## [341] 51 5 67 35 25 5 69 46 7 1 88 99 90 49 16 67 31
## [358] 90 27 99 33 7 75 5 56 90 25 5 46 98 95 19 83 98
## [375] 31 37 35 35 99 42 67 25 31 61 64 58 99 85 66 55 27
## [392] 85 64 69 33 83 33 24 98 69 28 24 10 5 7 7 42 61
## [409] 37 28 17 19 16 19 67 44 66 49 25 98 66 28 61 33 77
## [426] 46 7 56 51 99 69 69 49 66 56 15 15 1 95 88 83 77
## [443] 19 67 56 90 66 88 98 56 56 75 83 10 61 27 37 46 31
## [460] 5 56 5 85 17 31 61 56 1 88 19 58 90 90 67 1 62
## [477] 66 95 33 49 28 35 47 56 82 58 51 25 35 24 27 33 28
## [494] 23 95 77 58 61 85 95 70 91 8 87 3 68 70 53 32 47
## [511] 48 50 92 84 86 54 63 93 32 47 36 70 45 45 76 80 68
## [528] 45 71 13 48 18 89 53 68 4 20 45 79 96 84 96 73 45
## [545] 70 13 6 73 100 73 6 41 74 63 63 68 20 78 50 70 100
## [562] 36 87 76 14 70 47 53 13 48 11 38 53 30 2 57 8 86
## [579] 63 80 94 8 59 53 59 57 45 50 36 29 70 81 52 80 84
## [596] 45 2 55 78 8 52 92 40 52 57 3 53 76 50 12 94 89
## [613] 73 3 43 86 21 32 21 57 29 70 12 91 70 40 43 14 8
## [630] 14 89 68 86 34 45 20 48 3 39 8 91 94 79 76 91 13
## [647] 100 53 2 94 73 94 74 91 68 79 20 73 21 54 14 53 21
## [664] 47 43 93 96 87 52 20 40 81 9 32 63 4 11 87 63 32
## [681] 91 86 86 92 14 12 48 32 34 80 4 40 59 86 41 73 9
## [698] 12 81 53 73 79 84 48 81 74 9 45 93 72 59 91 39 9
## [715] 2 78 78 40 89 2 41 43 89 92 48 3 40 36 89 36 26
## [732] 36 91 41 86 3 79 4 92 91 48 36 94 68 91 78 20 13
## [749] 14 30 53 3 63 43 29 41 81 86 92 100 40 80 100 39 74
## [766] 12 91 48 54 57 6 3 80 96 41 74 63 87 74 41 2 26
## [783] 12 94 26 57 73 91 43 71 43 81 84 11 29 79 89 71 20
## [800] 45 50 48 26 96 54 38 26 57 41 39 39 86 26 8 32 36
## [817] 76 45 18 21 4 80 14 63 86 8 2 52 96 45 21 63 72
## [834] 78 80 74 87 20 8 48 40 52 86 50 13 50 29 76 53 80
## [851] 91 80 34 91 13 50 45 12 30 20 84 57 81 48 68 36 87
## [868] 20 3 63 40 84 8 80 53 6 5 20 34 41 2 53 52 100
## [885] 57 72 21 18 79 39 87 32 41 6 20 81 50 59 74 87 76
## [902] 8 30 57 53 8 8 57 84 92 38 78 76 53 50 71 3 39
## [919] 29 29 59 30 32 9 43 70 80 40 41 9 48 81 11 43 91
## [936] 18 52 81 86 2 18 18 87 93 36 13 70 87 47 47 36 73
## [953] 92 63 12 74 4 68 74 92 20 54 14 87 87 87 92 70 2
## [970] 78 45 73 92 59 55 96 8 93 81 20 40 9 96 76 50 100
## [987] 9 87 47 38 37 43 73 78 12 40 2 68 8 2
##
## Within cluster sum of squares by cluster:
## [1] 0.057897476 0.022633876 0.017947630 0.028682234 0.047320776
## [6] 0.024581316 0.073564248 0.035694617 0.028703887 0.053435903
## [11] 0.112911345 0.010851556 0.066307322 0.023264995 0.053585321
## [16] 0.039839694 0.073478882 0.028418170 0.052539608 0.035002146
## [21] 0.055674361 0.081175488 0.026134020 0.044041934 0.048340189
## [26] 0.015856581 0.051810060 0.064125426 0.010630242 0.011553181
## [31] 0.100857109 0.016086477 0.035428517 0.020605043 0.050478406
## [36] 0.044707951 0.034158842 0.019600658 0.049242509 0.032059299
## [41] 0.083799811 0.029291397 0.017727410 0.045104768 0.029743397
## [46] 0.025364658 0.060669357 0.026631747 0.046034957 0.054586421
## [51] 0.034922176 0.016886644 0.021173627 0.147292177 0.017108664
## [56] 0.093079586 0.015303556 0.072678973 0.093019915 0.000000000
## [61] 0.038187296 0.033363714 0.072565858 0.066831852 0.013434728
## [66] 0.049585251 0.029831109 0.020518018 0.029205886 0.043429302
## [71] 0.016101497 0.059939590 0.065172341 0.022596209 0.064045789
## [76] 0.007698713 0.081457617 0.077285933 0.009714804 0.037172634
## [81] 0.046370726 0.049514471 0.050374828 0.018375984 0.059347997
## [86] 0.041911503 0.047460765 0.030376372 0.021589953 0.051618580
## [91] 0.047567325 0.052536720 0.059549962 0.018080208 0.098448383
## [96] 0.011491981 0.000000000 0.035913236 0.061788490 0.008668759
## (between_SS / total_SS = 99.4 %)
##
## Available components:
##
## [1] "cluster" "centers" "totss" "withinss"
## [5] "tot.withinss" "betweenss" "size" "iter"
## [9] "ifault"
k medoid clustering
library(cluster)
all <- read.table("snps.txt", header=T,sep="\t")
result <- pam(all, 2, FALSE, "euclidean")
result
## Medoids:
## ID name allele1 allele2
## [1,] 13 5 2 2
## [2,] 5 14 3 3
## Clustering vector:
## [1] 1 2 2 2 2 2 2 2 2 1 1 1 1 1 1 1 1 2
## Objective function:
## build swap
## 3.087855 2.508287
##
## Available components:
## [1] "medoids" "id.med" "clustering" "objective" "isolation"
## [6] "clusinfo" "silinfo" "diss" "call" "data"
summary(result)
## Medoids:
## ID name allele1 allele2
## [1,] 13 5 2 2
## [2,] 5 14 3 3
## Clustering vector:
## [1] 1 2 2 2 2 2 2 2 2 1 1 1 1 1 1 1 1 2
## Objective function:
## build swap
## 3.087855 2.508287
##
## Numerical information per cluster:
## size max_diss av_diss diameter separation
## [1,] 9 4.242641 2.512493 8.124038 1
## [2,] 9 4.898979 2.504081 8.485281 1
##
## Isolated clusters:
## L-clusters: character(0)
## L*-clusters: character(0)
##
## Silhouette plot information:
## cluster neighbor sil_width
## 12 1 2 0.70505808
## 11 1 2 0.70097518
## 13 1 2 0.68851254
## 10 1 2 0.68056010
## 1 1 2 0.63944310
## 14 1 2 0.63538460
## 15 1 2 0.46908273
## 16 1 2 0.35730302
## 17 1 2 0.06532298
## 6 2 1 0.70559746
## 7 2 1 0.70088387
## 5 2 1 0.69051866
## 8 2 1 0.67395882
## 4 2 1 0.64632654
## 9 2 1 0.60774245
## 3 2 1 0.53758572
## 2 2 1 0.37584267
## 18 2 1 0.09361645
## Average silhouette width per cluster:
## [1] 0.5490714 0.5591192
## Average silhouette width of total data set:
## [1] 0.5540953
##
## 153 dissimilarities, summarized :
## Min. 1st Qu. Median Mean 3rd Qu. Max.
## 1.000 3.162 6.000 6.554 9.110 17.059
## Metric : euclidean
## Number of objects : 18
##
## Available components:
## [1] "medoids" "id.med" "clustering" "objective" "isolation"
## [6] "clusinfo" "silinfo" "diss" "call" "data"
plot(result$data, col = result$clustering)
Hierarchical clustering
dat <- matrix(rnorm(500), nrow=50, ncol=10)
dat
## [,1] [,2] [,3] [,4] [,5]
## [1,] 1.104797535 0.63787505 1.32465334 -0.25992335 -0.007320741
## [2,] -0.638433884 0.95061273 0.52292022 0.17514650 0.435569501
## [3,] -2.021707903 -0.77850734 -0.51801442 1.10097672 0.691677214
## [4,] 1.019227776 1.71111709 0.38055854 0.44028900 0.433922698
## [5,] 1.048120526 1.09481962 -1.68762001 0.61746647 0.162703017
## [6,] 0.422329491 -0.32101248 -0.23729926 0.99853886 0.596124149
## [7,] 1.715203772 -0.03371737 -1.65854441 -0.47806956 0.323289217
## [8,] 0.857493896 0.79314703 -2.15846227 0.26335257 -2.212372883
## [9,] -0.704869937 0.86180800 0.47720567 0.90167346 2.092521081
## [10,] -0.529457370 -0.68268225 0.44040894 1.17657372 1.543582069
## [11,] -0.333237109 -0.20054647 0.44268528 0.37247847 0.486138736
## [12,] -1.079332006 1.49654184 0.56427818 -0.83427277 0.505108830
## [13,] 0.634255302 -0.02736137 -1.42541593 -0.05457677 0.737447725
## [14,] 0.322512677 -0.40967147 -0.00152185 0.38504078 0.690064577
## [15,] -1.531934111 1.66264116 1.43652229 -1.25082658 -0.835219052
## [16,] -0.777980920 -0.50712455 1.48106801 0.93846973 -0.039813872
## [17,] -1.370740161 -2.28435991 0.49800635 -1.15625703 -0.520810315
## [18,] 0.291441813 -0.21536996 -2.23817956 -1.13951256 0.541866967
## [19,] -0.121916635 -1.42268046 -0.64909492 -0.75554282 -0.102022074
## [20,] -0.407345541 -0.10970670 0.77514355 1.06781957 0.183143787
## [21,] 0.009500766 0.40119358 0.47077325 -0.22033991 1.433699912
## [22,] -0.605192986 0.12504966 -0.31059586 -0.06843142 0.393997199
## [23,] 0.126785728 -0.49754578 1.37070084 1.35362496 0.213009955
## [24,] -0.117273200 -1.18604245 -2.33241843 -0.31624999 0.515226004
## [25,] -0.217383365 -1.22240081 0.35384684 -1.84560143 -1.940444258
## [26,] 1.052677507 0.55642459 0.52527402 1.18728119 -1.838557784
## [27,] 1.135699100 0.88366640 -0.27493314 0.62232672 -1.552886027
## [28,] -1.260257972 -1.47211104 -1.23902710 -1.43913253 -0.805754735
## [29,] -0.982368301 0.07255701 0.09464866 -0.54286234 -1.258337764
## [30,] 0.321521747 -0.43689189 -0.39133650 0.59269900 1.720407125
## [31,] 0.154625634 -0.48636477 -0.25950773 2.69057794 -0.556879930
## [32,] -1.061863911 -0.66699457 0.66973499 0.76459266 -0.747863657
## [33,] -0.457305326 -0.22214139 0.03409044 -0.78491148 -0.733648370
## [34,] -0.736272290 -0.11004995 1.80494021 -0.41299414 1.081906838
## [35,] 0.849040550 -0.60756910 0.35677233 0.78016506 -0.051792206
## [36,] -2.338840060 -0.16804619 0.90469345 -1.46141846 -1.656513489
## [37,] -2.472918585 -0.31390118 -2.08125799 1.77166015 -0.072396919
## [38,] -2.216327354 1.14453264 -0.98494022 0.01055371 -0.409199484
## [39,] -2.037112840 -0.41184555 0.96394814 2.25156777 0.097243363
## [40,] 1.239702085 0.28817084 0.24705372 -0.22815373 1.748506193
## [41,] 0.984387787 -1.46653647 -1.51321835 -0.90992563 -1.960247259
## [42,] -1.761246049 0.81642555 -0.68560249 -1.04490090 -2.024400792
## [43,] 0.080012937 -0.51216665 0.27789593 1.19661811 -0.813865639
## [44,] -0.120125451 -0.49180348 -0.18822432 1.32262506 1.094092451
## [45,] -0.353031494 0.53231789 2.65639116 1.16040198 0.692426537
## [46,] -0.483383107 0.16159368 1.30021130 0.70068368 0.063998526
## [47,] -1.965545164 -0.11589754 0.89684067 -0.40691379 -0.083085823
## [48,] -0.559672753 -0.26826424 0.75026828 0.71223381 -1.497730455
## [49,] 1.869963115 0.23141846 0.59864835 -0.81426515 -0.162971475
## [50,] 0.048185182 0.18263742 1.81664831 -1.03148670 0.780833096
## [,6] [,7] [,8] [,9] [,10]
## [1,] -0.26737192 -0.82279100 -0.945755480 0.09437026 0.58207625
## [2,] -0.11221575 -0.64528347 -1.803507024 -1.25336569 1.06473816
## [3,] -1.47929116 2.43197764 1.611013295 2.45091692 -0.60510123
## [4,] 0.55829114 -1.02660328 0.258008895 0.95411582 0.19945536
## [5,] 0.83161052 0.87100896 -0.765632581 2.04072845 0.52767667
## [6,] -0.11278553 -1.35742314 -1.418208589 -0.07394035 -2.26198024
## [7,] -0.04785735 0.82297396 1.100363065 0.15232761 -2.21732453
## [8,] -0.67473476 0.66250542 0.167627637 -0.38784192 1.70116532
## [9,] -2.61457860 -1.58894275 -0.186432860 1.23748883 -0.59746149
## [10,] 1.09891523 0.22853225 -1.352267185 0.54320457 0.18732458
## [11,] 0.92329594 -1.74275080 0.884215856 1.07834535 0.49112664
## [12,] -0.07930201 0.42953484 0.531027645 -1.10967590 1.81924609
## [13,] -0.26327625 0.10758705 1.658734844 -0.64729778 -0.48395916
## [14,] -0.34218879 0.62004651 -1.741474005 0.13080102 -0.76000340
## [15,] -0.93483806 -0.85557134 1.493576198 -0.06253494 1.22857495
## [16,] -0.06169878 -0.38896284 -1.232636077 0.74197605 0.46853798
## [17,] -1.50969611 -0.72895698 0.027939618 -0.83649695 -2.01353439
## [18,] -1.15153283 0.98736098 0.775497248 -1.23147911 -0.27197819
## [19,] 0.23258530 -0.92936214 -0.377447373 0.05508135 -0.25757350
## [20,] 1.52923053 -1.97807610 1.768223112 -0.20562734 -0.84978031
## [21,] -0.04584245 -1.54323936 2.041499750 -0.08982952 -1.44626868
## [22,] -0.33892771 -1.44637922 0.001020245 -1.20592128 -0.55419720
## [23,] 0.93623313 -0.29848778 1.024025762 0.22832894 0.04792215
## [24,] 1.11621466 -0.49599548 1.166253764 -1.63741551 0.43505975
## [25,] 1.76356584 -0.03863671 -0.458777508 2.37714582 0.90735656
## [26,] 0.35942351 0.06583886 -1.489813928 -0.16367133 0.43111535
## [27,] 0.32909443 0.39247755 0.997393088 0.14204676 0.14490740
## [28,] -2.27039937 0.33608990 0.111351925 -0.81001621 0.98356721
## [29,] -0.88028861 -0.89989057 1.480715004 1.73354433 0.44803709
## [30,] 0.38362170 0.93363150 -2.001014335 0.92523531 -0.19176666
## [31,] 0.34720435 0.37341456 0.097776314 0.87435382 0.29157498
## [32,] -0.37840859 0.43747426 -1.908511364 -0.57113012 1.04413588
## [33,] -0.59076038 -1.62019769 -1.123747150 0.06793347 1.06000312
## [34,] -0.79918627 0.68311924 -0.338626555 -1.22330558 0.08817845
## [35,] 1.46458492 -0.17965817 0.632656319 -0.78775485 -0.55729490
## [36,] 0.40572861 0.39406253 -0.481221693 -0.93515238 0.02216662
## [37,] 1.40419937 0.29076114 1.074151565 0.97628128 0.66119869
## [38,] -0.11800518 0.19088493 0.818221363 -0.66880842 -0.07542987
## [39,] 0.70632842 -0.16176184 0.535107073 -0.23663230 -1.21406617
## [40,] 0.36760863 -1.04174195 -1.390887490 -0.61977418 -1.83030212
## [41,] -1.33889188 -0.72090035 0.439255160 1.05452255 1.80144957
## [42,] -0.86993438 -0.98622660 0.080764878 0.17933073 0.30288079
## [43,] 0.12772454 1.95166227 0.079850029 -0.69208549 -0.64995185
## [44,] 0.27190270 -1.71450382 -0.810329064 0.83084106 -0.15635790
## [45,] -0.94603456 1.28443779 -0.126174578 2.43496653 -0.67303033
## [46,] 0.06237562 0.07322864 -1.042467206 -1.82602624 0.39048600
## [47,] -1.52558285 -0.57034221 -0.299680479 -1.21577893 1.84000261
## [48,] -0.50030378 0.26970598 -0.115909185 0.52715478 -0.86367223
## [49,] 0.51866300 -0.40700665 -0.117779514 -0.45633651 1.22055768
## [50,] 0.25866693 0.97662624 -1.436576414 0.17436868 0.79637555
hc <- hclust(dist(dat))
hc
##
## Call:
## hclust(d = dist(dat))
##
## Cluster method : complete
## Distance : euclidean
## Number of objects: 50
plot(hc)
Expectation-maximization
library(mclust)
## Package 'mclust' version 5.3
## Type 'citation("mclust")' for citing this R package in publications.
data("mtcars")
head(mtcars)
## mpg cyl disp hp drat wt qsec vs am gear carb
## Mazda RX4 21.0 6 160 110 3.90 2.620 16.46 0 1 4 4
## Mazda RX4 Wag 21.0 6 160 110 3.90 2.875 17.02 0 1 4 4
## Datsun 710 22.8 4 108 93 3.85 2.320 18.61 1 1 4 1
## Hornet 4 Drive 21.4 6 258 110 3.08 3.215 19.44 1 0 3 1
## Hornet Sportabout 18.7 8 360 175 3.15 3.440 17.02 0 0 3 2
## Valiant 18.1 6 225 105 2.76 3.460 20.22 1 0 3 1
str(mtcars)
## 'data.frame': 32 obs. of 11 variables:
## $ mpg : num 21 21 22.8 21.4 18.7 18.1 14.3 24.4 22.8 19.2 ...
## $ cyl : num 6 6 4 6 8 6 8 4 4 6 ...
## $ disp: num 160 160 108 258 360 ...
## $ hp : num 110 110 93 110 175 105 245 62 95 123 ...
## $ drat: num 3.9 3.9 3.85 3.08 3.15 2.76 3.21 3.69 3.92 3.92 ...
## $ wt : num 2.62 2.88 2.32 3.21 3.44 ...
## $ qsec: num 16.5 17 18.6 19.4 17 ...
## $ vs : num 0 0 1 1 0 1 0 1 1 1 ...
## $ am : num 1 1 1 0 0 0 0 0 0 0 ...
## $ gear: num 4 4 4 3 3 3 3 4 4 4 ...
## $ carb: num 4 4 1 1 2 1 4 2 2 4 ...
fit <- Mclust(mtcars)
fit
## 'Mclust' model object:
## best model: ellipsoidal, equal shape (VEV) with 4 components
summary(fit)
## ----------------------------------------------------
## Gaussian finite mixture model fitted by EM algorithm
## ----------------------------------------------------
##
## Mclust VEV (ellipsoidal, equal shape) model with 4 components:
##
## log.likelihood n df BIC ICL
## -71.24536 32 281 -1116.363 -1116.363
##
## Clustering table:
## 1 2 3 4
## 12 7 9 4
d <- density(mtcars$mpg)
d
##
## Call:
## density.default(x = mtcars$mpg)
##
## Data: mtcars$mpg (32 obs.); Bandwidth 'bw' = 2.477
##
## x y
## Min. : 2.97 Min. :6.481e-05
## 1st Qu.:12.56 1st Qu.:5.461e-03
## Median :22.15 Median :1.926e-02
## Mean :22.15 Mean :2.604e-02
## 3rd Qu.:31.74 3rd Qu.:4.530e-02
## Max. :41.33 Max. :6.795e-02
plot(d)
Anomaly detection
y <- rnorm(1000)
boxplot(y)
identify(rep(1, length(y)), y, labels = seq_along(y))
## integer(0)
x <- rnorm(1000)
summary(x)
## Min. 1st Qu. Median Mean 3rd Qu. Max.
## -2.789995 -0.667856 -0.032975 -0.008402 0.643473 3.932214
boxplot.stats(x)$out
## [1] -2.780705 3.468434 3.932214 -2.789995
boxplot(x)
boxplot(mpg~cyl,data=mtcars, xlab="Cylinders", ylab="MPG")
x <- rnorm(10000)
y <- rnorm(10000)
f <- data.frame(x,y)
a <- boxplot.stats(x)$out
b <- boxplot.stats(y)$out
list <- union(a,b)
plot(f)
px <- f[f$x %in% a,]
py <- f[f$y %in% b,]
p <- rbind(px,py)
par(new=TRUE)
plot(p$x, p$y,cex=2,col=2)
Calculating anomalies
data("women")
str(women)
## 'data.frame': 15 obs. of 2 variables:
## $ height: num 58 59 60 61 62 63 64 65 66 67 ...
## $ weight: num 115 117 120 123 126 129 132 135 139 142 ...
head(women)
## height weight
## 1 58 115
## 2 59 117
## 3 60 120
## 4 61 123
## 5 62 126
## 6 63 129
summary(women)
## height weight
## Min. :58.0 Min. :115.0
## 1st Qu.:61.5 1st Qu.:124.5
## Median :65.0 Median :135.0
## Mean :65.0 Mean :136.7
## 3rd Qu.:68.5 3rd Qu.:148.0
## Max. :72.0 Max. :164.0
outliers <- function(women, low, high) {
outs <- subset(women, women$height < low | women$height > high)
return(outs)
}
outliers(women, 60, 70)
## height weight
## 1 58 115
## 2 59 117
## 14 71 159
## 15 72 164
library(DMwR)
## Loading required package: lattice
## Loading required package: grid
str(mtcars)
## 'data.frame': 32 obs. of 11 variables:
## $ mpg : num 21 21 22.8 21.4 18.7 18.1 14.3 24.4 22.8 19.2 ...
## $ cyl : num 6 6 4 6 8 6 8 4 4 6 ...
## $ disp: num 160 160 108 258 360 ...
## $ hp : num 110 110 93 110 175 105 245 62 95 123 ...
## $ drat: num 3.9 3.9 3.85 3.08 3.15 2.76 3.21 3.69 3.92 3.92 ...
## $ wt : num 2.62 2.88 2.32 3.21 3.44 ...
## $ qsec: num 16.5 17 18.6 19.4 17 ...
## $ vs : num 0 0 1 1 0 1 0 1 1 1 ...
## $ am : num 1 1 1 0 0 0 0 0 0 0 ...
## $ gear: num 4 4 4 3 3 3 3 4 4 4 ...
## $ carb: num 4 4 1 1 2 1 4 2 2 4 ...
scores <- lofactor(mtcars, k=3)
plot(density(scores))
Association rules
library(arules)
## Loading required package: Matrix
##
## Attaching package: 'arules'
## The following objects are masked from 'package:base':
##
## abbreviate, write
data <- read.csv("http://www.salemmarafi.com/wp-content/uploads/2014/03/groceries.csv")
rules <- apriori(data)
## Apriori
##
## Parameter specification:
## confidence minval smax arem aval originalSupport maxtime support minlen
## 0.8 0.1 1 none FALSE TRUE 5 0.1 1
## maxlen target ext
## 10 rules FALSE
##
## Algorithmic control:
## filter tree heap memopt load sort verbose
## 0.1 TRUE TRUE FALSE TRUE 2 TRUE
##
## Absolute minimum support count: 1529
##
## set item appearances ...[0 item(s)] done [0.00s].
## set transactions ...[655 item(s), 15295 transaction(s)] done [0.00s].
## sorting and recoding items ... [3 item(s)] done [0.00s].
## creating transaction tree ... done [0.00s].
## checking subsets of size 1 2 3 done [0.00s].
## writing ... [5 rule(s)] done [0.00s].
## creating S4 object ... done [0.00s].
rules
## set of 5 rules
inspect(rules)
## lhs rhs support
## [1] {semi.finished.bread=} => {margarine=} 0.2278522
## [2] {semi.finished.bread=} => {ready.soups=} 0.2278522
## [3] {margarine=} => {ready.soups=} 0.3998039
## [4] {semi.finished.bread=,margarine=} => {ready.soups=} 0.2278522
## [5] {semi.finished.bread=,ready.soups=} => {margarine=} 0.2278522
## confidence lift
## [1] 1 2.501226
## [2] 1 1.861385
## [3] 1 1.861385
## [4] 1 1.861385
## [5] 1 2.501226
rules2 <- apriori(data, parameter = list(supp = 0.01, conf = 0.8))
## Apriori
##
## Parameter specification:
## confidence minval smax arem aval originalSupport maxtime support minlen
## 0.8 0.1 1 none FALSE TRUE 5 0.01 1
## maxlen target ext
## 10 rules FALSE
##
## Algorithmic control:
## filter tree heap memopt load sort verbose
## 0.1 TRUE TRUE FALSE TRUE 2 TRUE
##
## Absolute minimum support count: 152
##
## set item appearances ...[0 item(s)] done [0.00s].
## set transactions ...[655 item(s), 15295 transaction(s)] done [0.00s].
## sorting and recoding items ... [75 item(s)] done [0.00s].
## creating transaction tree ... done [0.01s].
## checking subsets of size 1 2 3 4 done [0.00s].
## writing ... [68 rule(s)] done [0.00s].
## creating S4 object ... done [0.00s].
inspect(rules2)
## lhs rhs support confidence lift
## [1] {semi.finished.bread=newspapers} => {margarine=} 0.01157241 0.8894472 2.224709
## [2] {semi.finished.bread=newspapers} => {ready.soups=} 0.01294541 0.9949749 1.852031
## [3] {citrus.fruit=newspapers} => {semi.finished.bread=} 0.01203008 0.8932039 3.920101
## [4] {citrus.fruit=newspapers} => {margarine=} 0.01346845 1.0000000 2.501226
## [5] {citrus.fruit=newspapers} => {ready.soups=} 0.01346845 1.0000000 1.861385
## [6] {margarine=newspapers} => {ready.soups=} 0.01203008 0.8720379 1.623198
## [7] {semi.finished.bread=shopping bags} => {margarine=} 0.01497221 1.0000000 2.501226
## [8] {semi.finished.bread=shopping bags} => {ready.soups=} 0.01497221 1.0000000 1.861385
## [9] {margarine=shopping bags} => {ready.soups=} 0.01641059 1.0000000 1.861385
## [10] {citrus.fruit=shopping bags} => {semi.finished.bread=} 0.01765283 1.0000000 4.388809
## [11] {citrus.fruit=shopping bags} => {margarine=} 0.01765283 1.0000000 2.501226
## [12] {citrus.fruit=shopping bags} => {ready.soups=} 0.01765283 1.0000000 1.861385
## [13] {citrus.fruit=bottled beer} => {margarine=} 0.01595293 0.8215488 2.054880
## [14] {citrus.fruit=bottled beer} => {ready.soups=} 0.01824126 0.9393939 1.748574
## [15] {citrus.fruit=canned beer} => {margarine=} 0.02262177 0.8917526 2.230475
## [16] {citrus.fruit=canned beer} => {ready.soups=} 0.02451782 0.9664948 1.799019
## [17] {citrus.fruit=soda} => {ready.soups=} 0.03059823 0.8509091 1.583869
## [18] {semi.finished.bread=} => {margarine=} 0.22785224 1.0000000 2.501226
## [19] {semi.finished.bread=} => {ready.soups=} 0.22785224 1.0000000 1.861385
## [20] {margarine=} => {ready.soups=} 0.39980386 1.0000000 1.861385
## [21] {semi.finished.bread=newspapers,
## margarine=} => {ready.soups=} 0.01157241 1.0000000 1.861385
## [22] {semi.finished.bread=newspapers,
## ready.soups=} => {margarine=} 0.01157241 0.8939394 2.235945
## [23] {citrus.fruit=newspapers,
## semi.finished.bread=} => {margarine=} 0.01203008 1.0000000 2.501226
## [24] {citrus.fruit=newspapers,
## margarine=} => {semi.finished.bread=} 0.01203008 0.8932039 3.920101
## [25] {citrus.fruit=newspapers,
## semi.finished.bread=} => {ready.soups=} 0.01203008 1.0000000 1.861385
## [26] {citrus.fruit=newspapers,
## ready.soups=} => {semi.finished.bread=} 0.01203008 0.8932039 3.920101
## [27] {citrus.fruit=newspapers,
## margarine=} => {ready.soups=} 0.01346845 1.0000000 1.861385
## [28] {citrus.fruit=newspapers,
## ready.soups=} => {margarine=} 0.01346845 1.0000000 2.501226
## [29] {semi.finished.bread=shopping bags,
## margarine=} => {ready.soups=} 0.01497221 1.0000000 1.861385
## [30] {semi.finished.bread=shopping bags,
## ready.soups=} => {margarine=} 0.01497221 1.0000000 2.501226
## [31] {citrus.fruit=shopping bags,
## semi.finished.bread=} => {margarine=} 0.01765283 1.0000000 2.501226
## [32] {citrus.fruit=shopping bags,
## margarine=} => {semi.finished.bread=} 0.01765283 1.0000000 4.388809
## [33] {citrus.fruit=shopping bags,
## semi.finished.bread=} => {ready.soups=} 0.01765283 1.0000000 1.861385
## [34] {citrus.fruit=shopping bags,
## ready.soups=} => {semi.finished.bread=} 0.01765283 1.0000000 4.388809
## [35] {citrus.fruit=shopping bags,
## margarine=} => {ready.soups=} 0.01765283 1.0000000 1.861385
## [36] {citrus.fruit=shopping bags,
## ready.soups=} => {margarine=} 0.01765283 1.0000000 2.501226
## [37] {citrus.fruit=bottled beer,
## semi.finished.bread=} => {margarine=} 0.01098398 1.0000000 2.501226
## [38] {citrus.fruit=bottled beer,
## semi.finished.bread=} => {ready.soups=} 0.01098398 1.0000000 1.861385
## [39] {citrus.fruit=bottled beer,
## margarine=} => {ready.soups=} 0.01595293 1.0000000 1.861385
## [40] {citrus.fruit=bottled beer,
## ready.soups=} => {margarine=} 0.01595293 0.8745520 2.187453
## [41] {citrus.fruit=bottled water,
## margarine=} => {ready.soups=} 0.01386074 1.0000000 1.861385
## [42] {citrus.fruit=canned beer,
## semi.finished.bread=} => {margarine=} 0.01837202 1.0000000 2.501226
## [43] {citrus.fruit=canned beer,
## margarine=} => {semi.finished.bread=} 0.01837202 0.8121387 3.564322
## [44] {citrus.fruit=canned beer,
## semi.finished.bread=} => {ready.soups=} 0.01837202 1.0000000 1.861385
## [45] {citrus.fruit=canned beer,
## margarine=} => {ready.soups=} 0.02262177 1.0000000 1.861385
## [46] {citrus.fruit=canned beer,
## ready.soups=} => {margarine=} 0.02262177 0.9226667 2.307798
## [47] {semi.finished.bread=soda,
## margarine=} => {ready.soups=} 0.01072246 1.0000000 1.861385
## [48] {citrus.fruit=soda,
## semi.finished.bread=} => {margarine=} 0.01412226 1.0000000 2.501226
## [49] {citrus.fruit=soda,
## semi.finished.bread=} => {ready.soups=} 0.01412226 1.0000000 1.861385
## [50] {citrus.fruit=soda,
## margarine=} => {ready.soups=} 0.02451782 1.0000000 1.861385
## [51] {citrus.fruit=soda,
## ready.soups=} => {margarine=} 0.02451782 0.8012821 2.004188
## [52] {citrus.fruit=rolls/buns,
## margarine=} => {ready.soups=} 0.01922197 1.0000000 1.861385
## [53] {citrus.fruit=whole milk,
## margarine=} => {ready.soups=} 0.01915659 1.0000000 1.861385
## [54] {semi.finished.bread=,
## margarine=} => {ready.soups=} 0.22785224 1.0000000 1.861385
## [55] {semi.finished.bread=,
## ready.soups=} => {margarine=} 0.22785224 1.0000000 2.501226
## [56] {citrus.fruit=newspapers,
## semi.finished.bread=,
## margarine=} => {ready.soups=} 0.01203008 1.0000000 1.861385
## [57] {citrus.fruit=newspapers,
## semi.finished.bread=,
## ready.soups=} => {margarine=} 0.01203008 1.0000000 2.501226
## [58] {citrus.fruit=newspapers,
## margarine=,
## ready.soups=} => {semi.finished.bread=} 0.01203008 0.8932039 3.920101
## [59] {citrus.fruit=shopping bags,
## semi.finished.bread=,
## margarine=} => {ready.soups=} 0.01765283 1.0000000 1.861385
## [60] {citrus.fruit=shopping bags,
## semi.finished.bread=,
## ready.soups=} => {margarine=} 0.01765283 1.0000000 2.501226
## [61] {citrus.fruit=shopping bags,
## margarine=,
## ready.soups=} => {semi.finished.bread=} 0.01765283 1.0000000 4.388809
## [62] {citrus.fruit=bottled beer,
## semi.finished.bread=,
## margarine=} => {ready.soups=} 0.01098398 1.0000000 1.861385
## [63] {citrus.fruit=bottled beer,
## semi.finished.bread=,
## ready.soups=} => {margarine=} 0.01098398 1.0000000 2.501226
## [64] {citrus.fruit=canned beer,
## semi.finished.bread=,
## margarine=} => {ready.soups=} 0.01837202 1.0000000 1.861385
## [65] {citrus.fruit=canned beer,
## semi.finished.bread=,
## ready.soups=} => {margarine=} 0.01837202 1.0000000 2.501226
## [66] {citrus.fruit=canned beer,
## margarine=,
## ready.soups=} => {semi.finished.bread=} 0.01837202 0.8121387 3.564322
## [67] {citrus.fruit=soda,
## semi.finished.bread=,
## margarine=} => {ready.soups=} 0.01412226 1.0000000 1.861385
## [68] {citrus.fruit=soda,
## semi.finished.bread=,
## ready.soups=} => {margarine=} 0.01412226 1.0000000 2.501226