📊📊📊📊📊📊📊📊📊📊📊📊📊📊📊📊📊📊📊📊📊📊📊📊📊📊📊📊📊📊📊📊📊📊📊📊📊📊📊📊

1 MI CURSO DE ESTADÍSTICA Y PROBABILIDAD - 2026

🎯🎯🎯🎯🎯🎯🎯🎯🎯🎯🎯🎯🎯🎯🎯🎯🎯🎯🎯🎯🎯🎯🎯🎯🎯🎯🎯🎯🎯🎯🎯🎯🎯🎯🎯🎯🎯🎯🎯🎯

1.1 SEMANA 7. Mi página Web en Estadistica

📊📊📊📊📊📊📊📊📊📊📊📊📊📊📊📊📊📊📊📊📊📊📊📊📊📊📊📊📊📊📊📊📊📊📊📊📊📊📊📊

1.2 Clase N° 28.LABORATORIO 7 - ANALISIS DE DATOS EN R

1.3 (i)Datos

library(readxl)
DATOS2026 <- read_excel("00. DATOS202460ULTIMOS25 (2).xlsx")
DATOS2026

#####<-========== PASO 4. =========->

1.4 (2i)Usando la aplicación para hacer la tabla

table_sexo<-table(DATOS2026$SEXO)
table_sexo
## 
##  Femenino Masculino 
##        42        32

#####<-========== PASO 5.=========->

1.5 (3i)Gráfico de torta para SEXO

pie_1<-pie(table_sexo, col=c("lightblue","pink"),
        main="Estudio de Pastel.\n Distribución por sexos - CARLOS GARCIA.", labels = table_sexo)

#####<-========== PASO 6. =========->

1.6 (4i)Construimos el diagrama de barras y el diagrama de Pastel para esta variable cualitativa

barp<-barplot(table_sexo, col = rainbow(5), border = "darkred",main = "Gráfico de Barras - CARLOS GARCIA",sub = "UTB",xlab = "SEXO", ylab = "Conteo")
text(barp, table_sexo-30, labels = table_sexo)

#####<-========== PASO 7. =========->

1.7 (5i)Usando la aplicación para hacer la tabla porcentual redondeando al entero mas cercano

table_sexo2<-round(table(DATOS2026$SEXO)/121*100)
table_sexo2
## 
##  Femenino Masculino 
##        35        26

#####<-========== PASO 8. =========->

1.8 (6i)Construimos el diagrama de barras % y da pastel para esta variable cualitativa

barp2<-barplot(table_sexo2, col = rainbow(5), border = "darkred",main = "Gráfico de Barras - CARLOS GARCIA",sub = "UTB",xlab = "SEXO", ylab = "Porcentaje")
text(barp2, table_sexo2-30, labels = table_sexo2)

#####<-========== PASO 9. =========->

1.9 (7i)Las tablas de frecuencias y las representaciones gráficas son dos maneras equivalentes de presentar la información. Las dos exponen ordenadamente la información recogida en una muestra

pie_1<-pie(table_sexo2, col=c("lightblue","pink"),
        main="Estudio de Pastel.\n Distribución por sexos - CARLOS GARCIA.", labels = table_sexo2)

#####<-========== PASO 10. =========->

1.10 (8i)Usando la aplicación para hacer la tabla con dos varibles SEXO y CURSO

table_3<-table(DATOS2026$SEXO, DATOS2026$CURSO)
table_3
##            
##             ESTADISTICAI PROBABILIDAD
##   Femenino            16           26
##   Masculino           10           22

#####<-========== PASO 11. =========->

1.11 (9i)Usando la aplicación para hacer el gráfico con dos varibles SEXO y CURSO

barp3<-barplot(table_3,
        main = "Gráfico de barras CURSO vs SEXO - CARLOS GARCIA",
        xlab = "CURSO", ylab = "Frecuencia",
        col = c("pink", "blue"),
        legend.text = rownames(table_3),
        beside = TRUE) # Barras agrupadas
text(barp3, table_3-5, labels = table_3)

#####<-========== PASO 12. =========->

1.12 (10i)Usando la aplicación para hacer la tabla con dos varibles SEXO y CURSO pero usando las frecuencias relativas aproximadas

table_4<-round(table(DATOS2026$SEXO, DATOS2026$CURSO)/74*100)
table_4
##            
##             ESTADISTICAI PROBABILIDAD
##   Femenino            22           35
##   Masculino           14           30

#####<-========== PASO 13. =========->

1.13 (11i)Usando la aplicación para hacer el gráfico con dos varibles SEXO y CURSO pero usando las frecuencias relativas aproximadas

