Probabilidad: Estudio de azar y la incertidumbre en cualquier situacion en la cual varios posibles sucesos pueden ocurrir.
Es un valor entre 0 (imposible) y 1 (seguro).
Ejemplo: La probabilidad de que llueva hoy es de 0.70 (70%).
Experimento: Cualquier accion cuyo resultado esta sujeto a la incertidumbre.
Ejemplo: Lanzar una moneda al aire.
#install.packages ("dice")
library (dice)
## Loading required package: gtools
#install.packages ("MASS")
library (MASS)
un_seis <- getEventProb(nrolls = 1, ndicePerRoll = 1,nsidesPerDie = 6, eventList = list(1))
un_seis
## [1] 0.1666667
fractions(un_seis)
## [1] 1/6
un_cinco <- getEventProb(nrolls = 1, ndicePerRoll = 2,nsidesPerDie = 6, eventList = list(5))
un_cinco
## [1] 0.1111111
fractions(un_cinco)
## [1] 1/9
dos_cincos <- getEventProb(nrolls = 2, ndicePerRoll = 1,nsidesPerDie = 6, eventList = list(5,5))
dos_cincos
## [1] 0.02777778
fractions(dos_cincos)
## [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,10,11,12)
probabilidad <- c(sumar_dos, sumar_tres, sumar_cuatro, sumar_cinco, sumar_seis, 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")
#install.packages ("tidyverse")
library (purrr)
conjunto_cartas <- c("A",2:10,"J","Q","K")
cartas <-c (rep(conjunto_cartas, 4))
conjunto_tipos <-c ("Corazon", "Diamante", "Trebol", "Espada")
tipos <-c (rep(conjunto_tipos, rep(13,4)))
baraja = data.frame(cartas,tipos)
baraja
## cartas tipos
## 1 A Corazon
## 2 2 Corazon
## 3 3 Corazon
## 4 4 Corazon
## 5 5 Corazon
## 6 6 Corazon
## 7 7 Corazon
## 8 8 Corazon
## 9 9 Corazon
## 10 10 Corazon
## 11 J Corazon
## 12 Q Corazon
## 13 K Corazon
## 14 A Diamante
## 15 2 Diamante
## 16 3 Diamante
## 17 4 Diamante
## 18 5 Diamante
## 19 6 Diamante
## 20 7 Diamante
## 21 8 Diamante
## 22 9 Diamante
## 23 10 Diamante
## 24 J Diamante
## 25 Q Diamante
## 26 K Diamante
## 27 A Trebol
## 28 2 Trebol
## 29 3 Trebol
## 30 4 Trebol
## 31 5 Trebol
## 32 6 Trebol
## 33 7 Trebol
## 34 8 Trebol
## 35 9 Trebol
## 36 10 Trebol
## 37 J Trebol
## 38 Q Trebol
## 39 K Trebol
## 40 A Espada
## 41 2 Espada
## 42 3 Espada
## 43 4 Espada
## 44 5 Espada
## 45 6 Espada
## 46 7 Espada
## 47 8 Espada
## 48 9 Espada
## 49 10 Espada
## 50 J Espada
## 51 Q Espada
## 52 K Espada
mano = baraja [sample(1:52, 5, replace = F),]
mano
## cartas tipos
## 52 K Espada
## 51 Q Espada
## 9 9 Corazon
## 28 2 Trebol
## 2 2 Corazon
numero <- c(2,3,4,5,6,7,8,9,"T","J","Q","K","A")
numeros <- rep(numero,4)
palo <- c("T", "C", "P", "D")
palos <- rep(palo,13)
baraja <- data.frame(numeros,palos)
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" "TT" "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" "TC" "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" "TP" "JD" "QT" "KC" "AP" "2D" "3T" "4C" "5P" "6D" "7T" "8C" "9P" "TD"
## 49 50 51 52
## "JT" "QC" "KP" "AD"
mano <- function(n) sample(mazo, n, rep =FALSE)
mi_mano <- mano(5)
mi_mano
## 12 41 25 5 19
## "KD" "3T" "KT" "6T" "7P"