2

The issue I am having is that for an assignment for a network analysis class I need to use the erdos.renyi.game command from the igraph package for R. This command looks like this:

erdos.renyi.game(n, p.or.m, type=c("gnp", "gnm"),
                 directed = FALSE, loops = FALSE, ...)

Unfortunately, it does not matter what I fill in for n or m (I need m), type, or directed, I always get the same error:

Error in .Call("R_igraph_erdos_renyi_game", as.numeric(n), as.numeric(type1), : At games.c:585 : Invalid probability given, Invalid value

The people around me in class used the exact same code as I did, and for them it worked. So could anyone please help me with this, because I am not really sure what is going on, and the teacher did not understand it either?

David Arenburg
  • 91,361
  • 17
  • 137
  • 196
Joes de Natris
  • 373
  • 1
  • 3
  • 5
  • Can you post the code that you're trying into the body of your question, formatting it accordingly please? Thanks. – ManoDestra Apr 08 '16 at 18:25
  • Welcome to StackOverflow. Please read [how do I ask a good question](http://stackoverflow.com/help/how-to-ask) and [proding a minimal reproducible example](http://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example#answer-5963610). You should provide the exact code that you tried (including loading the required packages). – lukeA Apr 08 '16 at 21:50

1 Answers1

1

I guess the 2nd value, which you pass on to erdos.renyi.game, is not a numeric value between 0 and 1:

library(igraph)
par(mfrow=c(1,3))
plot(erdos.renyi.game(10, p=1))
plot(erdos.renyi.game(10, p=.5))
plot(erdos.renyi.game(10, p=0))

erdos.renyi.game(10, p=10)
# Error in .Call("R_igraph_erdos_renyi_game", as.numeric(n), as.numeric(type1),  : 
#   At games.c:585 : Invalid probability given, Invalid value

For example, 10 is greater 1 and therefore not a valid probability.

lukeA
  • 53,097
  • 5
  • 97
  • 100
  • 1
    The function is a bit confusing. I just read that you need `m`, not `p` - in that case you have to change the `type` parameter: `g <- erdos.renyi.game(10, p.or.m=2, type="gnm")`. `2` is the number of desired edges. – lukeA Apr 09 '16 at 12:34