Probabilidad: Es el 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 acción cuyo resultado está sujeto a la incertidumbre. Ejemplo: Lanzar una moneda al aire.
# install.packages("dice")
library(dice)
# install.packages("MASS")
library(MASS)
# install.packages("tidyverse")
library(purrr) 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 = 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,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")#T= 10
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 ## 34 31 40 33 13
## "9C" "6P" "2D" "8T" "AT"