如何用R组织分数进入帕累托队列?

时间:2013-07-09 17:33:28

标签: r ranking

按照Cutter,2003的方法,我正在使用块级人口普查数据计算社会脆弱性指数(SoVI)。 我通过PCA生成了4个主成分分数,我想使用Pareto排名将块组织组织成一系列排名(根据Rygel等人2006:构建社会脆弱性指数的方法)。

我很抱歉这个问题不清楚。下面是我使用的示例数据集,表示块组的行和表示漏洞维度的列(PCA组件分数)。我想在一个新专栏中使用Pareto方法计算基于4个漏洞维度的排名。

sovi<-structure(list(deprivation = c(4.28, 4.91, 7.63, 
1.33,6.03,6.40,-0.21,6.72,-1.45,5.76), 
oldage = c(1.04,0.87,1.14,0.18,0.75,0.93,1.29,0.81,5.57,1.28),
housing = c(1.57, 1.41, 2.27, 0.21,0.97,2.65,-0.33,1.68,-1.72,1.78), 
education = c(-3.65,-1.73,-3.57,-3.37,-3.20,-2.06,-0.59,-2.93,-0.40,-3.09)), 
.Names = c("deprivation", "oldage", "housing", "education"),
row.names=c(NA,10L), class = "data.frame") 

来自Rygel,“Pareto排名方法背后的基本原理如下。每个案例i都是基于一组n个分量得分{ci1,ci2,...,cin}。(... )假设任何单个组件的得分越高表示漏洞越大。当比较两个(...)区块组A和B时,只有当A的得分至少等于A时,情况A比情况B更容易受到攻击。对于所有组件的B,如果至少有一个组件,其中A得分高于B“。

我搜索了R网站,但未找到进行帕累托排名的套餐。

非常感谢!

1 个答案:

答案 0 :(得分:0)

您引用的定义仅定义了部分订单: 你拥有的组件越多,可比组就越少。

您可以使用双循环或outer来比较所有可能的组对, 并igraph绘制结果。

n <- nrow(sovi)
a <- outer(1:n, 1:n, Vectorize( function(i,j) 
  all( sovi[i,] >= sovi[j,] ) && 
  any( sovi[i,] >  sovi[j,] ) 
) )
library(igraph)
g <- graph.adjacency(a)
plot(g)

# Remove the edges that can be inferred by transitivity
hasse <- function(g) {
  # Inspired from:
  #   http://web.bahcesehir.edu.tr/atabey_kaygun/other/hasse-local.html
  es <- get.edgelist(g)
  for( e in 1:nrow(es) ) { 
    i <- es[e,1]
    j <- es[e,2]
    g[i,j] <- FALSE
    p <- get.shortest.paths(g,i,j)
    if( length(p[[1]]) == 0 ) {
      g[i,j] <- TRUE 
    } else { 
      cat( "Removing edge ", i, "-", j, " because of ", paste(p[[1]],collapse="-"), "\n", sep="")
    }
  }
  g
}
plot(hasse(g))

Graph of the partial order