degree_distribution method clarification

Hi everyone, congratulations for this amazing tool! :slight_smile:

I have a question regarding the usage of the degree_distribution method:
link

To my understanding, plotting the result of:

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

Yes.

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:

> 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

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

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.

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?