0

解釈するには多すぎることがわかっているため、より少ないクラスターにカットしたい樹形図があります。私のデータフレームは次のようになります。

    > head(alpha)
              locs 2009 2010 2011 2012 2013 2014 2015 2016 2017 2018
    1           A1   12   14   15   15   14   21   10   18   18   20
    2           A2   11   11   12   13    9   16   20   18   18   11
    3           B1   12   13   20   17   21   20   27   14   22   25
    4           B2   15   18   18   25   21   17   27   23   28   23
    5           B3   22   22   26   24   28   23   31   25   32   25
    6           B4   18   21   25   20   20   14   23   22   20   26

    library("ggplot2") #for the heatmap
    library("ggdendro") #for the dendrogram 
    library("reshape2") #for data wrangling
    library("grid") #to combine the two plots heatmap and dendrogram

    # Read in data
    setwd("C:/Users/data")
    alpha <- read.csv2("alpha.csv", header=TRUE, check.names=FALSE) 
    str(alpha) #structure of the dataset: locations (locs) = factor, values = integer

    #scale the data variables (columns 4-9)
    alpha.scaled <- alpha
    alpha.scaled[, c(2:11)] <- scale(alpha.scaled[, 2:11])
    alpha.scaled[, c(2:11)] <- scale(alpha.scaled[, 2:11])

    # run clustering
    alpha.matrix <- as.matrix(alpha.scaled[, -c(1)])
    rownames(alpha.matrix) <- alpha.scaled$locs

    alpha.dendro <- as.dendrogram(hclust(d = dist(x = alpha.matrix), method="complete" ))

    # Create dendrogram (=cluster)
    dendro.plot <- ggdendrogram(data = alpha.dendro, rotate = TRUE)

    alphacut <- cutree(alpha.dendro, h=3) 

alphacut <- cutree(alpha.dendro, h=3)

cutree(alpha.dendro, h = 3) のエラー:

'tree' が正しくありません (composante 'merge')

    alphacut <- cutree(as.dendrogram(hclust(d = dist(x = alpha.matrix), method="complete" )),k=5)

alphacut <- cutree(as.dendrogram(hclust(d = dist(x = alpha.matrix), method="complete" )), k=5)

cutree(as.dendrogram(hclust(d = dist(x = alpha.matrix), method = "complete")) のエラー:

'tree' が正しくありません (composante 'merge')

私はこれに対する解決策を見つけていません。「alpha.dendro」を見ると、2 つのリストがありますが、マージ コンポーネントがないため、これが問題のようです。誰かが何をすべきか知っていますか?

4

0 に答える 0