barp4<-barplot(table_4,
        main = "Gráfico de barras CURSO vs SEXO en porcentajes - CARLOS GARCIA",
        xlab = "CURSO", ylab = "Frecuencia",
        col = c("pink", "blue"),
        legend.text = rownames(table_4),
        beside = TRUE) # Barras agrupadas
text(barp4, table_4-5, labels = table_4)

#####<-========== PASO 14. =========->

1.14 (12i)Usando la aplicación para hacer la tabla con dos varibles SEXO y CURSO

table_5<-table(DATOS2026$ESTRATO, DATOS2026$CURSO)
table_5
##      
##       ESTADISTICAI PROBABILIDAD
##   I              5           10
##   II             7           18
##   III            9            9
##   IV             5            5
##   V              0            5

#####<-========== PASO 15. =========->

1.14.1 (13i)Usando la aplicación para hacer el gráfico con dos varibles SEXO y CURSO

barp3<-barplot(table_5,
        main = "Gráfico de barras CURSO vs ESTRATO - CARLOS GARCIA",
        xlab = "CURSO", ylab = "Frecuencia",
        col = rainbow(5),
        legend.text = rownames(table_5),
        beside = TRUE) # Barras agrupadas
text(barp3, table_5-1, labels = table_3)

#####<-========== PASO 16. =========->

1.14.2 (14i)Usando la aplicación para hacer la tabla con dos varibles SEXO y CURSO

table_6<-table(DATOS2026$ESTRATO, DATOS2026$SEXO)
table_6
##      
##       Femenino Masculino
##   I          8         7
##   II        17         8
##   III       10         8
##   IV         4         6
##   V          3         2

#####<-========== PASO 17. =========->

1.15 (15i)Usando la aplicación para hacer el gráfico con dos varibles SEXO y CURSO

barp3<-barplot(table_6,
        main = "Gráfico de barras CURSO vs ESTRATO - CARLOS GARCIA",
        xlab = "CURSO", ylab = "Frecuencia",
        col = rainbow(5),
        legend.text = rownames(table_6),
        beside = TRUE) # Barras agrupadas
text(barp3, table_6-1, labels = table_6)

#####<-========== PASO 18. =========->

1.16 (16i)Tabla de Frecuencias Usando el paquete summarytools: observamos ya una tabla mas completa

#install.packages("summarytools")
library (summarytools)
## Warning in fun(libname, pkgname): couldn't connect to display ":0"
## system might not have X11 capabilities; in case of errors when using dfSummary(), set st_options(use.x11 = FALSE)
tabla_8 <- freq(DATOS2026$EDAD)
tabla_8
## Frequencies  
## DATOS2026$EDAD  
## Type: Numeric  
## 
##               Freq   % Valid   % Valid Cum.   % Total   % Total Cum.
## ----------- ------ --------- -------------- --------- --------------
##          17      7      9.46           9.46      9.46           9.46
##          18     32     43.24          52.70     43.24          52.70
##          19     21     28.38          81.08     28.38          81.08
##          20      7      9.46          90.54      9.46          90.54
##          21      4      5.41          95.95      5.41          95.95
##          22      3      4.05         100.00      4.05         100.00
##        <NA>      0                               0.00         100.00
##       Total     74    100.00         100.00    100.00         100.00

#####<-========== PASO 19. =========->

1.17 (17i)Tabla de Frecuencias Usando el paquete summarytools: observamos ya una tabla mas completa

library(summarytools)
summary(DATOS2026$EDAD)
##    Min. 1st Qu.  Median    Mean 3rd Qu.    Max. 
##    17.0    18.0    18.0    18.7    19.0    22.0

#####<-========== PASO 20. =========->

1.17.1 (18i)Una primera vista del diagrama de caja para la variable Edad

boxplot(DATOS2026$EDAD, horizontal = TRUE, col = rainbow(3))

#####<-========== PASO 21. =========->

1.17.2 (19i)Identificamos donde queda la mediana

x = DATOS2026$EDAD
boxplot(x, notch = TRUE, horizontal = TRUE, col = rainbow(3))
## Warning in (function (z, notch = FALSE, width = NULL, varwidth = FALSE, : some
## notches went outside hinges ('box'): maybe set notch=FALSE

#####<-========== PASO 22. =========->

1.17.3 (20i)EDAD vs SEXO

x = DATOS2026$EDAD
y = DATOS2026$SEXO
boxplot(x~y, horizontal = TRUE, col = rainbow(3))

#####<-========== PASO 23. =========->

1.18 (21i)EDAD vs ESTRATO

