19041198 MARCO DANIEL DE LA TORRE MENDIA
Las librerías
library(readr)
Los datos
Como son pocos tados se pueden cargar dirctamente de la WEB así como también se pueden descargar y tratarlos localmente.
#datos <- read.csv("https://raw.githubusercontent.com/rpizarrog/probabilidad-y-estad-stica/master/practicas%20R/unidad%202/participantes%20en%20equipos%20deportivos.csv")
datos <- read.csv("https://raw.githubusercontent.com/rpizarrog/probabilidad-y-estad-stica/master/practicas%20R/unidad%202/alumnos.deportes.2020.csv")
datos
## X nombres sexo futbol basquetbol voleybol atletismo ajedrez tenis
## 1 1 Ana F FALSE FALSE FALSE FALSE FALSE FALSE
## 2 2 Antonio M FALSE FALSE FALSE FALSE FALSE FALSE
## 3 3 Aracely F FALSE FALSE FALSE FALSE FALSE TRUE
## 4 4 Carmen F FALSE TRUE FALSE FALSE FALSE FALSE
## 5 5 Eduardo M TRUE FALSE FALSE FALSE FALSE FALSE
## 6 6 Ernesto M FALSE TRUE FALSE FALSE FALSE FALSE
## 7 7 Gabino M FALSE TRUE FALSE FALSE FALSE FALSE
## 8 8 Gerardo M TRUE FALSE TRUE FALSE FALSE TRUE
## 9 9 Javier M FALSE TRUE FALSE FALSE FALSE FALSE
## 10 10 Jeorgina F FALSE TRUE FALSE FALSE FALSE FALSE
## 11 11 Juan M TRUE FALSE FALSE TRUE FALSE FALSE
## 12 12 Lalo M FALSE FALSE TRUE FALSE FALSE FALSE
## 13 13 Laura F FALSE TRUE FALSE FALSE FALSE FALSE
## 14 14 Lucy F TRUE FALSE TRUE TRUE FALSE FALSE
## 15 15 Luis M FALSE FALSE TRUE FALSE FALSE FALSE
## 16 16 Luisa F FALSE FALSE FALSE FALSE FALSE FALSE
## 17 17 Lupita F TRUE TRUE FALSE FALSE FALSE FALSE
## 18 18 Margarita F FALSE TRUE FALSE TRUE FALSE FALSE
## 19 19 Margarito M FALSE FALSE FALSE FALSE FALSE TRUE
## 20 20 Maria F FALSE TRUE FALSE FALSE FALSE FALSE
## 21 21 Memo M TRUE FALSE FALSE FALSE TRUE FALSE
## 22 22 Oscar M FALSE FALSE FALSE FALSE FALSE FALSE
## 23 23 Paco M TRUE FALSE TRUE FALSE TRUE FALSE
## 24 24 Patricia F TRUE FALSE FALSE TRUE FALSE FALSE
## 25 25 Paty F TRUE TRUE FALSE FALSE FALSE FALSE
## 26 26 Raul M TRUE FALSE FALSE FALSE FALSE FALSE
## 27 27 Romualdo M TRUE FALSE FALSE FALSE FALSE FALSE
## 28 28 Rosario F FALSE FALSE FALSE FALSE FALSE FALSE
## 29 29 Rubén M TRUE FALSE FALSE FALSE FALSE FALSE
## 30 30 Salvador M TRUE FALSE FALSE TRUE FALSE FALSE
## 31 31 Sandra F FALSE FALSE FALSE FALSE FALSE FALSE
## 32 32 Sandro M FALSE FALSE FALSE FALSE FALSE TRUE
## 33 33 Saul M TRUE FALSE TRUE FALSE FALSE FALSE
## 34 34 Yuri F TRUE FALSE FALSE FALSE FALSE FALSE
## 35 35 Arturo M FALSE FALSE FALSE FALSE FALSE FALSE
## 36 36 Angélica F TRUE TRUE TRUE FALSE FALSE FALSE
## 37 37 Arnulfo M FALSE FALSE TRUE FALSE FALSE FALSE
## 38 38 Bety F TRUE TRUE FALSE FALSE FALSE FALSE
## 39 39 Carlos M TRUE FALSE FALSE FALSE FALSE FALSE
## 40 40 Dagoberto M FALSE FALSE TRUE FALSE FALSE FALSE
## 41 41 Dany F TRUE TRUE FALSE FALSE FALSE FALSE
## 42 42 Dalia F TRUE FALSE FALSE FALSE FALSE FALSE
## 43 43 Efren M TRUE FALSE FALSE TRUE FALSE FALSE
## 44 44 Ernestina F TRUE FALSE TRUE FALSE TRUE FALSE
## 45 45 Fernando M TRUE FALSE FALSE TRUE FALSE FALSE
## 46 46 Fabián M FALSE TRUE TRUE FALSE FALSE FALSE
## 47 47 Fernanda F FALSE FALSE FALSE FALSE FALSE FALSE
## 48 48 Gabriela F FALSE FALSE FALSE FALSE FALSE FALSE
## 49 49 Gabriel M TRUE FALSE FALSE FALSE FALSE FALSE
## 50 50 Guille F TRUE FALSE FALSE FALSE TRUE FALSE
## 51 51 Jorge M TRUE TRUE FALSE FALSE FALSE FALSE
## 52 52 Lorenzo M TRUE FALSE TRUE FALSE FALSE FALSE
## 53 53 Mikaela F FALSE TRUE FALSE FALSE FALSE FALSE
## 54 54 Miguel M TRUE TRUE FALSE FALSE FALSE FALSE
## 55 55 Marcela F FALSE FALSE FALSE TRUE FALSE FALSE
## 56 56 Orlando M TRUE FALSE FALSE FALSE FALSE FALSE
## 57 57 Otilia F TRUE FALSE FALSE TRUE FALSE FALSE
## 58 58 Pedro M TRUE TRUE FALSE FALSE FALSE FALSE
## 59 59 Perla F FALSE FALSE FALSE FALSE FALSE FALSE
## 60 60 Raquel F TRUE TRUE FALSE FALSE FALSE FALSE
## 61 61 Susana F FALSE FALSE FALSE FALSE FALSE FALSE
## 62 62 Sandy F FALSE TRUE FALSE FALSE FALSE FALSE
## 63 63 Sotelo M FALSE FALSE TRUE TRUE FALSE FALSE
## 64 64 Tiburcio M FALSE FALSE FALSE TRUE FALSE FALSE
## 65 65 Teresa F FALSE FALSE FALSE FALSE FALSE FALSE
## 66 66 Walter F TRUE TRUE FALSE FALSE FALSE FALSE
## 67 67 Xóchitl F FALSE TRUE TRUE TRUE TRUE FALSE
n <- nrow(datos) # Determina conjunto de obesrvaciones o renglones
Conjunto Hombres y Mujeres
- Se determinan los conjuntos según el género de la persona mediante la función subset() que permite filtrar datos
- hombres
- mujeres
hombres <- subset(datos, sexo =='M')
mujeres <- subset(datos, sexo =='F')
hombres
## X nombres sexo futbol basquetbol voleybol atletismo ajedrez tenis
## 2 2 Antonio M FALSE FALSE FALSE FALSE FALSE FALSE
## 5 5 Eduardo M TRUE FALSE FALSE FALSE FALSE FALSE
## 6 6 Ernesto M FALSE TRUE FALSE FALSE FALSE FALSE
## 7 7 Gabino M FALSE TRUE FALSE FALSE FALSE FALSE
## 8 8 Gerardo M TRUE FALSE TRUE FALSE FALSE TRUE
## 9 9 Javier M FALSE TRUE FALSE FALSE FALSE FALSE
## 11 11 Juan M TRUE FALSE FALSE TRUE FALSE FALSE
## 12 12 Lalo M FALSE FALSE TRUE FALSE FALSE FALSE
## 15 15 Luis M FALSE FALSE TRUE FALSE FALSE FALSE
## 19 19 Margarito M FALSE FALSE FALSE FALSE FALSE TRUE
## 21 21 Memo M TRUE FALSE FALSE FALSE TRUE FALSE
## 22 22 Oscar M FALSE FALSE FALSE FALSE FALSE FALSE
## 23 23 Paco M TRUE FALSE TRUE FALSE TRUE FALSE
## 26 26 Raul M TRUE FALSE FALSE FALSE FALSE FALSE
## 27 27 Romualdo M TRUE FALSE FALSE FALSE FALSE FALSE
## 29 29 Rubén M TRUE FALSE FALSE FALSE FALSE FALSE
## 30 30 Salvador M TRUE FALSE FALSE TRUE FALSE FALSE
## 32 32 Sandro M FALSE FALSE FALSE FALSE FALSE TRUE
## 33 33 Saul M TRUE FALSE TRUE FALSE FALSE FALSE
## 35 35 Arturo M FALSE FALSE FALSE FALSE FALSE FALSE
## 37 37 Arnulfo M FALSE FALSE TRUE FALSE FALSE FALSE
## 39 39 Carlos M TRUE FALSE FALSE FALSE FALSE FALSE
## 40 40 Dagoberto M FALSE FALSE TRUE FALSE FALSE FALSE
## 43 43 Efren M TRUE FALSE FALSE TRUE FALSE FALSE
## 45 45 Fernando M TRUE FALSE FALSE TRUE FALSE FALSE
## 46 46 Fabián M FALSE TRUE TRUE FALSE FALSE FALSE
## 49 49 Gabriel M TRUE FALSE FALSE FALSE FALSE FALSE
## 51 51 Jorge M TRUE TRUE FALSE FALSE FALSE FALSE
## 52 52 Lorenzo M TRUE FALSE TRUE FALSE FALSE FALSE
## 54 54 Miguel M TRUE TRUE FALSE FALSE FALSE FALSE
## 56 56 Orlando M TRUE FALSE FALSE FALSE FALSE FALSE
## 58 58 Pedro M TRUE TRUE FALSE FALSE FALSE FALSE
## 63 63 Sotelo M FALSE FALSE TRUE TRUE FALSE FALSE
## 64 64 Tiburcio M FALSE FALSE FALSE TRUE FALSE FALSE
mujeres
## X nombres sexo futbol basquetbol voleybol atletismo ajedrez tenis
## 1 1 Ana F FALSE FALSE FALSE FALSE FALSE FALSE
## 3 3 Aracely F FALSE FALSE FALSE FALSE FALSE TRUE
## 4 4 Carmen F FALSE TRUE FALSE FALSE FALSE FALSE
## 10 10 Jeorgina F FALSE TRUE FALSE FALSE FALSE FALSE
## 13 13 Laura F FALSE TRUE FALSE FALSE FALSE FALSE
## 14 14 Lucy F TRUE FALSE TRUE TRUE FALSE FALSE
## 16 16 Luisa F FALSE FALSE FALSE FALSE FALSE FALSE
## 17 17 Lupita F TRUE TRUE FALSE FALSE FALSE FALSE
## 18 18 Margarita F FALSE TRUE FALSE TRUE FALSE FALSE
## 20 20 Maria F FALSE TRUE FALSE FALSE FALSE FALSE
## 24 24 Patricia F TRUE FALSE FALSE TRUE FALSE FALSE
## 25 25 Paty F TRUE TRUE FALSE FALSE FALSE FALSE
## 28 28 Rosario F FALSE FALSE FALSE FALSE FALSE FALSE
## 31 31 Sandra F FALSE FALSE FALSE FALSE FALSE FALSE
## 34 34 Yuri F TRUE FALSE FALSE FALSE FALSE FALSE
## 36 36 Angélica F TRUE TRUE TRUE FALSE FALSE FALSE
## 38 38 Bety F TRUE TRUE FALSE FALSE FALSE FALSE
## 41 41 Dany F TRUE TRUE FALSE FALSE FALSE FALSE
## 42 42 Dalia F TRUE FALSE FALSE FALSE FALSE FALSE
## 44 44 Ernestina F TRUE FALSE TRUE FALSE TRUE FALSE
## 47 47 Fernanda F FALSE FALSE FALSE FALSE FALSE FALSE
## 48 48 Gabriela F FALSE FALSE FALSE FALSE FALSE FALSE
## 50 50 Guille F TRUE FALSE FALSE FALSE TRUE FALSE
## 53 53 Mikaela F FALSE TRUE FALSE FALSE FALSE FALSE
## 55 55 Marcela F FALSE FALSE FALSE TRUE FALSE FALSE
## 57 57 Otilia F TRUE FALSE FALSE TRUE FALSE FALSE
## 59 59 Perla F FALSE FALSE FALSE FALSE FALSE FALSE
## 60 60 Raquel F TRUE TRUE FALSE FALSE FALSE FALSE
## 61 61 Susana F FALSE FALSE FALSE FALSE FALSE FALSE
## 62 62 Sandy F FALSE TRUE FALSE FALSE FALSE FALSE
## 65 65 Teresa F FALSE FALSE FALSE FALSE FALSE FALSE
## 66 66 Walter F TRUE TRUE FALSE FALSE FALSE FALSE
## 67 67 Xóchitl F FALSE TRUE TRUE TRUE TRUE FALSE
Frecuencias de Hombres y Mujeres
- Determinar frecuencias mediante función table() que permite generar la frecuencia de una variable
- ¿Cuántos casos hay que son hombres?
- ¿Cuántos casos hay que son mujeres?
table(datos$sexo)
##
## F M
## 33 34
Frecuencias relativas de Hombres y Mujeres
- Determinar frecuencias relativas mediante función prop.table(table()).
- ¿Cuál es la probabilidad al seleccionar a una persona de de todo conjunto de datos sea hombre?
- ¿Cuál es la probabilidad al seleccionar a una persona de de todo conjunto de datos sea mujer?
- Se redondea a 4 posiciones decimales
- Se determinala probabilidad en %
round(prop.table(table(datos$sexo)),4)
##
## F M
## 0.4925 0.5075
round(prop.table(table(datos$sexo)),4) * 100
##
## F M
## 49.25 50.75
Conjunto Fútbol
- Se determina el conjunto de personas que practican el deporte del fútbol según la disciplina de fubol
- futbol
futbol <- subset(datos, futbol == TRUE)
futbol
## X nombres sexo futbol basquetbol voleybol atletismo ajedrez tenis
## 5 5 Eduardo M TRUE FALSE FALSE FALSE FALSE FALSE
## 8 8 Gerardo M TRUE FALSE TRUE FALSE FALSE TRUE
## 11 11 Juan M TRUE FALSE FALSE TRUE FALSE FALSE
## 14 14 Lucy F TRUE FALSE TRUE TRUE FALSE FALSE
## 17 17 Lupita F TRUE TRUE FALSE FALSE FALSE FALSE
## 21 21 Memo M TRUE FALSE FALSE FALSE TRUE FALSE
## 23 23 Paco M TRUE FALSE TRUE FALSE TRUE FALSE
## 24 24 Patricia F TRUE FALSE FALSE TRUE FALSE FALSE
## 25 25 Paty F TRUE TRUE FALSE FALSE FALSE FALSE
## 26 26 Raul M TRUE FALSE FALSE FALSE FALSE FALSE
## 27 27 Romualdo M TRUE FALSE FALSE FALSE FALSE FALSE
## 29 29 Rubén M TRUE FALSE FALSE FALSE FALSE FALSE
## 30 30 Salvador M TRUE FALSE FALSE TRUE FALSE FALSE
## 33 33 Saul M TRUE FALSE TRUE FALSE FALSE FALSE
## 34 34 Yuri F TRUE FALSE FALSE FALSE FALSE FALSE
## 36 36 Angélica F TRUE TRUE TRUE FALSE FALSE FALSE
## 38 38 Bety F TRUE TRUE FALSE FALSE FALSE FALSE
## 39 39 Carlos M TRUE FALSE FALSE FALSE FALSE FALSE
## 41 41 Dany F TRUE TRUE FALSE FALSE FALSE FALSE
## 42 42 Dalia F TRUE FALSE FALSE FALSE FALSE FALSE
## 43 43 Efren M TRUE FALSE FALSE TRUE FALSE FALSE
## 44 44 Ernestina F TRUE FALSE TRUE FALSE TRUE FALSE
## 45 45 Fernando M TRUE FALSE FALSE TRUE FALSE FALSE
## 49 49 Gabriel M TRUE FALSE FALSE FALSE FALSE FALSE
## 50 50 Guille F TRUE FALSE FALSE FALSE TRUE FALSE
## 51 51 Jorge M TRUE TRUE FALSE FALSE FALSE FALSE
## 52 52 Lorenzo M TRUE FALSE TRUE FALSE FALSE FALSE
## 54 54 Miguel M TRUE TRUE FALSE FALSE FALSE FALSE
## 56 56 Orlando M TRUE FALSE FALSE FALSE FALSE FALSE
## 57 57 Otilia F TRUE FALSE FALSE TRUE FALSE FALSE
## 58 58 Pedro M TRUE TRUE FALSE FALSE FALSE FALSE
## 60 60 Raquel F TRUE TRUE FALSE FALSE FALSE FALSE
## 66 66 Walter F TRUE TRUE FALSE FALSE FALSE FALSE
Frecuencias de personas en Fútbol
- Determinar frecuencias mediante función table() que permite generar la frecuencia de una variable
- ¿Cuántas personas hay que practican Fútbol?
table(datos$futbol)
##
## FALSE TRUE
## 34 33
Frecuencias relativas del conjunto Fútbol
- Determinar frecuencias relativas mediante función prop.table(table()).
- ¿Cuál es la probabilidad al seleccionar a una persona de de todo conjunto de datos y que juegue fútbol?
- Se redondea a 4 posiciones decimales
- Se determinala probabilidad en %
round(prop.table(table(datos$futbol)),4)
##
## FALSE TRUE
## 0.5075 0.4925
round(prop.table(table(datos$futbol)),4) * 100
##
## FALSE TRUE
## 50.75 49.25
Conjunto Basquetbol
- Se determina el conjunto de personas que practican el deporte del basquetbol según la disciplina de basquetbol
- basquetbol
basquetbol <- subset(datos, basquetbol == TRUE)
basquetbol
## X nombres sexo futbol basquetbol voleybol atletismo ajedrez tenis
## 4 4 Carmen F FALSE TRUE FALSE FALSE FALSE FALSE
## 6 6 Ernesto M FALSE TRUE FALSE FALSE FALSE FALSE
## 7 7 Gabino M FALSE TRUE FALSE FALSE FALSE FALSE
## 9 9 Javier M FALSE TRUE FALSE FALSE FALSE FALSE
## 10 10 Jeorgina F FALSE TRUE FALSE FALSE FALSE FALSE
## 13 13 Laura F FALSE TRUE FALSE FALSE FALSE FALSE
## 17 17 Lupita F TRUE TRUE FALSE FALSE FALSE FALSE
## 18 18 Margarita F FALSE TRUE FALSE TRUE FALSE FALSE
## 20 20 Maria F FALSE TRUE FALSE FALSE FALSE FALSE
## 25 25 Paty F TRUE TRUE FALSE FALSE FALSE FALSE
## 36 36 Angélica F TRUE TRUE TRUE FALSE FALSE FALSE
## 38 38 Bety F TRUE TRUE FALSE FALSE FALSE FALSE
## 41 41 Dany F TRUE TRUE FALSE FALSE FALSE FALSE
## 46 46 Fabián M FALSE TRUE TRUE FALSE FALSE FALSE
## 51 51 Jorge M TRUE TRUE FALSE FALSE FALSE FALSE
## 53 53 Mikaela F FALSE TRUE FALSE FALSE FALSE FALSE
## 54 54 Miguel M TRUE TRUE FALSE FALSE FALSE FALSE
## 58 58 Pedro M TRUE TRUE FALSE FALSE FALSE FALSE
## 60 60 Raquel F TRUE TRUE FALSE FALSE FALSE FALSE
## 62 62 Sandy F FALSE TRUE FALSE FALSE FALSE FALSE
## 66 66 Walter F TRUE TRUE FALSE FALSE FALSE FALSE
## 67 67 Xóchitl F FALSE TRUE TRUE TRUE TRUE FALSE
Frecuencias de personas en Basquetbol
- Determinar frecuencias mediante función table() que permite generar la frecuencia de una variable
- ¿Cuántas personas hay que practican Basquetbol?
table(datos$basquetbol)
##
## FALSE TRUE
## 45 22
Frecuencias relativas del conjunto Basquetbol
- Determinar frecuencias relativas mediante función prop.table(table()).
- ¿Cuál es la probabilidad al seleccionar a una persona de de todo conjunto de datos y que juegue basquetbol?
- Se redondea a 4 posiciones decimales
- Se determinala probabilidad en %
round(prop.table(table(datos$basquetbol)),4)
##
## FALSE TRUE
## 0.6716 0.3284
round(prop.table(table(datos$basquetbol)),4) * 100
##
## FALSE TRUE
## 67.16 32.84
Conjunto Voleybol
- Se determina el conjunto de personas que practican el deporte del * * * * * Voleybol según la disciplina de Voleybol
- voleybol
voleybol <- subset(datos, voleybol == TRUE)
voleybol
## X nombres sexo futbol basquetbol voleybol atletismo ajedrez tenis
## 8 8 Gerardo M TRUE FALSE TRUE FALSE FALSE TRUE
## 12 12 Lalo M FALSE FALSE TRUE FALSE FALSE FALSE
## 14 14 Lucy F TRUE FALSE TRUE TRUE FALSE FALSE
## 15 15 Luis M FALSE FALSE TRUE FALSE FALSE FALSE
## 23 23 Paco M TRUE FALSE TRUE FALSE TRUE FALSE
## 33 33 Saul M TRUE FALSE TRUE FALSE FALSE FALSE
## 36 36 Angélica F TRUE TRUE TRUE FALSE FALSE FALSE
## 37 37 Arnulfo M FALSE FALSE TRUE FALSE FALSE FALSE
## 40 40 Dagoberto M FALSE FALSE TRUE FALSE FALSE FALSE
## 44 44 Ernestina F TRUE FALSE TRUE FALSE TRUE FALSE
## 46 46 Fabián M FALSE TRUE TRUE FALSE FALSE FALSE
## 52 52 Lorenzo M TRUE FALSE TRUE FALSE FALSE FALSE
## 63 63 Sotelo M FALSE FALSE TRUE TRUE FALSE FALSE
## 67 67 Xóchitl F FALSE TRUE TRUE TRUE TRUE FALSE
Frecuencias de personas en Voleybol
- Determinar frecuencias mediante función table() que permite generar la * frecuencia de una variable
- ¿Cuántas personas hay que practican voleybol?
table(datos$voleybol)
##
## FALSE TRUE
## 53 14
Frecuencias relativas del conjunto Voleybol
- Determinar frecuencias relativas mediante función prop.table(table()).
- ¿Cuál es la probabilidad al seleccionar a una persona de de todo conjunto de datos y que juegue voleybol?
- Se redondea a 4 posiciones decimales
- Se determina la probabilidad en %
round(prop.table(table(datos$voleybol)),4)
##
## FALSE TRUE
## 0.791 0.209
round(prop.table(table(datos$voleybol)),4) * 100
##
## FALSE TRUE
## 79.1 20.9
Conjunto Atletismo
- Se determina el conjunto de personas que practican el deporte del atletismo según la disciplina de atletismo
- atletismo
atletismo <- subset(datos, atletismo == TRUE)
atletismo
## X nombres sexo futbol basquetbol voleybol atletismo ajedrez tenis
## 11 11 Juan M TRUE FALSE FALSE TRUE FALSE FALSE
## 14 14 Lucy F TRUE FALSE TRUE TRUE FALSE FALSE
## 18 18 Margarita F FALSE TRUE FALSE TRUE FALSE FALSE
## 24 24 Patricia F TRUE FALSE FALSE TRUE FALSE FALSE
## 30 30 Salvador M TRUE FALSE FALSE TRUE FALSE FALSE
## 43 43 Efren M TRUE FALSE FALSE TRUE FALSE FALSE
## 45 45 Fernando M TRUE FALSE FALSE TRUE FALSE FALSE
## 55 55 Marcela F FALSE FALSE FALSE TRUE FALSE FALSE
## 57 57 Otilia F TRUE FALSE FALSE TRUE FALSE FALSE
## 63 63 Sotelo M FALSE FALSE TRUE TRUE FALSE FALSE
## 64 64 Tiburcio M FALSE FALSE FALSE TRUE FALSE FALSE
## 67 67 Xóchitl F FALSE TRUE TRUE TRUE TRUE FALSE
Frecuencias de personas en atletismo
- Determinar frecuencias mediante función table() que permite generar la frecuencia de una variable
- ¿Cuántas personas hay que practican atletismo?
table(datos$atletismo )
##
## FALSE TRUE
## 55 12
Frecuencias relativas del conjunto Atletismo
- Determinar frecuencias relativas mediante función prop.table(table()).
- ¿Cuál es la probabilidad al seleccionar a una persona de de todo conjunto de datos y que juegue atletismo?
- Se redondea a 4 posiciones decimales
- Se determina la probabilidad en %
round(prop.table(table(datos$atletismo )),4)
##
## FALSE TRUE
## 0.8209 0.1791
round(prop.table(table(datos$atletismo )),4) * 100
##
## FALSE TRUE
## 82.09 17.91
Conjunto Ajedrez
- Se determina el conjunto de personas que practican el deporte del ajedrez según la disciplina de ajedrez
- ajedrez
ajedrez <- subset(datos, ajedrez == TRUE)
ajedrez
## X nombres sexo futbol basquetbol voleybol atletismo ajedrez tenis
## 21 21 Memo M TRUE FALSE FALSE FALSE TRUE FALSE
## 23 23 Paco M TRUE FALSE TRUE FALSE TRUE FALSE
## 44 44 Ernestina F TRUE FALSE TRUE FALSE TRUE FALSE
## 50 50 Guille F TRUE FALSE FALSE FALSE TRUE FALSE
## 67 67 Xóchitl F FALSE TRUE TRUE TRUE TRUE FALSE
Frecuencias de personas en Ajedrez
- Determinar frecuencias mediante función table() que permite generar la frecuencia de una variable
- ¿Cuántas personas hay que practican ajedrez?
table(datos$ajedrez )
##
## FALSE TRUE
## 62 5
Frecuencias relativas del conjunto Ajedrez
- Determinar frecuencias relativas mediante función prop.table(table()).
- ¿Cuál es la probabilidad al seleccionar a una persona de de todo conjunto de datos y que juegue ajedrez?
- Se redondea a 4 posiciones decimales
- Se determina la probabilidad en %
round(prop.table(table(datos$ajedrez )),4)
##
## FALSE TRUE
## 0.9254 0.0746
round(prop.table(table(datos$ajedrez )),4) * 100
##
## FALSE TRUE
## 92.54 7.46
Unión de conjuntos
- La unión significa los de un conjunto integrando los del otro conjunto, * si se repite se omite su valor.
Unión de fútbol y basquetbol
- Todos los nombres de alumnos que juegan fútbol y también los nombres de alumnos que juegan basquetbol.
- futbol
- basquetbol
- ¿Cuántos alumnos hay que juegan fútbol o basquetbol?
- ¿Cuál es la probabilidad de que existan alumnos que jueguen fútbol basquetbol?
- Se determina su probabilidad por medio de la frecuencia relativa del * conjunto fútbol union con basquetbol. (frecuencia / n)
futUbas <- union(futbol$nombres, basquetbol$nombres)
futUbas
## [1] "Eduardo" "Gerardo" "Juan" "Lucy" "Lupita" "Memo"
## [7] "Paco" "Patricia" "Paty" "Raul" "Romualdo" "Rubén"
## [13] "Salvador" "Saul" "Yuri" "Angélica" "Bety" "Carlos"
## [19] "Dany" "Dalia" "Efren" "Ernestina" "Fernando" "Gabriel"
## [25] "Guille" "Jorge" "Lorenzo" "Miguel" "Orlando" "Otilia"
## [31] "Pedro" "Raquel" "Walter" "Carmen" "Ernesto" "Gabino"
## [37] "Javier" "Jeorgina" "Laura" "Margarita" "Maria" "Fabián"
## [43] "Mikaela" "Sandy" "Xóchitl"
Cálculo de probabilidad por frecuencia relativa
- ¿Cuántos alumnos hay que juegan fútbol o basquetbol?
- ¿Cuál es la probabilidad de que existan alumnos que jueguen fútbol basquetbol?
- Se determina su probabilidad por medio de la frecuencia relativa del conjunto fútbol union con basquetbol. (frecuencia / n)
cat("Hay ", length(futUbas), " alumnos que juegan fútbol o basquetbol de un total de ",n)
## Hay 45 alumnos que juegan fútbol o basquetbol de un total de 67
prob.futUbas <- length(futUbas) / n
cat("* ¿Cuál es la probabilidad de que existan alumnos que jueguen fútbol o basquetbol?
", prob.futUbas)
## * ¿Cuál es la probabilidad de que existan alumnos que jueguen fútbol o basquetbol?
## 0.6716418
Intersección de conjuntos
- La intersección significa los que están en un conjunto y tambien están en el otro conjunto por, por ejemplo futbol intersección con basquetbol
Intersección entre futbol y basquetbol
- Los que juegan futbol y que también juegan basquetbol
futIbas <- intersect(futbol$nombres, basquetbol$nombres)
futIbas
## [1] "Lupita" "Paty" "Angélica" "Bety" "Dany" "Jorge"
## [7] "Miguel" "Pedro" "Raquel" "Walter"
Cálculo de probabilidad por frecuenai relativa de la intersección entre futbol y basquetbol
- Los que juegan futbol y que también juegan basquetbol
- Se determina su probabilidad por medio de la frecuencia relativa del conjunto fútbol intersección con basquetbol. (frecuencia / n)
cat("Hay ", length(futIbas), " alumnos que juegan fútbol y que también juegan basquetbol de un total de ",n)
## Hay 10 alumnos que juegan fútbol y que también juegan basquetbol de un total de 67
prob.futIbas <- length(futIbas) / n
cat("¿Cuántos alumnos hay que juegan fútbol y basquetbol?", prob.futIbas)
## ¿Cuántos alumnos hay que juegan fútbol y basquetbol? 0.1492537
Ley de la adición para determinar probabilidades
- Al tener elementos en común se determina el cálculo de la probailidad por medio de la ley de la adición Prob(A ∪ B) = Prob(A) + Prob(B) - Prob(A ∩ B) * ¿ Cuál es la probabilidad de que juegue futbol o basquetbol una persona por medio de la ley de la adición para conjuntos no excluyentes que significa que hay elementos en común?
Probabilida de que juegue fútbol o que juegue basquetbol
- Anteriormente por medio de prop.table(table()) se observaron las probabilidades, aquí se vuelven a determinar
- Se almacenan las probabilidades en variables correspondientes prob.futbol[2] porque es la que es TRUE prob.basquetbol[2] porque es la que es TRUE
prob.futbol <- prop.table(table(datos$futbol))
prob.basquetbol <- prop.table(table(datos$basquetbol))
prob.futbol <- prob.futbol[2]
prob.basquetbol <- prob.basquetbol[2]
prob.futbol
## TRUE
## 0.4925373
prob.basquetbol
## TRUE
## 0.3283582
Cálculo de probabilidad de P(futbol U basquetbol)
- Ya se tiene las probabilidad de
- prob.futbol
- prob.basquetbol
- futIbas
- Se genera la probabailida de futbol union con basquetbol (prob.futUbas) por medio de la fórmula
- Se sustituye en la fórmula de la ley de la adición Prob(A ∪ B) = Prob(A) * Prob(B) - Prob(A ∩ B)
- Comprobar que la probabilidad es la misma que por medio del métoto de frecuencia relativa
- Se utiliza la función as.numeric() para garantizar que son numéricos y se pueden hacer operaciones aritiméticas
as.numeric(prob.futbol)
## [1] 0.4925373
as.numeric(prob.basquetbol)
## [1] 0.3283582
as.numeric(prob.futIbas)
## [1] 0.1492537
prob.futUbas <- as.numeric(prob.futbol) + as.numeric(prob.basquetbol) - as.numeric(prob.futIbas)
prob.futUbas
## [1] 0.6716418
cat("* ¿Cuál es la probabilidad de que existan alumnos que jueguen fútbol o basquetbol?
", prob.futUbas)
## * ¿Cuál es la probabilidad de que existan alumnos que jueguen fútbol o basquetbol?
## 0.6716418
Tablas cruzadas
table(datos$futbol, datos$basquetbol)
##
## FALSE TRUE
## FALSE 22 12
## TRUE 23 10
Frecuencias utilizando tablas cruzadas
- futbol
- basquetbol
- La función table() generan frecuencias
- El atributo dnn son los encabezados de la tabla, arriba y a la izquierda
- Con la matriz es mas fácil determinar probabilidades de conjuntos
- función rbind() para agregar renglon
- función cbind() para agregar columna
- apply() para alicar por ejemplo sum a cad renglon o columna
tabla.cruzada <- table(datos$futbol, datos$basquetbol, dnn = c('fútbol','basquetbol'))
tabla.cruzada
## basquetbol
## fútbol FALSE TRUE
## FALSE 22 12
## TRUE 23 10
tabla.cruzada.s <- rbind(tabla.cruzada, apply(tabla.cruzada,2,sum))
tabla.cruzada.s <- cbind(tabla.cruzada.s, apply(tabla.cruzada.s,1,sum))
tabla.cruzada.s
## FALSE TRUE
## FALSE 22 12 34
## TRUE 23 10 33
## 45 22 67
Interpretación de la tabla cruzada frecuencias
- Hay 33 alumnos que juegan futbol; renglón 2 de un total de 67
- Hay 22 personas que juegan basquetbol columna 2 de un total de 67
- Hay 10 personas que juegan futbol y basquetbol al mismo tiempo de un total de 67
Cálculo de probabilidades utilizando tablas cruzadas
- futbol
- basquetbol
- La función prop.table(table()) generacia probabailidades
- El atributo dnn son los encabezados de la tabla, arribay y a la izquierda
- Con la matriz es mas fácil determinar probabilidades de conjuntos
- función rbind() para agregar renglon
- función cbind() para agregar columna
- apply() para alicar por ejemplo sum a cad renglon o columna
prob.tabla.cruzada <- round(prop.table(table(datos$futbol, datos$basquetbol, dnn = c('fútbol','basquetbol'))),4)
prob.tabla.cruzada
## basquetbol
## fútbol FALSE TRUE
## FALSE 0.3284 0.1791
## TRUE 0.3433 0.1493
prob.tabla.cruzada <- rbind(prob.tabla.cruzada,apply(prob.tabla.cruzada,2,sum))
prob.tabla.cruzada <- cbind(prob.tabla.cruzada, apply(prob.tabla.cruzada,1,sum))
prob.tabla.cruzada
## FALSE TRUE
## FALSE 0.3284 0.1791 0.5075
## TRUE 0.3433 0.1493 0.4926
## 0.6717 0.3284 1.0001
Interpretación de la tabla cruzada probabilidades
- Hay 34 alumnos que juegan futbol que representan el 49.26% del 100%
- Hay 22 personas que juegan basquetbol que representan el 32.84% del 100%
- Hay 22 personas que juegan futbol y basquetbol al mismo tiempo que representan el 14.93% del 100% o del total de alumnos