model geometric distribution

2

What command in R studio should I use for the next case?

On the roll of a die, count the number of times the die is rolled until it rolls 6.

I need to model a geometric distribution for 10000 releases assigning different probabilities and observing the behavior of the graph. I do not know what programming expression to use to count the number of runs until the success (number 6). Thanks

    
asked by NZLR 31.08.2018 в 18:16
source

2 answers

0

the probability of getting a 6 on a throw is 1/6

the probability of not getting a 6 on a throw is 5/6

but your question is focused on the simulation of 1000 launches, for them we use sample .

probabilidades <- sample(6,1000, replace='TRUE')
probabilidadesConNo6 <- probabilidades[probabilidades < 6]

length(probabilidadesConNo6) / length(probabilidades) //esta es la probabilidad de 1000 lanzamientos

The replace = 'TRUE' to be independent

    
answered by 31.08.2018 в 18:39
0

If you are looking for a simulation, you can first implement a function that simulates throwing the dice until you get the expected result:

intentos <- function(resultado_buscado) {
    i <- 1
    while (!(sample(1:6,size=1)==resultado_buscado)) {
        i <- i + 1
    }
    return (i)
}    

The previous function will generate a random result among the 6 possible ones and will repeat the cycle until obtaining the value that we are looking for.

Then we can repeat the procedure the n times we want, for this we can use an implicit loop with sapply() , finally with table() we will generate the frequency table

table(sapply(1:10000, function(x) {intentos(6)}))

  1    2    3    4    5    6    7    8    9   10   11   12   13   14   15 
1665 1417 1127 1019  833  654  567  437  376  323  254  228  192  161  125 
  16   17   18   19   20   21   22   23   24   25   26   27   28   29   30 
 123   81   61   61   54   36   32   27   28   20   20   13   14   10    6 
  31   33   34   35   36   37   38   41   42   44   46   47   52   61 
   9    6    1    3    4    2    2    1    3    1    1    1    1    1 
    
answered by 01.09.2018 в 05:13