Cluster the data with one of the following methods:

- immunr_hclust clusters the data using the hierarchical clustering from hcut;

- immunr_kmeans clusters the data using the K-means algorithm from kmeans;

- immunr_dbscan clusters the data using the DBSCAN algorithm from dbscan.

immunr_hclust(.data, .k = 2, .k.max = nrow(.data) - 1, .method = "complete", .dist = TRUE)

immunr_kmeans(.data, .k = 2, .k.max = as.integer(sqrt(nrow(.data))) + 1,
.method = c("silhouette", "gap_stat"))

immunr_dbscan(.data, .eps, .dist = TRUE)

Arguments

.data

Matrix or data frame with features, distance matrix or output from repOverlapAnalysis or geneUsageAnalysis functions.

.k

The number of clusters to create, passed as k to hcut or as centers to kmeans.

.k.max

Limits the maximum number of clusters. It is passed as k.max to fviz_nbclust for immunr_hclust and immunr_kmeans.

.method

Passed to hcut or as fviz_nbclust.

In case of hcut the agglomeration method is going to be used (argument hc_method).

In case of fviz_nbclust it is the method to be used for estimating the optimal number of clusters (argument method).

.dist

If TRUE then ".data" is expected to be a distance matrix. If FALSE then the euclidean distance is computed for the input objects.

.eps

Local radius for expanding clusters, minimal distance between points to expand clusters. Passed as eps to dbscan.

Value

immunr_hclust - list with two elements. First element is an output from hcut. Second element is an output from fviz_nbclust

immunr_kmeans - list with three elements. First element is an output from kmeans. Second element is an output from fviz_nbclust. Third element is the input dataset .data.

immunr_dbscan - list with two elements. First element is an output from dbscan. Second element is the input dataset .data.

Examples

data(immdata)
gu <- geneUsage(immdata$data, .norm = TRUE)
immunr_hclust(t(as.matrix(gu[, -1])), .dist = FALSE)
#> $hcut
#> 
#> Call:
#> stats::hclust(d = x, method = hc_method)
#> 
#> Cluster method   : complete 
#> Distance         : euclidean 
#> Number of objects: 12 
#> 
#> 
#> $nbclust

#> 
#> attr(,"class")
#> [1] "immunr_hclust" "list"         

gu[is.na(gu)] <- 0
immunr_kmeans(t(as.matrix(gu[, -1])))
#> $kmeans
#> K-means clustering with 2 clusters of sizes 8, 4
#> 
#> Cluster means:
#>          [,1]        [,2]       [,3]        [,4]       [,5]        [,6]
#> 1 0.003217927 0.005136958 0.03808497 0.002784769 0.02163279 0.001354764
#> 2 0.002404951 0.005592294 0.03748111 0.002902743 0.01969097 0.002277234
#>         [,7]        [,8]        [,9]       [,10]      [,11]        [,12]
#> 1 0.07282388 0.003681283 0.007062313 0.007135019 0.01712132 0.0009044963
#> 2 0.09805826 0.003895011 0.005357461 0.008832893 0.01636634 0.0009559951
#>        [,13]       [,14]      [,15]      [,16]       [,17]        [,18]
#> 1 0.01055184 0.004005534 0.02206314 0.09415083 0.007917676 0.0005239859
#> 2 0.01451586 0.004843118 0.02369379 0.09298495 0.006958857 0.0004885246
#>        [,19]       [,20]      [,21]      [,22]      [,23]      [,24]
#> 1 0.01181950 0.012562645 0.03086468 0.03558444 0.08733554 0.02499238
#> 2 0.01448042 0.008492464 0.02489818 0.04641556 0.07148150 0.02866064
#>         [,25]      [,26]      [,27]        [,28]     [,29]       [,30]
#> 1 0.003829546 0.03453340 0.02073357 0.0300495338 0.0682959 0.002492186
#> 2 0.006282781 0.04145543 0.01610477 0.0003515766 0.1121346 0.003280249
#>        [,31]       [,32]       [,33]      [,34]      [,35]       [,36]
#> 1 0.01009462 0.009413752 0.001458858 0.01183709 0.02104105 0.009513854
#> 2 0.01453411 0.013339090 0.001442820 0.01395531 0.01135077 0.009440908
#>        [,37]      [,38]        [,39]        [,40]      [,41]      [,42]
#> 1 0.03355204 0.02163971 0.0003137076 3.862787e-05 0.06556093 0.01877986
#> 2 0.03261857 0.02226965 0.0001722818 3.357057e-05 0.03685651 0.02487504
#>          [,43]      [,44]       [,45]      [,46]      [,47]      [,48]
#> 1 0.0010012403 0.01051308 0.004479564 0.01563413 0.04882278 0.03305829
#> 2 0.0006173741 0.01162180 0.003929323 0.01415173 0.04569534 0.02175729
#> 
#> Clustering vector:
#> A2-i129 A2-i131 A2-i133 A2-i132 A4-i191 A4-i192     MS1     MS2     MS3     MS4 
#>       2       1       1       1       1       1       1       2       1       2 
#>     MS5     MS6 
#>       1       2 
#> 
#> Within cluster sum of squares by cluster:
#> [1] 0.022967774 0.009796951
#>  (between_SS / total_SS =  29.4 %)
#> 
#> Available components:
#> 
#> [1] "cluster"      "centers"      "totss"        "withinss"     "tot.withinss"
#> [6] "betweenss"    "size"         "iter"         "ifault"      
#> 
#> $nbclust

