# 第7章 聚类分析
x1 = c(5,7,3,6,6)
x2 = c(7,1,2,5,6)
plot(x1,x2); text(x1,x2,rownames(1:5),adj=-0.5)
# 距离矩阵计算函数dist()的用法
dist(x, method="euclidean", diag=FALSE, upper=FALSE, p=2)
# x为数据矩阵,数据框,method为计算方法,包括"euclidean","maximum","manhattan","canberra","binary","minkowski"
# diag为是否包含对角线元素,upper为是否需要上三角,p为Minkowski距离的幂次
X = cbind(x1,x2)
dist(X, method="minkowski", p=2)
# 系统聚类函数hclust()的用法
hclust(d, method="complete", ...)
# d为相似矩阵,method为系统聚类方法,包括"ward","single","complete","average","mcquitty","median","centroid"
# 最短距离法-欧式距离
hc = hclust(dist(X), "single")
cbind(hc$merge, hc$height)
plot(hc)
# w
x1 = c(5,7,3,6,6)
x2 = c(7,1,2,5,6)
plot(x1,x2); text(x1,x2,rownames(1:5),adj=-0.5)
# 距离矩阵计算函数dist()的用法
dist(x, method="euclidean", diag=FALSE, upper=FALSE, p=2)
# x为数据矩阵,数据框,method为计算方法,包括"euclidean","maximum","manhattan","canberra","binary","minkowski"
# diag为是否包含对角线元素,upper为是否需要上三角,p为Minkowski距离的幂次
X = cbind(x1,x2)
dist(X, method="minkowski", p=2)
# 系统聚类函数hclust()的用法
hclust(d, method="complete", ...)
# d为相似矩阵,method为系统聚类方法,包括"ward","single","complete","average","mcquitty","median","centroid"
# 最短距离法-欧式距离
hc = hclust(dist(X), "single")
cbind(hc$merge, hc$height)
plot(hc)
# w