# How to create graphs without multi-edges from the sample\_pa\_age function?

**URL:** <https://igraph.discourse.group/t/how-to-create-graphs-without-multi-edges-from-the-sample-pa-age-function/1758>\
**Category:** Usage\
**Tags:** R\
**Created:** [24 February 2024 09:45 UTC](https://igraph.discourse.group/t/how-to-create-graphs-without-multi-edges-from-the-sample-pa-age-function/1758 "2024-02-24T09:45:28Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![Ava999](https://yyz2.discourse-cdn.com/free1/user_avatar/igraph.discourse.group/ava999/32/1039_2.png) [@Ava999](https://igraph.discourse.group/u/Ava999)\
**Post date:** [24 February 2024 09:45 UTC](https://igraph.discourse.group/t/how-to-create-graphs-without-multi-edges-from-the-sample-pa-age-function/1758/1 "2024-02-24T09:45:28Z")

</div>

To investigate the properties of a citation network, I am modelling a Barabasi-Albert graph with aging exponent, and I would like to apply the igraph function [sample\_pa\_age](https://igraph.org/r/doc/sample_pa_age.html). However, this graph also generates multi-edges, which I would like to avoid. For the sample\_pa function it is possible to choose the algorithm for generating the BA graph, but this is not an option for the sample\_pa\_age function. I cannot remove multi-edges afterwards, because they won’t have the correct degree distribution, and I would like the sample\_pa function and the sample\_pa\_age function to yield the same graph (if chosen the same random seed) if the aging.exp is set to 0 for the sample\_pa\_age function.

Any help is appreciated!

---

<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:** [24 February 2024 21:47 UTC](https://igraph.discourse.group/t/how-to-create-graphs-without-multi-edges-from-the-sample-pa-age-function/1758/2 "2024-02-24T21:47:19Z")

</div>

> [@Ava999](#):
>
> However, this graph also generates multi-edges, which I would like to avoid.

Can you show a minimal example of a command (and random seed) that produces non-simple graphs?

---

<div class="post-metadata">

**Author:** ![dan\_suthers](https://yyz2.discourse-cdn.com/free1/user_avatar/igraph.discourse.group/dan_suthers/32/254_2.png) [@dan\_suthers](https://igraph.discourse.group/u/dan_suthers)\
**Post date:** [25 February 2024 00:23 UTC](https://igraph.discourse.group/t/how-to-create-graphs-without-multi-edges-from-the-sample-pa-age-function/1758/3 "2024-02-25T00:23:35Z")

</div>

Hi Ava999,  
I don’t think there is a way to control this with sample\_pa\_age. The documentation does say “This function might generate graphs with multiple edges.”  
How much will this matter? As a graph grows, the probability of multiedges gets very small (there are more nodes for the m new edges to choose from), so for large models will be an insignificant fraction. Could you just allow both to have multi-edges? Then both will be “correct” degree distributions under their models.  
I’m also unclear on what you mean by having two different random models generate the “same graph”. If you want the same graph, just copy it, so you must mean something else.  
DS

---

<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:** [25 February 2024 16:41 UTC](https://igraph.discourse.group/t/how-to-create-graphs-without-multi-edges-from-the-sample-pa-age-function/1758/4 "2024-02-25T16:41:13Z")

</div>

> [@dan\_suthers](#):
>
> The documentation does say “This function might generate graphs with multiple edges.”

It does say that, but the simple examples I tried didn’t generate multi-edges. It’d be good to have an example that does to understand if multi-edges can be avoided.

---

<div class="post-metadata">

**Author:** ![Ava999](https://yyz2.discourse-cdn.com/free1/user_avatar/igraph.discourse.group/ava999/32/1039_2.png) [@Ava999](https://igraph.discourse.group/u/Ava999)\
**Post date:** [26 February 2024 20:09 UTC](https://igraph.discourse.group/t/how-to-create-graphs-without-multi-edges-from-the-sample-pa-age-function/1758/5 "2024-02-26T20:09:46Z")

</div>

Yes, sorry of course! dan\_suthers does make a good point that it might not matter for larger models, I was experimenting with smaller examples to try out the function

```auto
set.seed(99)
h <- sample_pa_age(10, pa.exp=1, m=2, aging.exp=0)
plot(h, layout = layout_nicely)

```

---

<div class="post-metadata">

**Author:** ![Ava999](https://yyz2.discourse-cdn.com/free1/user_avatar/igraph.discourse.group/ava999/32/1039_2.png) [@Ava999](https://igraph.discourse.group/u/Ava999)\
**Post date:** [26 February 2024 20:14 UTC](https://igraph.discourse.group/t/how-to-create-graphs-without-multi-edges-from-the-sample-pa-age-function/1758/6 "2024-02-26T20:14:02Z")

</div>

Hi Dan,  
Thank you for your reply, and good point! I’ll keep that in mind when I work with the larger models, for now I was mostly trying to get a grasp of how the R functions work.

As for the “same graph”, I wanted to generate the same graph by the sample\_pa function (to see if they would yield the same result), e.g.

```auto
set.seed(99)
g <- sample_pa(10, power = 1,m = 2)
plot(g, layout = layout_nicely)

```

as I would with the sample\_pa\_age function, but with the aging.exp set to 0, so

```auto
set.seed(99)
h <- sample_pa_age(10, pa.exp=1, m=2, aging.exp=0)
plot(h, layout = layout_nicely)

```

---

<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:** [26 February 2024 20:38 UTC](https://igraph.discourse.group/t/how-to-create-graphs-without-multi-edges-from-the-sample-pa-age-function/1758/7 "2024-02-26T20:38:08Z")

</div>

I’m sorry, I didn’t look carefully. This function does indeed create multi-edges and does not support simple graphs the same way `sample_pa()` does.

If you need a version that creates simple graphs, feel free to open a feature request at [GitHub - igraph/igraph: Library for the analysis of networks](https://github.com/igraph/igraph/) Be sure to explain in detail what you need it for. I should say that no improvements were planned for this function, but if there is enough demand, we may return to it.
