igraph-help
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [igraph] Questions about walktrap.community


From: Wang, Jing
Subject: Re: [igraph] Questions about walktrap.community
Date: Mon, 31 Oct 2011 10:05:18 -0500
User-agent: Microsoft-MacOutlook/14.10.0.110310

Dear Gabor,

        It work now. Thank you very much for your help! Happy Holloween!

Best,
Jing

On 10/31/11 9:44 AM, "Gábor Csárdi" <address@hidden> wrote:

>Hmmm, as.hclust.dendrogram requires integers as node ids, quite
>strange, since this is usually not done in R. I have fixed this in the
>0.5 development tree. Here is the new version of the as.dendrogram
>function for walktrap objects. You can just redefine this in your
>code. Please tell me if there are any more problems.
>
>Btw. similar fixed were needed for as.dendrogram versions operating on
>the output of edge-betweenness based and leading eigenvector based
>community detection.
>
>Best,
>Gabor
>
>########################
>
>as.dendrogram.igraph.walktrap <- function (object, hang=-1,
>                                           use.modularity=FALSE, ...)
>{
>  stopifnot(nrow(object$merges)> 0)
>  storage.mode(object$merges) <- "integer"
>  object$merges <- object$merges + 1L
>  if (is.null(object$labels))
>    object$labels <- 1:(nrow(object$merges)+1)-1
>  z <- list()
>  if (!use.modularity || is.null(object$modularity)) {
>    object$height <- 1:nrow(object$merges)
>  } else {
>    object$height <- object$modularity[-1]
>    object$height <- cumsum(object$height - min(object$height))
>  }
>  nMerge <- length(oHgt <- object$height)
>  if (nMerge != nrow(object$merges))
>    stop("'merge' and 'height' do not fit!")
>  hMax <- oHgt[nMerge]
>  one <- 1:1;
>  two <- 2:2 # integer!
>  leafs <- nrow(object$merges)+1
>  for (k in 1:nMerge) {
>    x <- object$merges[k, ]# no sort() anymore!
>    if (any(neg <- x < leafs+1))
>      h0 <- if (hang < 0) 0 else max(0, oHgt[k] - hang * hMax)
>    if (all(neg)) {                  # two leaves
>      zk <- as.list(x)
>      attr(zk, "members") <- two
>      attr(zk, "midpoint") <- 0.5 # mean( c(0,1) )
>      objlabels <- object$labels[x]
>      attr(zk[[1]], "label") <- objlabels[1]
>      attr(zk[[2]], "label") <- objlabels[2]
>      attr(zk[[1]], "members") <- attr(zk[[2]], "members") <- one
>      attr(zk[[1]], "height") <- attr(zk[[2]], "height") <- h0
>      attr(zk[[1]], "leaf") <- attr(zk[[2]], "leaf") <- TRUE
>    }
>    else if (any(neg)) {            # one leaf, one node
>      X <- as.character(x)
>      ## Originally had "x <- sort(..) above => leaf always left, x[1];
>      ## don't want to assume this
>      isL <- x[1] < leafs+1 ## is leaf left?
>      zk <-
>        if(isL) list(x[1], z[[X[2]]])
>        else    list(z[[X[1]]], x[2])
>      attr(zk, "members") <- attr(z[[X[1 + isL]]], "members") + one
>      attr(zk, "midpoint") <-
>        (igraph:::.memberDend(zk[[1]]) + attr(z[[X[1 + isL]]],
>"midpoint"))/2
>      attr(zk[[2 - isL]], "members") <- one
>      attr(zk[[2 - isL]], "height") <- h0
>      attr(zk[[2 - isL]], "label") <- object$labels[x[2 - isL]]
>      attr(zk[[2 - isL]], "leaf") <- TRUE
>      }
>    else {                        # two nodes
>      x <- as.character(x)
>      zk <- list(z[[x[1]]], z[[x[2]]])
>      attr(zk, "members") <- attr(z[[x[1]]], "members") +
>        attr(z[[x[2]]], "members")
>      attr(zk, "midpoint") <- (attr(z[[x[1]]], "members") +
>                               attr(z[[x[1]]], "midpoint") +
>                               attr(z[[x[2]]], "midpoint"))/2
>    }
>    attr(zk, "height") <- oHgt[k]
>    z[[k <- as.character(k+leafs)]] <- zk
>  }
>  z <- z[[k]]
>  class(z) <- "dendrogram"
>  z
>}
>
>
>
>
>On Fri, Oct 28, 2011 at 6:19 PM, Wang, Jing <address@hidden>
>wrote:
>> Dear Gabor,
>>
>>        I can transform the walktrap data to dendrogram using
>>as.dendrogram, but
>> when I transform the dendrogram to hclust type (because some functions
>> need hclust type, so I must get the hclust data), I always get the
>> following error:
>>
>>        Error: all(vapply(s, is.integer, NA)) is not TRUE
>>
>> So, would you please give me some suggestion how to address this error?
>> Thank you very much for you help!
>>
>> Best,
>> Jing
>>
>> On 10/28/11 3:36 PM, "Gábor Csárdi" <address@hidden> wrote:
>>
>>>On Fri, Oct 28, 2011 at 6:53 AM, Tamas Nepusz <address@hidden> wrote:
>>>[...]
>>>>> I have two questions about walktrap.community. The first question is
>>>>>whether
>>>>> there is a method to change the result of walktrap.community to a
>>>>>"hclust"
>>>>> class.
>>>> I'm not an expert in the R interface so I cannot answer this question
>>>>-- but
>>>> maybe someone else on this list can.
>>>
>>>You can convert it to a 'dendogram' object, which you can simply plot
>>>via 'plot()'. Just call 'as.dendrogram()' on it.
>>>
>>>G.
>>>
>>>[...]
>>>
>>>--
>>>Gabor Csardi <address@hidden>     MTA KFKI RMKI
>>>
>>>_______________________________________________
>>>igraph-help mailing list
>>>address@hidden
>>>https://lists.nongnu.org/mailman/listinfo/igraph-help
>>>
>>
>>
>>
>> _______________________________________________
>> igraph-help mailing list
>> address@hidden
>> https://lists.nongnu.org/mailman/listinfo/igraph-help
>>
>
>
>
>-- 
>Gabor Csardi <address@hidden>     MTA KFKI RMKI
>
>_______________________________________________
>igraph-help mailing list
>address@hidden
>https://lists.nongnu.org/mailman/listinfo/igraph-help
>





reply via email to

[Prev in Thread] Current Thread [Next in Thread]