#> 
#> $data
#>                 [,1]        [,2]       [,3]        [,4]       [,5]         [,6]
#> A2-i129 0.0036742192 0.006429884 0.03521127 0.003214942 0.02801592 0.0012247397
#> A2-i131 0.0042728521 0.009156112 0.04303373 0.002136426 0.02624752 0.0016786205
#> A2-i133 0.0000000000 0.001251369 0.02111685 0.004066948 0.01955264 0.0007821054
#> A2-i132 0.0023361075 0.004234195 0.01576873 0.002482114 0.02350708 0.0035041612
#> A4-i191 0.0056354450 0.005441119 0.07306646 0.003303537 0.01846094 0.0003886514
#> A4-i192 0.0010303967 0.002747725 0.03692255 0.002747725 0.01940580 0.0012021295
#> MS1     0.0035152636 0.004625347 0.03607771 0.002590194 0.01739130 0.0007400555
#> MS2     0.0005598321 0.004898530 0.01987404 0.001399580 0.01469559 0.0018194542
#> MS3     0.0066553165 0.009750813 0.04705154 0.002476397 0.02693082 0.0020120724
#> MS4     0.0025513630 0.005237008 0.03518195 0.004297032 0.02336511 0.0017456694
#> MS5     0.0022980378 0.003888987 0.03164221 0.002474810 0.02156620 0.0005303164
#> MS6     0.0028343906 0.005803752 0.05965717 0.002699420 0.01268727 0.0043190714
#>               [,7]        [,8]        [,9]        [,10]      [,11]        [,12]
#> A2-i129 0.09231476 0.005664421 0.006736069 0.0099510104 0.01347214 0.0013778322
#> A2-i131 0.07004425 0.008240501 0.008087899 0.0138867694 0.02151686 0.0013734168
#> A2-i133 0.04895980 0.001251369 0.007038949 0.0075082121 0.01595495 0.0010949476
#> A2-i132 0.06322091 0.005548255 0.011388524 0.0106584903 0.01226456 0.0010220470
#> A4-i191 0.06471045 0.003497862 0.005635445 0.0077730276 0.01496308 0.0011659541
#> A4-i192 0.09565516 0.002919457 0.007384510 0.0051519835 0.01270823 0.0008586639
#> MS1     0.07511563 0.001295097 0.007215541 0.0042553191 0.02035153 0.0009250694
#> MS2     0.08481456 0.002379286 0.003918824 0.0131560532 0.02239328 0.0006997901
#> MS3     0.06995821 0.003869370 0.004798019 0.0032502709 0.01888253 0.0006190992
#> MS4     0.08674634 0.004297032 0.004431315 0.0112797100 0.01826239 0.0016113871
#> MS5     0.09492664 0.002828354 0.004949620 0.0045960757 0.02032880 0.0001767721
#> MS6     0.12835740 0.003239304 0.006343636 0.0009447969 0.01133756 0.0001349710
#>               [,13]       [,14]      [,15]      [,16]       [,17]        [,18]
#> A2-i129 0.016993264 0.004898959 0.03735456 0.07853644 0.007960808 0.0004592774
#> A2-i131 0.017091409 0.009308714 0.02990996 0.08698306 0.014191973 0.0013734168
#> A2-i133 0.018301267 0.003597685 0.02455811 0.09400907 0.009228844 0.0014077898
#> A2-i132 0.008322383 0.006570302 0.02409111 0.07825960 0.009344430 0.0007300336
#> A4-i191 0.006412748 0.002137583 0.02234745 0.09405363 0.009716284 0.0001943257
#> A4-i192 0.008071441 0.001373862 0.02610338 0.10630259 0.007384510 0.0000000000
#> MS1     0.007030527 0.003330250 0.01110083 0.11285846 0.004810361 0.0000000000
#> MS2     0.018894332 0.005738279 0.02379286 0.09769069 0.009377187 0.0004198740
#> MS3     0.008048290 0.004488469 0.01965640 0.08899551 0.004952794 0.0003095496
#> MS4     0.018396670 0.007385524 0.02242514 0.10433732 0.005908419 0.0009399758
#> MS5     0.011136645 0.001237405 0.01873785 0.09174474 0.003712215 0.0001767721
#> MS6     0.003779187 0.001349710 0.01120259 0.09137535 0.004589013 0.0001349710
#>               [,19]       [,20]      [,21]      [,22]      [,23]      [,24]
#> A2-i129 0.016533987 0.008879363 0.02372933 0.05541947 0.06736069 0.03628291
#> A2-i131 0.012513353 0.013123760 0.02945216 0.01907523 0.05829391 0.03403022
#> A2-i133 0.012200845 0.012044424 0.02690443 0.07805412 0.09682465 0.02205537
#> A2-i132 0.012848591 0.011680537 0.03285151 0.05095634 0.07738356 0.02978537
#> A4-i191 0.009327633 0.018460941 0.03109211 0.02973183 0.11815002 0.02701127
#> A4-i192 0.008243174 0.020436201 0.03262923 0.02472952 0.09582689 0.02679031
#> MS1     0.014246068 0.007955597 0.03848289 0.04680851 0.09491212 0.01831637
#> MS2     0.008537439 0.008397481 0.02029391 0.07109867 0.09587124 0.02897131
#> MS3     0.013155858 0.009905587 0.03234793 0.01516793 0.08481659 0.01702523
#> MS4     0.016113871 0.008459782 0.03383913 0.04740164 0.05156439 0.02846784
#> MS5     0.012020506 0.006894113 0.02315715 0.02015202 0.07247658 0.02492487
#> MS6     0.016736402 0.008233230 0.02173033 0.01174248 0.07112971 0.02092050
#>                [,25]      [,26]      [,27]        [,28]      [,29]        [,30]
#> A2-i129 0.0067360686 0.03505818 0.01607471 0.0004592774 0.11007348 0.0033680343
#> A2-i131 0.0132763620 0.01022432 0.01327636 0.0279261407 0.06928125 0.0035098428
#> A2-i133 0.0034412639 0.01908337 0.01423432 0.0437979040 0.05615517 0.0028155795
#> A2-i132 0.0002920134 0.03562564 0.02263104 0.0487662432 0.04555410 0.0017520806
#> A4-i191 0.0025262340 0.06276720 0.03186941 0.0000000000 0.06101827 0.0007773028
#> A4-i192 0.0030911901 0.03245750 0.01992100 0.0494590417 0.05117637 0.0008586639
#> MS1     0.0016651249 0.04051804 0.02331175 0.0205365402 0.09435708 0.0027752081
#> MS2     0.0061581526 0.03247026 0.01385584 0.0001399580 0.13505948 0.0016794962
#> MS3     0.0038693701 0.03281226 0.01764433 0.0256926172 0.08079245 0.0035598205
#> MS4     0.0088626292 0.04592453 0.01248825 0.0005371290 0.10447160 0.0048341614
#> MS5     0.0024748100 0.04277886 0.02298038 0.0242177833 0.08803253 0.0038889871
#> MS6     0.0033742745 0.05236874 0.02200027 0.0002699420 0.09893373 0.0032393035
#>               [,31]       [,32]        [,33]       [,34]       [,35]
#> A2-i129 0.015156154 0.006736069 0.0004592774 0.011635028 0.010104103
#> A2-i131 0.015107584 0.008393102 0.0015260186 0.013886769 0.021059057
#> A2-i133 0.008603160 0.009385265 0.0007821054 0.009072423 0.028625059
#> A2-i132 0.009490437 0.010512484 0.0024821142 0.011388524 0.016206746
#> A4-i191 0.005635445 0.005829771 0.0005829771 0.014768752 0.015157404
#> A4-i192 0.003949854 0.005838915 0.0006869311 0.010303967 0.026446849
#> MS1     0.007400555 0.011655874 0.0009250694 0.009990749 0.012025902
#> MS2     0.014695591 0.011756473 0.0016794962 0.014835549 0.014975507
#> MS3     0.016251354 0.011143786 0.0018572976 0.011143786 0.028478564
#> MS4     0.011548274 0.018262388 0.0022827984 0.014233920 0.011145428
#> MS5     0.014318543 0.012550822 0.0028283543 0.014141771 0.020328796
#> MS6     0.016736402 0.016601431 0.0013497098 0.015116750 0.009178027
#>               [,36]      [,37]      [,38]        [,39]        [,40]      [,41]
#> A2-i129 0.004592774 0.02602572 0.02908757 0.0000000000 0.0000000000 0.03230251
#> A2-i131 0.007477491 0.02517931 0.03326721 0.0009156112 0.0001526019 0.05295285
#> A2-i133 0.009228844 0.02096043 0.02299390 0.0000000000 0.0001564211 0.07398717
#> A2-i132 0.008176376 0.02715725 0.01971091 0.0001460067 0.0000000000 0.05781866
#> A4-i191 0.014768752 0.03789351 0.01612903 0.0005829771 0.0000000000 0.06024096
#> A4-i192 0.009101838 0.03331616 0.01579942 0.0001717328 0.0000000000 0.08397733
#> MS1     0.005735430 0.03885291 0.02072155 0.0001850139 0.0000000000 0.05513414
#> MS2     0.003778866 0.02687194 0.01609517 0.0004198740 0.0000000000 0.05164451
#> MS3     0.018263427 0.04581334 0.02399009 0.0001547748 0.0000000000 0.06454109
#> MS4     0.006176984 0.03249631 0.02041090 0.0001342823 0.0001342823 0.04431315
#> MS5     0.003358671 0.03924342 0.02050557 0.0003535443 0.0000000000 0.07583525
#> MS6     0.023215009 0.04508031 0.02348495 0.0001349710 0.0000000000 0.01916588
#>               [,42]        [,43]       [,44]       [,45]       [,46]      [,47]
#> A2-i129 0.025413350 0.0003061849 0.012706675 0.004592774 0.008726271 0.05006124
#> A2-i131 0.008545704 0.0018312223 0.013428964 0.005188463 0.023195483 0.05753090
#> A2-i133 0.024558110 0.0009385265 0.010949476 0.003128422 0.017362740 0.06444549
#> A2-i132 0.031829464 0.0002920134 0.009928457 0.007154329 0.016936779 0.05416849
#> A4-i191 0.009716284 0.0011659541 0.007773028 0.002331908 0.010687913 0.03789351
#> A4-i192 0.009273570 0.0012021295 0.006525846 0.002232526 0.012536493 0.04585265
#> MS1     0.024606846 0.0003700278 0.013506013 0.005920444 0.013320999 0.03533765
#> MS2     0.013435969 0.0002799160 0.006298111 0.002099370 0.016515045 0.04534640
#> MS3     0.019965950 0.0006190992 0.010679461 0.005107568 0.014239282 0.04550379
#> MS4     0.016785283 0.0012085404 0.010071170 0.003491339 0.016113871 0.04337317
#> MS5     0.021742973 0.0015909493 0.011313417 0.004772848 0.016793353 0.04984974
#> MS6     0.043865569 0.0006748549 0.017411257 0.005533810 0.015251721 0.04400054
#>              [,48]
#> A2-i129 0.02862829
#> A2-i131 0.03784526
#> A2-i133 0.02753011
#> A2-i132 0.06322091
#> A4-i191 0.02720560
#> A4-i192 0.02919457
#> MS1     0.02719704
#> MS2     0.01021693
#> MS3     0.02275190
#> MS4     0.02645361
#> MS5     0.02952095
#> MS6     0.02173033
#> 
#> attr(,"class")
#> [1] "immunr_kmeans" "list"