# degree\_distribution method clarification

**URL:** https://igraph.discourse.group/t/degree-distribution-method-clarification/522
**Category:** Usage
**Tags:** R
**Created:** [20 November 2020 09:55 UTC](https://igraph.discourse.group/t/degree-distribution-method-clarification/522 "2020-11-20T09:55:04Z")
**Posts on this page:** 5
**Page:** 1

<div class="post-metadata">

### Author: ![Eldin](https://yyz2.discourse-cdn.com/free1/user_avatar/igraph.discourse.group/eldin/32/403_2.png) [@Eldin](https://igraph.discourse.group/u/Eldin)
#### Post date: [20 November 2020 09:55 UTC](https://igraph.discourse.group/t/degree-distribution-method-clarification/522/1 "2020-11-20T09:55:04Z")

</div>

Hi everyone, congratulations for this amazing tool! 🙂

I have a question regarding the usage of the degree\_distribution method:  
[link](https://igraph.org/r/doc/degree.html)

To my understanding, plotting the result of:

```auto
degree_distribution(graph, cumulative = TRUE)

```

is to generate the so-called Complementary Cumulative Degree Distribution (CCDF of degree), am I right?  
in other words, the plot shows the number of vertices with degree at least k for every value of k, is it correct? Can anyone confirm this?

See: [link](https://math.stackexchange.com/questions/651672/commulative-degree-distribution-of-nodes-in-a-scale-free-network)

---

<div class="post-metadata">

### Author: ![szhorvat](https://yyz2.discourse-cdn.com/free1/user_avatar/igraph.discourse.group/szhorvat/32/3_2.png) [@szhorvat](https://igraph.discourse.group/u/szhorvat)
#### Post date: [20 November 2020 15:03 UTC](https://igraph.discourse.group/t/degree-distribution-method-clarification/522/2 "2020-11-20T15:03:50Z")

</div>

> [@Eldin](#):
>
> is to generate the so-called Complementary Cumulative Degree Distribution (CCDF of degree), am I right?

Yes.

> [@Eldin](#):
>
> in other words, the plot shows the number of vertices with degree at least k for every value of k, is it correct? Can anyone confirm this?

Yes, that is correct, and k starts at zero. So the $k+1$th element of the result is the fraction of vertices with degree at least k.

You can easily test this:

```auto
> g<-make_graph(c(1,2, 2,3), directed = F)
> degree_distribution(g)
[1] 0.0000000 0.6666667 0.3333333
> degree_distribution(g, cumulative = T)
[1] 1.0000000 1.0000000 0.3333333

```

---

<div class="post-metadata">

### Author: ![Eldin](https://yyz2.discourse-cdn.com/free1/user_avatar/igraph.discourse.group/eldin/32/403_2.png) [@Eldin](https://igraph.discourse.group/u/Eldin)
#### Post date: [20 November 2020 15:19 UTC](https://igraph.discourse.group/t/degree-distribution-method-clarification/522/3 "2020-11-20T15:19:12Z")

</div>

Hi, thank you for your response. I was curious to understand why degree\_distribution:

```
 dg2 = degree_distribution(g, cumulative=TRUE, mode="in")
 dg2 = dg2[dg2 > 0] # filter out 0 values to plot on a log-log

```

and the following custom code:

```
 dist = degree(g, mode="in)
 dg1 = list();
 for (i in 1:max(dist)) { # I start from 1 rather than 0 because I want to plot on a log-log
   dg1[i] = length(dist[dist >= i]) / length(dist);
 }

```

produce two slightly different log-log plots:

```
plot(dg2, log="xy", type="l", xlab="Number of vertices", ylab="P(X >= k)")
lines(1:max(dist), dg1, col="red")

```

You can see the attached image. What am I doing wrong with my code? ![plot](https://global.discourse-cdn.com/free1/uploads/igraph/original/1X/298e8a6611c7255cb65f5dd2a5b935e9adb322ae.png)

---

<div class="post-metadata">

### Author: ![szhorvat](https://yyz2.discourse-cdn.com/free1/user_avatar/igraph.discourse.group/szhorvat/32/3_2.png) [@szhorvat](https://igraph.discourse.group/u/szhorvat)
#### Post date: [20 November 2020 15:35 UTC](https://igraph.discourse.group/t/degree-distribution-method-clarification/522/4 "2020-11-20T15:35:15Z")

</div>

I don’t use R, but this: `dg2 = dg2[dg2 > 0]` seems wrong to me. If you drop the k th element, the k+1 th becomes the k th. It is no longer true that the k th element is the frequency of degree k-1.

---

<div class="post-metadata">

### Author: ![Eldin](https://yyz2.discourse-cdn.com/free1/user_avatar/igraph.discourse.group/eldin/32/403_2.png) [@Eldin](https://igraph.discourse.group/u/Eldin)
#### Post date: [20 November 2020 15:53 UTC](https://igraph.discourse.group/t/degree-distribution-method-clarification/522/5 "2020-11-20T15:53:17Z")

</div>

I tried to plot with and without the line:

```
 dg2 = dg2[dg2 > 0]

```

…it doesn’t make any difference, the result is the same. That line of code doesn’t affect the plot. Also, if k becomes k+1, the situation should be made even by the fact that in the for loop I am not counting the 0, so also in that case I should have k that becomes k+1…

What do you think?