library(ggplot2)
x = DATOS2026$EDAD
z = DATOS2026$ESTRATO
boxplot(x~z, horizontal = TRUE, col = rainbow(3))

#install.packages("ggplot2")

####<-========== PASO 24. =========->

1.18.1 (22i)EDAD vs ESTRATO vs SEXO

library(ggplot2)
ggplot(data= DATOS2026,mapping= aes(y=EDAD,x = ESTRATO, fill=SEXO))+geom_boxplot()+
  scale_y_continuous(name = "EDAD") +
  scale_x_discrete(labels = abbreviate, name = "ESTRATO")

####<-========== PASO 25. =========->

1.18.2 (23i)Estudiemos la variable ESTATURA y obtengamos sus seis medidas representativas

summary(DATOS2026$ESTATURA)
##    Min. 1st Qu.  Median    Mean 3rd Qu.    Max. 
##   153.0   163.0   168.0   168.4   174.0   192.0

####<-========== PASO 26. =========->

1.18.2.1 (24i)Una primera vista del diagrama de caja para la variable ESTATURA

boxplot(DATOS2026$ESTATURA, horizontal = TRUE, col = rainbow(3))

####<-========== PASO 27. =========->

1.18.2.2 (25i)Identificamos donde queda la mediana

x = DATOS2026$ESTATURA
boxplot(x, notch = TRUE, horizontal = TRUE, col = rainbow(3))

####<-========== PASO 28. =========->

1.18.2.3 (26i)EDAD vs SEXO

x = DATOS2026$ESTATURA
y = DATOS2026$SEXO
boxplot(x~y, horizontal = TRUE, col = rainbow(3))

####<-========== PASO 29. =========->

1.18.2.4 (27)EDAD vs ESTRATO

library(ggplot2)
x = DATOS2026$ESTATURA
z = DATOS2026$ESTRATO
boxplot(x~z, horizontal = TRUE, col = rainbow(3))

####<-========== PASO 30. =========->

1.18.3 (28i)ESTATURA vs ESTRATO vs SEXO

library(ggplot2)
ggplot(data= DATOS2026,mapping= aes(y=ESTATURA,x = ESTRATO, fill=SEXO))+geom_boxplot()+
  scale_y_continuous(name = "ESTATURA") +
  scale_x_discrete(labels = abbreviate, name = "ESTRATO")

####<-========== PASO 31. =========->

1.18.4 (29i)Histograma y tabla de frecuencias usando Regla de Sturges

1.18.4.0.1 Usando la libreria “agricolae”
library(agricolae)
h2<-graph.freq(DATOS2026$EDAD, col=colors()[75]) #[86]

#install.packages("agricolae")

####<-========== PASO 32. =========->

1.18.5 (30i)Tabla de fecuencias agrupadas Regla de Sturges

1.18.5.0.1 Usando la libreria “agricolae”
summary(h2)

####<-========== PASO 33. =========->

1.18.5.1 (31i)Polígono de frecuencia absolutas

1.18.5.1.0.1 frequency : counts (1) and relative (2)
plot(h2,  col=colors()[70], frequency = 1)
polygon.freq(h2, col = "red", frequency = 1, lwd = 2)

####<-========== PASO 34. =========->

1.18.6 (32i)Polígono de frecuencia relativas

1.18.6.0.0.1 frequency : counts (1) and relative (2)
plot(h2,  col=colors()[70], frequency = 2)
polygon.freq(h2, col = "red", frequency = 2, lwd = 2)

####<-========== PASO 35. =========->

1.18.7 (33i)Ojivas - usando R

fr_por_clase2<-h2$counts
fr_por_clase2
## [1]  7 32 21  0  7  4  0  3
total_n2<-sum(h2$counts)
total_n2
## [1] 74
fr_relativos2<-fr_por_clase2/total_n2
fr_porcentuales2<-100*fr_relativos2
fr_porcentuales2
## [1]  9.459459 43.243243 28.378378  0.000000  9.459459  5.405405  0.000000
## [8]  4.054054
cumsum(fr_por_clase2)
## [1]  7 39 60 60 67 71 71 74
cumsum(fr_relativos2)
## [1] 0.09459459 0.52702703 0.81081081 0.81081081 0.90540541 0.95945946 0.95945946
## [8] 1.00000000
cumsum(fr_porcentuales2)
## [1]   9.459459  52.702703  81.081081  81.081081  90.540541  95.945946  95.945946
## [8] 100.000000

####<-========== PASO 36. =========->

1.19 (34i)Ojivas - frecuencias porcentuales

p4<-cumsum(fr_porcentuales2)
plot(p4, col = "red")
lines(p4, col = "red")