 # How can I calculate knn(k) of not simple graph?

I try to use

``````knn(graph)\$knnk
``````

where “graph” is not simple graph. But igraph out error message.
How can I avoid simplifying of my graph and get knnk of it?

Cross-posted to StackOverflow.

For reference, the relevant issue is here:

I see you also posted the question on StackOverflow. This is fine, but please do cross-link your posts so that people won’t waste time answering an already-answered question (one of the cross-posts is bound to get an answer before the other).

Since you want to compute this for a non-simple graph, a few questions:

Initially, I have undirected simple graph, but after using:

``````rewire(as.undirected(graph), with = keeping_degseq(loops = TRUE, niter=100000000))
``````

I get non-simple graph with loops. So, I need to combine plots of original graph’s knn(k) and rewired graph’ knn(k).
(All graphs are not weighted)

Yes, this is because you explicitly allowed loop creation using `loops = TRUE`. Can you explain why you are doing this if the starting graph is simple? What is your goal with `rewire`?

My starting graph is Disassortative, but it is Structural Disassortativity. I use rewire() function for Degree Preserving Randomization for free of Structural Disassortativity.

In that case, would it not make more sense to keep the graph loop-free, as it was originally, i.e. use `rewire` with `loops = FALSE`?

Then you will not need to think about how to define the average neighbour degree in loopy graphs.

So, I just have rewired graph loop-free (use loop=FALSE early).
If that’s enough for free of structural disassortativity, then my problem is solved. Thank you.