R plot graphics statistics people same birthday

78 Views Asked by At

I want to code the birthday problem in R using the plot . I've wrote the code the problem is that I get an error with that .

Any idea is welcomed .Thank you very much .

Edit edit I've changed the code :

paradoxe_anniversaires <- function(n){
  N<-365
  produit = 1 ;

    for(i in 1:(n-1))
    produit<-produit*(1 -(i/N) )

 resultat <- (1 - produit)
 return (resultat)
}
graphe_anniv <- function(){
  x<- c(1:100)
  y<-paradoxe_anniversaires(x)
  plot(x,y)
}

but this time I have Error in xy.coords(x, y, xlabel, ylabel, log) : 'x' and 'y' lengths differ In addition: Warning message: In 1:(n - 1) :

Error in xy.coords(x, y, xlabel, ylabel, log) : 'x' and 'y' lengths differ

1

There are 1 best solutions below

3
On

I think the problem is with taking the factorial of 365. When I just try to run factorial(365) in R, it returns the same errors about the value out of range in 'gammafn'. I ran your code with a smaller value for N and it works just fine. It seems to work fine with values of N which are less than or equal to 170.