"install.packages(′gtools′)"
## [1] "install.packages('gtools')"
(library(gtools))
## [1] "gtools" "stats" "graphics" "grDevices" "utils" "datasets"
## [7] "methods" "base"
permutacion_repe= permutations(14, 4, set= FALSE, repeats.allowed= TRUE)
permutacion_sin_repe= permutations(14, 4, v= 1:14, set=FALSE, repeats.allowed= FALSE)
print(nrow(permutacion_repe))
## [1] 38416
print(nrow(permutacion_sin_repe))
## [1] 24024
letras=c ("a", "b", "c")
combi_repe= combinations(length(letras), 3, letras, set= FALSE, repeats.allowed= TRUE)
combi_sinrepe= combinations(length(letras), 3, letras, repeats.allowed= FALSE)
print(combi_repe)
## [,1] [,2] [,3]
## [1,] "a" "a" "a"
## [2,] "a" "a" "b"
## [3,] "a" "a" "c"
## [4,] "a" "b" "b"
## [5,] "a" "b" "c"
## [6,] "a" "c" "c"
## [7,] "b" "b" "b"
## [8,] "b" "b" "c"
## [9,] "b" "c" "c"
## [10,] "c" "c" "c"
print(combi_sinrepe)
## [,1] [,2] [,3]
## [1,] "a" "b" "c"
permutacion_sinrepe= permutations(30,2)
combinacion_sinrepe= combinations(30, 2)
print(nrow(permutacion_sinrepe))
## [1] 870
print(nrow(combinacion_sinrepe))
## [1] 435
Bayes = function(PBA, PA, PB) {
(PAB*PA)/PB
}
datos = apply(Titanic, c(1,4), sum)
datos
## Survived
## Class No Yes
## 1st 122 203
## 2nd 167 118
## 3rd 528 178
## Crew 673 212
P_pasajeros= ((sum(datos[5:7]))/(sum(datos[1:3], datos[5:7]))) * 100
P_tripulación= 100 * ((datos[8])/(sum(datos[4], datos[8])))
P_pasajeros
## [1] 37.91793
P_tripulación
## [1] 23.9548
datos = apply(Titanic, c(1,2,4), sum)
datos
## , , Survived = No
##
## Sex
## Class Male Female
## 1st 118 4
## 2nd 154 13
## 3rd 422 106
## Crew 670 3
##
## , , Survived = Yes
##
## Sex
## Class Male Female
## 1st 62 141
## 2nd 25 93
## 3rd 88 90
## Crew 192 20
P_mujer= (sum(datos[16]))/(sum(datos[8], datos[16]))
P_mujer
## [1] 0.8695652
datos = apply(Titanic, c(1,3,4), sum)
datos
## , , Survived = No
##
## Age
## Class Child Adult
## 1st 0 122
## 2nd 0 167
## 3rd 52 476
## Crew 0 673
##
## , , Survived = Yes
##
## Age
## Class Child Adult
## 1st 6 197
## 2nd 24 94
## 3rd 27 151
## Crew 0 212
P_menor_de_edad= (sum(datos[11]))/(sum(datos[3], datos[11]))
P_menor_de_edad
## [1] 0.3417722
datos= apply(Titanic, c(2,3,4), sum)
P_mujeres= (sum(datos[8]))/(sum(datos[8], datos[4]))
P_nignos= (sum(datos[5:6]))/(sum(datos[1:2], datos[5:6]))
P_hombres= (sum(datos[7]))/(sum(datos[7], datos[3]))
P_nignos_y_mujeres = P_mujeres * P_nignos
P_mujeres
## [1] 0.7435294
P_nignos
## [1] 0.5229358
P_hombres
## [1] 0.2027594
P_nignos_y_mujeres
## [1] 0.3888181
set.seed(100)
sample((apply(Titanic, c(1), sum)), 1)
## 2nd
## 285
datos= apply(Titanic, c(1, 2, 3, 4), sum)
P_mujer = (sum(datos[30]))/(sum(datos[30], datos[14]))
P_nignos = (sum(datos[18],datos[22]))/(sum(datos[18], datos[22], datos[2], datos[6]))
P_hombres= (sum(datos[27]))/(sum(datos[27], datos[10]))
P_nignos_y_mujeres = P_mujer * P_nignos
P_mujer
## [1] 0.8602151
P_nignos
## [1] 1
P_hombres
## [1] 0.3275109
P_nignos_y_mujeres
## [1] 0.8602151