agnes 位於 cluster 包(package)。 說明
計算數據集的凝聚層次聚類。
用法
agnes(x, diss = inherits(x, "dist"), metric = "euclidean",
stand = FALSE, method = "average", par.method,
keep.diss = n < 100, keep.data = !diss, trace.lev = 0)
參數
x |
數據矩陣或 DataFrame ,或相異矩陣,具體取決於 對於矩陣或 DataFrame ,每行對應一個觀察值,每列對應一個變量。所有變量都必須是數字。允許缺失值 (NA)。 在相異矩陣的情況下, |
diss |
邏輯標誌:如果為 TRUE( |
metric |
字符串,指定用於計算觀測值之間差異的度量。當前可用的選項是 |
stand |
邏輯標誌:如果為 TRUE,則在計算差異之前對 |
method |
定義聚類方法的字符串。實現的六種方法是 默認值為 |
par.method |
如果 |
keep.diss , keep.data |
邏輯指示是否應將差異和/或輸入數據 |
trace.lev |
指定算法期間打印診斷的跟蹤級別的整數。默認 |
細節
agnes 在 Kaufman 和 Rousseuw (1990) 的第 5 章中有完整說明。與hclust等其他凝聚聚類方法相比,agnes具有以下特點:(a)它產生凝聚係數(參見agnes.object),衡量發現的聚類結構的數量; (b) 除了通常的樹之外,它還提供橫幅,一種新穎的圖形顯示(請參閱plot.agnes)。
agnes-算法構建聚類的層次結構。
起初,每個觀察結果本身都是一個小簇。聚類被合並,直到隻剩下一個包含所有觀測值的大聚類。每個階段兩人最近的簇合並形成一個更大的簇。
為了method="average",兩個簇之間的距離是一個簇中的點與另一簇中的點之間的差異的平均值。
在method="single",我們使用第一個簇中的點和第二個簇中的點之間的最小差異(最近鄰法)。
什麽時候method="complete",我們使用第一個簇中的點與第二個簇中的點之間的最大差異(最遠鄰居方法)。
method = "flexible" 允許(並要求)更多細節:Lance-Williams 公式指定當聚類聚集時如何計算相異性(K&R;(1990), p.237 中的方程 (32))。如果簇 和 聚合成一個新簇,則它們的並集與另一個簇 之間的差異由下式給出
其中四個係數由向量指定par.method,直接作為長度為 4 的向量,或者(更方便)如果par.method長度為 1,比如說,par.method擴展為 “Flexible Strategy” (K&R;(1990), p.236 f) 和 Lance-Williams 係數.
另外,如果length(par.method) == 3,已設置。
使用 method = "flexible" 時可能需要小心和專業知識,特別是當 par.method 指定的長度大於 1 時。自 cluster 版本 2.0 起,導致無效 merge 結構的選擇現在會發出錯誤信號(已來自 C 代碼)。加權平均值 (method="weighted" ) 與 method="flexible", par.method = 0.5 相同。另外,method= "single"相當於method="flexible", par.method = c(.5,.5,0,-.5),method="complete"相當於method="flexible", par.method = c(.5,.5,0,+.5)。
method = "gaverage" 是 "average" 的泛化,又名 “flexible UPGMA” 方法,並且(該方法的泛化)在 Belbin 等人中詳細介紹。 (1992)。如"flexible",它使用上麵的Lance-Williams公式進行相異性更新,但和不是常數。但分別與簇 和 的大小 和 成正比,即
其中 、 由 par.method 確定,直接作為 或 和 ,或者(不太靈活,但更方便)如下:
Belbin 等人提出了 “flexible beta”,即用戶隻會指定 (如 par.method ),明智地
並且確定和為
和。
此 可以由 par.method 指定(作為長度為 1 的向量),如果未指定 par.method,則使用默認值 -0.1,因為 Belbin 等人建議采用 -0.1 左右的 值作為一般的凝聚層次聚類策略。
請注意, method = "gaverage", par.method = 0 (或 par.method =
c(1,1,0,0) )相當於 agnes() 默認方法 "average" 。
值
表示聚類的類 "agnes" (擴展 "twins" )的對象。有關詳細信息和適用的方法,請參閱agnes.object。
BACKGROUND
聚類分析將數據集劃分為彼此相似的觀察組(聚類)。
例子
data(votes.repub)
agn1 <- agnes(votes.repub, metric = "manhattan", stand = TRUE)
agn1
plot(agn1)
op <- par(mfrow=c(2,2))
agn2 <- agnes(daisy(votes.repub), diss = TRUE, method = "complete")
plot(agn2)
## alpha = 0.625 ==> beta = -1/4 is "recommended" by some
agnS <- agnes(votes.repub, method = "flexible", par.meth = 0.625)
plot(agnS)
par(op)
## "show" equivalence of three "flexible" special cases
d.vr <- daisy(votes.repub)
a.wgt <- agnes(d.vr, method = "weighted")
a.sing <- agnes(d.vr, method = "single")
a.comp <- agnes(d.vr, method = "complete")
iC <- -(6:7) # not using 'call' and 'method' for comparisons
stopifnot(
all.equal(a.wgt [iC], agnes(d.vr, method="flexible", par.method = 0.5)[iC]) ,
all.equal(a.sing[iC], agnes(d.vr, method="flex", par.method= c(.5,.5,0, -.5))[iC]),
all.equal(a.comp[iC], agnes(d.vr, method="flex", par.method= c(.5,.5,0, +.5))[iC]))
## Exploring the dendrogram structure
(d2 <- as.dendrogram(agn2)) # two main branches
d2[[1]] # the first branch
d2[[2]] # the 2nd one { 8 + 42 = 50 }
d2[[1]][[1]]# first sub-branch of branch 1 .. and shorter form
identical(d2[[c(1,1)]],
d2[[1]][[1]])
## a "textual picture" of the dendrogram :
str(d2)
data(agriculture)
## Plot similar to Figure 7 in ref
## Not run: plot(agnes(agriculture), ask = TRUE)
data(animals)
aa.a <- agnes(animals) # default method = "average"
aa.ga <- agnes(animals, method = "gaverage")
op <- par(mfcol=1:2, mgp=c(1.5, 0.6, 0), mar=c(.1+ c(4,3,2,1)),
cex.main=0.8)
plot(aa.a, which.plot = 2)
plot(aa.ga, which.plot = 2)
par(op)
## Show how "gaverage" is a "generalized average":
aa.ga.0 <- agnes(animals, method = "gaverage", par.method = 0)
stopifnot(all.equal(aa.ga.0[iC], aa.a[iC]))
作者
Method "gaverage" has been contributed by Pierre Roudier, Landcare
Research, New Zealand.
參考
Kaufman, L. and Rousseeuw, P.J. (1990). (=: “K&R(1990)”) Finding Groups in Data: An Introduction to Cluster Analysis. Wiley, New York.
Anja Struyf, Mia Hubert and Peter J. Rousseeuw (1996) Clustering in an Object-Oriented Environment. Journal of Statistical Software 1. doi:10.18637/jss.v001.i04
Struyf, A., Hubert, M. and Rousseeuw, P.J. (1997). Integrating Robust Clustering Techniques in S-PLUS, Computational Statistics and Data Analysis, 26, 17-37.
Lance, G.N., and W.T. Williams (1966). A General Theory of Classifactory Sorting Strategies, I. Hierarchical Systems. Computer J. 9, 373-380.
Belbin, L., Faith, D.P. and Milligan, G.W. (1992). A Comparison of Two Approaches to Beta-Flexible Clustering. Multivariate Behavioral Research, 27, 417-433.
也可以看看
agnes.object、daisy、diana、dist、hclust、plot.agnes、twins.object。
相關用法
- R agnes.object 聚合嵌套 (AGNES) 對象
- R agriculture 歐盟農業勞動力
- R animals 動物的屬性
- R summary.clara “clara”對象的摘要方法
- R diana 分裂分析聚類
- R pluton 鈈同位素成分批次
- R votes.repub 總統選舉中共和黨候選人的投票
- R print.mona MONA 對象的打印方法
- R print.clara CLARA 對象的打印方法
- R mona 二元變量的單論分析聚類
- R plot.diana 分裂層次聚類圖
- R plot.mona 一元分裂層次聚類的旗幟
- R bannerplot 繪圖橫幅(層次聚類)
- R plot.partition 數據集分區圖
- R summary.agnes “agnes”對象的摘要方法
- R pltree 繪製層次聚類的聚類樹
- R summary.mona “mona”對象的摘要方法
- R plantTraits 植物物種性狀數據
- R plot.agnes 凝聚層次聚類圖
- R print.agnes AGNES 對象的打印方法
- R chorSub Kola 數據 C 範圍的子集
- R pam 圍繞 Medoid 進行分區
- R volume.ellipsoid 計算(橢球體的)體積
- R clusplot (分區對象的)雙變量聚類圖
- R print.pam PAM 對象的打印方法
注:本文由純淨天空篩選整理自R-devel大神的英文原創作品 Agglomerative Nesting (Hierarchical Clustering)。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。
