#install.packages("dice")
library(dice)
## Loading required package: gtools
#install.packages("gtools")
library(gtools)
#install.packages("MASS")
library(MASS)
#probabilidad de obtener un 5
un_seis <- getEventProb (nrolls = 1, ndicePerRoll = 1, nsidesPerDie = 6, eventList = list(6))
un_seis
## [1] 0.1666667
fractions(un_seis)
## [1] 1/6
un_cinco <- getEventProb(nrolls = 2, ndicePerRoll = 1, nsidesPerDie = 6, eventList = list(5))
un_cinco
## [1] 0.3055556
fractions(un_cinco)
## [1] 11/36
dos_cinco <- getEventProb(nrolls = 2, ndicePerRoll = 1, nsidesPerDie = 6, eventList = list(5,5))
dos_cinco
## [1] 0.02777778
fractions(dos_cinco)
## [1] 1/36
sumar_dos <- getEventProb(nrolls = 1, ndicePerRoll = 2, nsidesPerDie = 6, eventList = list(2))
sumar_tres <- getEventProb(nrolls = 1, ndicePerRoll = 2, nsidesPerDie = 6, eventList = list(3))
sumar_cuatro <- getEventProb(nrolls = 1, ndicePerRoll = 2, nsidesPerDie = 6, eventList = list(4))
sumar_cinco <- getEventProb(nrolls = 1, ndicePerRoll = 2, nsidesPerDie = 6, eventList = list(5))
sumar_seis <- getEventProb(nrolls = 1, ndicePerRoll = 2, nsidesPerDie = 6, eventList = list(6))
sumar_siete <- getEventProb(nrolls = 1, ndicePerRoll = 2, nsidesPerDie = 6, eventList = list(7))
sumar_ocho <- getEventProb(nrolls = 1, ndicePerRoll = 2, nsidesPerDie = 6, eventList = list(8))
sumar_nueve <- getEventProb(nrolls = 1, ndicePerRoll = 2, nsidesPerDie = 6, eventList = list(9))
sumar_diez <- getEventProb(nrolls = 1, ndicePerRoll = 2, nsidesPerDie = 6, eventList = list(10))
sumar_once <- getEventProb(nrolls = 1, ndicePerRoll = 2, nsidesPerDie = 6, eventList = list(11))
sumar_doce <- getEventProb(nrolls = 1, ndicePerRoll = 2, nsidesPerDie = 6, eventList = list(12))
suma <- c(2,3,4,5,6,7,8,9,10,11,12)
probabilidad <- c(sumar_dos,sumar_tres, sumar_cuatro, sumar_cinco, sumar_seis, sumar_siete, sumar_ocho, sumar_nueve, sumar_diez, sumar_once, sumar_doce)
tabla <- cbind(suma, probabilidad)
barplot(probabilidad, names.arg =suma, main = "Probabilidad", xlab = "suma de 2 dados", col = "Tomato" )
#EXPERIMENTO : MANO DE POKER
#install.packages("tidyverse")
library(purrr)
#crear baraja inglesa
numero <- c (2,3,4,5,6,7,8,9,"D", "J", "Q", "K", "A")
numeros <- rep(numero, 4)
palo <- c ("T", "C", "P", "D")
palos <-rep(palo, 13)
baraja <- data.frame(numeros, palos)
#crear el mazo de barajas
mazo <- apply(format(baraja),1, paste, collapse="")
mazo
## 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
## "2T" "3C" "4P" "5D" "6T" "7C" "8P" "9D" "DT" "JC" "QP" "KD" "AT" "2C" "3P" "4D"
## 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32
## "5T" "6C" "7P" "8D" "9T" "DC" "JP" "QD" "KT" "AC" "2P" "3D" "4T" "5C" "6P" "7D"
## 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48
## "8T" "9C" "DP" "JD" "QT" "KC" "AP" "2D" "3T" "4C" "5P" "6D" "7T" "8C" "9P" "DD"
## 49 50 51 52
## "JT" "QC" "KP" "AD"
#crear la mano de cartas
mano <- function(n) sample(mazo, n, rep=FALSE)
mi_mano <- mano (5)
mi_mano
## 47 12 52 6 27
## "9P" "KD" "AD" "7C" "2P"
Es interesante como podemos jugar con los números y conocer las probabilidades de obtener como pudimos ver en el ejemplo un 5 al lanzar un dado y despúes en la baraja la infinidad de posibilidades de que te salga una cosa u otra entre las posibilidades y caracterisiticas que tiene la baraja inglesa.