如何获得介于 0 和 1 之间的接近度分数

How to obtain a closeness score bounded between 0 and 1

我想计算网络的紧密度,例如

relations=structure(list(From = c("France", "Italy", "Malta", "Spain", 
"Germany", "Austria", "Luxembourg", "Luxembourg", "Luxembourg", 
"Greece", "Slovakia", "Belgium", "Luxembourg", "Estonia", "Germany", 
"Netherlands", "Netherlands", "Cyprus", "Greece", "Lithuania", 
"Estonia", "Greece", "Lithuania", "Slovakia", "Netherlands", 
"Luxembourg", "Estonia", "Malta", "Belgium", "Cyprus", "Austria", 
"Estonia", "Austria", "Germany", "Austria", "Netherlands", "Portugal", 
"Portugal", "Estonia", "Italy", "Spain", "Finland", "Belgium", 
"Spain", "Estonia", "Latvia", "Luxembourg", "Luxembourg", "Netherlands", 
"Italy", "Lithuania", "Cyprus", "Ireland", "Luxembourg", "Ireland", 
"Spain", "Belgium", "Latvia", "Netherlands", "Italy", "Slovenia", 
"Netherlands", "Greece", "Spain", "Austria", "Finland", "Malta", 
"Spain", "Austria", "Lithuania", "France", "Portugal", "Cyprus", 
"Finland", "Spain", "Spain", "Belgium", "Germany", "Germany", 
"Greece", "Netherlands", "Luxembourg", "Estonia", "Ireland", 
"Italy", "Portugal", "Greece", "Estonia", "Belgium", "Germany", 
"Slovenia", "Slovakia", "Lithuania", "Slovenia", "Portugal", 
"Portugal", "Slovakia", "France", "Portugal", "Netherlands"), 
    To = c("Slovakia", "Germany", "Portugal", "Austria", "Latvia", 
    "Cyprus", "Portugal", "Greece", "Italy", "Slovenia", "Ireland", 
    "Malta", "Ireland", "Germany", "Cyprus", "Portugal", "Slovenia", 
    "Italy", "Luxembourg", "France", "Slovakia", "Netherlands", 
    "Greece", "France", "Ireland", "Netherlands", "Cyprus", "Germany", 
    "Portugal", "Austria", "Luxembourg", "Austria", "Spain", 
    "Netherlands", "Belgium", "Cyprus", "Cyprus", "Luxembourg", 
    "Finland", "Belgium", "Lithuania", "Austria", "Spain", "Slovenia", 
    "Luxembourg", "Finland", "Slovenia", "Germany", "Austria", 
    "Slovenia", "Slovenia", "Portugal", "Finland", "Lithuania", 
    "Latvia", "France", "Netherlands", "Cyprus", "Spain", "Malta", 
    "France", "Finland", "Belgium", "Latvia", "Slovenia", "Slovenia", 
    "Cyprus", "Slovakia", "Slovakia", "Latvia", "Austria", "Ireland", 
    "Luxembourg", "Belgium", "Italy", "Estonia", "Greece", "Slovakia", 
    "Belgium", "Italy", "Latvia", "Malta", "Greece", "France", 
    "Greece", "Netherlands", "France", "Slovenia", "Latvia", 
    "Finland", "Austria", "Slovenia", "Belgium", "Cyprus", "Greece", 
    "Slovenia", "Cyprus", "Finland", "Malta", "Germany"), weight = c(3.63689639539779e-09, 
    2.36155345798604e-11, 1.90981717262912e-08, 1.27550515412245e-09, 
    2.75032212941667e-09, 3.79663088493923e-08, 1.42368280746262e-08, 
    1.51146811601353e-08, 1.75314892144034e-09, 2.07956027448449e-08, 
    1.38623943876156e-07, 1.92893849444567e-08, 5.66419694274739e-08, 
    5.8089561312222e-09, 1.95827364947702e-09, 6.7071674411728e-10, 
    4.23667746162198e-09, 4.62966220873406e-08, 1.21403390886489e-07, 
    1.26979107479853e-08, 5.59978765605208e-07, 3.14788992090851e-09, 
    5.0058794053616e-07, 5.22186410794211e-09, 9.21607337940845e-10, 
    2.51322812227745e-09, 3.04984607426863e-07, 3.20992561385791e-09, 
    8.92180336424503e-10, 6.12766236972513e-08, 1.20231538847898e-08, 
    1.34589665048046e-07, 8.84238627642763e-10, 2.63370671763944e-11, 
    1.11903749128791e-09, 1.16731679208085e-08, 4.99654438989995e-08, 
    2.90162442064053e-08, 2.55621731534268e-09, 1.58298464637584e-10, 
    5.07475932446428e-08, 2.54927518867625e-09, 2.24427326793633e-10, 
    4.49723284363684e-09, 2.43010060636845e-06, 1.90760030501003e-08, 
    6.35902610582491e-08, 5.48833215255332e-10, 4.06612010446768e-10, 
    5.32889353797193e-10, 1.23745070305762e-06, 8.89608483306497e-07, 
    3.75876719292064e-09, 4.44758324449273e-07, 1.35536579831994e-07, 
    5.42265922046125e-11, 4.8233448207134e-11, 3.4286615533894e-07, 
    2.0214285544428e-10, 8.57988303618593e-10, 1.35631258148319e-09, 
    7.97944858545598e-10, 4.2673026648725e-09, 9.28491399244895e-08, 
    1.03420112425729e-09, 2.4972909387896e-08, 8.12118760999133e-07, 
    1.31225365800221e-08, 1.77287287047586e-09, 6.53958727055997e-09, 
    3.05841917976996e-10, 9.20687775127977e-09, 4.32323785012335e-07, 
    8.40653865200987e-10, 1.23500809608508e-10, 6.59008808575339e-08, 
    1.13962199159936e-09, 4.68300414991578e-10, 3.54758342726504e-11, 
    6.55880483863129e-10, 1.17833628272869e-08, 5.08802989644665e-07, 
    7.22191649442396e-07, 2.7028184600344e-10, 2.2810918951755e-10, 
    8.10987753872438e-10, 1.50406384816011e-09, 5.46176491471454e-06, 
    2.32716789835402e-08, 2.10873259303399e-10, 1.81735402994258e-09, 
    9.71369590422109e-09, 2.01941765282435e-08, 1.8961914804496e-07, 
    9.4461402995167e-09, 1.69816623519093e-07, 9.16774899583353e-08, 
    8.54588845128718e-10, 4.79160495478785e-08, 2.31994460360924e-11
    )), row.names = c(NA, -100L), class = c("tbl_df", "tbl", 
"data.frame"))
actors= c("Slovakia", "Germany", "Portugal", "Austria", "Latvia", "Cyprus", 
"Greece", "Italy", "Slovenia", "Ireland", "Malta", "Luxembourg", 
"France", "Netherlands", "Spain", "Belgium", "Finland", "Lithuania", 
"Estonia")
g <- graph_from_data_frame(relations, directed=TRUE, vertices=actors)

