gpt4 book ai didi

r - Network_plot 'names' 属性

转载 作者:行者123 更新时间:2023-12-04 09:39:31 26 4
gpt4 key购买 nike

我正在尝试制作一个网络图来显示相关性。我的代码:

camas_desempleo %>% 
select(-CCAA) %>%
correlate() %>%
network_plot()

数据:
> dput(camas_desempleo)
structure(list(CCAA = c("andalucía", "cataluña", "comunitat valenciana",
"madrid, comunidad de", "canarias", "castilla - la mancha", "galicia",
"castilla y león", "país vasco", "extremadura", "murcia, región de",
"asturias, principado de", "aragón", "balears, illes", "cantabria"
), paro = c(884121, 418438.25, 393648.25, 368107, 225404, 185089.75,
175023.5, 151656.5, 125436, 109651.75, 106352, 76787.75, 71575.5,
63432.75, 40508.5), pub = c(572, 511, 450, 479, 187, 155, 215,
180, 158, 97, 112, 86, 113, 78, 40), priv = c(162, 141, 101,
225, 50, 13, 48, 20, 21, 5, 11, 7, 22, 46, 0), total = c(734,
652, 551, 704, 237, 168, 263, 200, 179, 102, 123, 93, 135, 124,
40)), row.names = c(NA, -15L), class = c("tbl_df", "tbl", "data.frame"
))

给出的错误如下:

Error in names(x) <- value : 'names' attribute [2] must be the same length as the vector [1] In addition: Warning message: In stats::cmdscale(abs(distance)) : only 1 of the first 2 eigenvalues are > 0

In addition: Warning message: In stats::cmdscale(abs(distance)) :
only 1 of the first 2 eigenvalues are > 0



我在文档中找不到有关此错误的任何信息,并且使用相同的代码为 mtcars 提供了一种非常相似的方法。数据集。

最佳答案

network_plot ( source code here ) 尝试执行以下步骤(第 188-189 行)时,就会出现问题:

points <- data.frame(stats::cmdscale(distance))
colnames(points) <- c("x", "y")
network_plot 代码假定它将处理具有 2 列的数据帧( k=2 中默认为 stats::cmdscale )。但这不一定是真的。从引用( ?stats::cmdscale ):

A set of Euclidean distances on n points can be represented exactly in at most n - 1 dimensions. cmdscale follows the analysis of Mardia (1978), and returns the best-fitting k-dimensional representation, where k may be less than the argument k.


> stats::cmdscale(distance)
[,1]
paro 0.118717157
pub 0.004476784
priv -0.106540786
total -0.016653154
Warning message:
In stats::cmdscale(distance) : only 1 of the first 2 eigenvalues are > 0

在你的情况下,你只得到一列,因为内积矩阵的只有一个特征值是正的。你能找到解决方法吗?不。这与您输入数据的性质有关,即您提供了非欧几里得距离这一事实。你可以阅读这个 here

关于r - Network_plot 'names' 属性,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62394466/

26 4 0