簡體   English   中英

as.vector中的APCluster錯誤(數據):沒有用於將此S4類強制轉換為向量的方法

[英]APCluster Error in as.vector(data): no method for coercing this S4 class to a vector

使用非聚集輸入數據框(fci),從apcluster()創建APResult作為epxected:

> apclr2q02 <- apcluster(negDistMat(r=2), fci)
> show(apclr2q02)

APResult object

Number of samples     =  1045 
Number of iterations  =  826 
Input preference      =  -22.6498 
Sum of similarities   =  -1603.52 
Sum of preferences    =  -1336.338 
Net similarity        =  -2939.858 
Number of clusters    =  59 

在線文檔說,aggExCluster()可以接受要作為輸入聚類的數據,也可以接受先前的聚類結果(ExClust或APResult)。 在非聚簇數據(fci)上運行aggExCluster,代碼按預期工作:

> aglomr2 <- aggExCluster(negDistMat(r=2), fci)
> aglomr2

AggExResult object

Number of samples          =  1045 
Maximum number of clusters =  1045 

結果可以用樹狀圖繪制,一切都很好; 但是,使用上面獲得的APResult(apclr2q02)作為輸入,將返回以下錯誤:

> aglomr2 <- aggExCluster(negDistMat(r=2), apclr2q02)
Error in as.vector(data) : 
  no method for coercing this S4 class to a vector

有關APResult對象作為輸入可能出錯的建議嗎?

如果要在作為' ExClust '或' APResult '對象給出的先前聚類結果之上使用aggExCluster() ,則需要將這些對象作為參數' x '傳遞,此外,需要提供相似性矩陣。 這是一個基於您的示例的自包含代碼片段(請注意,從apcluster()返回的對象' apres '包括相似性矩陣):

cl1 <- cbind(rnorm(50,0.2,0.05),rnorm(50,0.8,0.06))
cl2 <- cbind(rnorm(50,0.7,0.08),rnorm(50,0.3,0.05))
x <- rbind(cl1,cl2)

apres <- apcluster(negDistMat(r=2), x, q=0.7)
aggExCluster(x=apres)

如果您從相似性矩陣開始,您可以將其包含在“APResult”對象中,即

sim <- negDistMat(r=2, x)
apres <- apcluster(sim, q=0.7, includeSim=TRUE)
aggExCluster(x=apres)

(如果在相似度矩陣上調用apcluster()則默認情況下矩陣不包含在結果對象中,可以使用“ includeSim=TRUE ”覆蓋該矩陣

或者,您也可以通過參數' s '指定相似性矩陣:

sim <- negDistMat(r=2, x)
apres <- apcluster(sim, q=0.7)
aggExCluster(x=apres, s=sim)

使用相似性函數和' APResult '對象調用aggExCluster()將不起作用,因為' APResult '不包含原始數據,因此aggExCluster()無法計算聚類所需的相似性矩陣。 相反,如果使用參數' s '作為相似函數調用aggExCluster() ,它期望參數' x '包含原始數據,因此將嘗試將其轉換為子表對象。 這就是您收到此錯誤消息的原因。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM