拓端tecdat|R语言使用灰色关联分析(Grey Relation Analysis,GRA)中国经济社会发展指标
发布时间:2022-11-16 23:57:48 258
相关标签: # 数据
灰色关联分析包括两个重要功能。 第一项功能:灰色关联度,与correlation系数相似,如果要评估某些单位,在使用此功能之前转置数据。第二个功能:灰色聚类,如层次聚类。
灰色关联分析包括两个重要功能。
第一项功能:灰色关联度,与correlation系数相似,如果要评估某些单位,在使用此功能之前转置数据。第二个功能:灰色聚类,如层次聚类。
灰色关联度
灰色关联度有两种用法。该算法用于测量两个变量的相似性,就像`cor`一样。如果要评估某些单位,可以转置数据集。
*一种是检查两个变量的相关性,数据类型如下:
| 参考| v1 | v2 | v3 |
| ----------- |||| ---- | ---- |
| 1.2 | 1.8 | 0.9 | 8.4 |
| 0.11 | 0.3 | 0.5 | 0.2 |
| 1.3 | 0.7 | 0.12 | 0.98 |
| 1.9 | 1.09 | 2.8 | 0.99 |
reference:参考变量,reference和v1之间的灰色关联度...近似地测量reference和v1的相似度。
*另一个是评估某些单位的好坏。
| 单位| v1 | v2 | v3 |
| ----------- |||| ---- | ---- |
| 江苏| 1.8 | 0.9 | 8.4 |
| 浙江| 0.3 | 0.5 | 0.2 |
| 安徽 0.7 | 0.12 | 0.98 |
| 福建| 1.09 | 2.8 | 0.99 |
-
##生成数据 -
#' economyCompare = data.frame(refer, liaoning, shandong, jiangsu, zhejiang, fujian, guangdong) -
# -
# 异常控制 # -
stop("'df' have NA" ) -
if (distingCoeff<0 | distingCoeff>1) stop("'distingCoeff' must be in range of [0,1]" ) -
#设置差学列矩阵空间 -
for (i in -
max(diff) -
#计算关联系数# -
relations = (mi+distingCoeff*mx) / (diff + distingCoeff*mx) -
#计算关联度# -
# 暂时简单处理, 等权 -
relDegree = rep(NA, nc) -
for (i in 1:nc) { -
# 等权 -
} -
#排序: 按关联度大到小# -
order(relDegree, -
#分配空间 关联关系描述(说明谁和谁的关联度) -
names(X_o -
names(relationalDegree) = relDes -
if (cluster) { -
greyRelDegree = GRA(economyC -
# 得到差异率矩阵 # -
0 -
abs(rel -
#得到距离矩阵# -
0, nrow -
iff[i,j]+grey_diff[j,i] -
} -
} -
# 得到灰色相关系数矩阵 # -
max(grey_dist) -
0, nrow = nc, ncol = nc) -
for (i in 1:nc) { -
for (j in 1:nc) { -
1 - grey_dist[i,j] / grey_dist_max -
} -
} -
1-grey_correl) # 得到无对角线的下三角矩阵(数值意义反向了, 值越小表示越相关 ) -
# 主对角线其实表示了各个对象的相近程度, 画图的时候, 相近的对象放在一起 -
# 系统聚类(分层聚类)函数, single: 单一连接(最短距离法/最近邻) -
# hc$height, 是上面矩阵的对角元素升序 -
# hc$order, 层次树图上横轴个体序号 -
-1) #hang: 设置标签悬挂位置 -
} -
#输出# -
if (cluster) { -
list(relationalDegree=relationalDegree, -
return(lst) -
} -
``` -
```{r} -
## 生成数据 -
rownames(economyCompare) = c("indGV", "indVA", "profit", "incomeTax") -
## 灰色关联度 -
greyRelDegree = greya(economyCompare) -
greyRelDegree -
```
灰色关联度
灰色聚类,如层次聚类
-
## 灰色聚类 -
greya(economyCompare, cluster = T)
文章来源: https://blog.51cto.com/u_14293657/5850530
特别声明:以上内容(图片及文字)均为互联网收集或者用户上传发布,本站仅提供信息存储服务!如有侵权或有涉及法律问题请联系我们。
举报