通过使用包 igraph。使用函数 closeness 我得到:

closeness(g)
   Slovakia     Germany    Portugal     Austria      Latvia      Cyprus      Greece       Italy    Slovenia     Ireland 
    4002492     7111002     6478738     6502665     2017834     1029940     6615891     7164685     5533119     6240785 
      Malta  Luxembourg      France Netherlands       Spain     Belgium     Finland   Lithuania     Estonia 
    5071100     7243749     6342911     7121291     7144000     7090895     6415382     3086085     7411727  

我想获得一个介于 0 和 1 之间的归一化接近度分数。如果一个节点是孤立的,则为 0,如果一个节点直接连接所有其他节点,则为 1。我能做什么

在函数中,您可以调用“normalized = TRUE”,因为它默认为“FALSE”。旁注:如果您添加用于计算接近度的代码,将会很有帮助。

closeness(
  graph,
  vids = V(graph),
  mode = c("out", "in", "all", "total"),
  weights = NULL,
  normalized = TRUE
)

您是否尝试过自己从 igraph 中对其进行标准化?您可以使用 caret 包:

library(caret)
c1 <-closeness(g)
df <- tibble(actors = actors,
             close = c1)
df_normalized <- df %>% 
  preProcess(., method=c("range")) %>% 
  predict(., df)

df_normalized