gpt4 book ai didi

r - 将 pvclust R 函数应用于预先计算的 dist 对象

转载 作者:行者123 更新时间:2023-12-01 11:03:02 25 4
gpt4 key购买 nike

我正在使用 R 执行层次聚类。作为第一种方法,我使用了 hclust 并执行了以下步骤:

  1. 我导入了距离矩阵
  2. 我使用 as.dist 函数将其转换为 dist 对象
  3. 我在 dist 对象上运行 hclust

这是 R 代码:

distm <- read.csv("distMatrix.csv")
d <- as.dist(distm)
hclust(d, "ward")

此时我想用函数pvclust做一些类似的事情;但是,我不能,因为不可能传递预先计算的 dist 对象。考虑到我使用的距离在 R 的 dist 函数提供的距离中不可用,我该如何继续?

最佳答案

我测试了文森特的建议,你可以这样做(我的数据集是相异矩阵):

# Import you data
distm <- read.csv("distMatrix.csv")
d <- as.dist(distm)

# Compute the eigenvalues
x <- cmdscale(d,1,eig=T)

# Plot the eigenvalues and choose the correct number of dimensions (eigenvalues close to 0)
plot(x$eig,
type="h", lwd=5, las=1,
xlab="Number of dimensions",
ylab="Eigenvalues")

# Recover the coordinates that give the same distance matrix with the correct number of dimensions
x <- cmdscale(d,nb_dimensions)

# As mentioned by Stéphane, pvclust() clusters columns
pvclust(t(x))

关于r - 将 pvclust R 函数应用于预先计算的 dist 对象,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8924488/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com