utput:
html_document:
toc: true
toc_float: true
toc_depth: 3
number_sections: true
theme: cosmo
highlight: tango
code_folding: show
df_print: paged
css: styles.css
pdf_document:
toc: true
number_sections: true
highlight: tango
word_document:
toc: true
number_sections: true

๐Ÿ“Š๐Ÿ“Š๐Ÿ“Š๐Ÿ“Š๐Ÿ“Š๐Ÿ“Š๐Ÿ“Š๐Ÿ“Š๐Ÿ“Š๐Ÿ“Š๐Ÿ“Š๐Ÿ“Š๐Ÿ“Š๐Ÿ“Š๐Ÿ“Š๐Ÿ“Š๐Ÿ“Š๐Ÿ“Š๐Ÿ“Š๐Ÿ“Š๐Ÿ“Š๐Ÿ“Š๐Ÿ“Š๐Ÿ“Š๐Ÿ“Š๐Ÿ“Š๐Ÿ“Š๐Ÿ“Š๐Ÿ“Š๐Ÿ“Š๐Ÿ“Š๐Ÿ“Š๐Ÿ“Š๐Ÿ“Š๐Ÿ“Š๐Ÿ“Š๐Ÿ“Š๐Ÿ“Š๐Ÿ“Š๐Ÿ“Š

MI CURSO DE ESTADรSTICA Y PROBABILIDAD - 2026

๐ŸŽฏ๐ŸŽฏ๐ŸŽฏ๐ŸŽฏ๐ŸŽฏ๐ŸŽฏ๐ŸŽฏ๐ŸŽฏ๐ŸŽฏ๐ŸŽฏ๐ŸŽฏ๐ŸŽฏ๐ŸŽฏ๐ŸŽฏ๐ŸŽฏ๐ŸŽฏ๐ŸŽฏ๐ŸŽฏ๐ŸŽฏ๐ŸŽฏ๐ŸŽฏ๐ŸŽฏ๐ŸŽฏ๐ŸŽฏ๐ŸŽฏ๐ŸŽฏ๐ŸŽฏ๐ŸŽฏ๐ŸŽฏ๐ŸŽฏ๐ŸŽฏ๐ŸŽฏ๐ŸŽฏ๐ŸŽฏ๐ŸŽฏ๐ŸŽฏ๐ŸŽฏ๐ŸŽฏ๐ŸŽฏ๐ŸŽฏ

SEMANA 7. Mi pรกgina Web en Estadistica

๐Ÿ“Š๐Ÿ“Š๐Ÿ“Š๐Ÿ“Š๐Ÿ“Š๐Ÿ“Š๐Ÿ“Š๐Ÿ“Š๐Ÿ“Š๐Ÿ“Š๐Ÿ“Š๐Ÿ“Š๐Ÿ“Š๐Ÿ“Š๐Ÿ“Š๐Ÿ“Š๐Ÿ“Š๐Ÿ“Š๐Ÿ“Š๐Ÿ“Š๐Ÿ“Š๐Ÿ“Š๐Ÿ“Š๐Ÿ“Š๐Ÿ“Š๐Ÿ“Š๐Ÿ“Š๐Ÿ“Š๐Ÿ“Š๐Ÿ“Š๐Ÿ“Š๐Ÿ“Š๐Ÿ“Š๐Ÿ“Š๐Ÿ“Š๐Ÿ“Š๐Ÿ“Š๐Ÿ“Š๐Ÿ“Š๐Ÿ“Š

Clase Nยฐ 28. LABORATORIO 7 ANALISIS DE DATOS EN R

๐Ÿš€๐Ÿš€๐Ÿš€๐Ÿš€๐Ÿš€๐Ÿš€๐Ÿš€๐Ÿš€๐Ÿš€๐Ÿš€๐Ÿš€๐Ÿš€๐Ÿš€๐Ÿš€๐Ÿš€๐Ÿš€๐Ÿš€๐Ÿš€๐Ÿš€๐Ÿš€๐Ÿš€๐Ÿš€๐Ÿš€๐Ÿš€๐Ÿš€๐Ÿš€๐Ÿš€๐Ÿš€๐Ÿš€๐Ÿš€๐Ÿš€๐Ÿš€๐Ÿš€๐Ÿš€๐Ÿš€๐Ÿš€๐Ÿš€๐Ÿš€๐Ÿš€๐Ÿš€

(i)Datos

library(readxl)
DATOS2026 <- read_excel("00. DATOS202460ULTIMOS25 (1).xlsx")
DATOS2026 
## # A tibble: 74 ร— 16
##    CURSO    ASISTENCIA2 ASISTENCIA1 `PARCIAL 1` `PARCIAL 2`   NRC PROGRAMA  EDAD
##    <chr>          <dbl>       <dbl> <chr>       <chr>       <dbl> <chr>    <dbl>
##  1 PROBABIโ€ฆ         100          90 3.6         4.3          2314 F_NEGOCโ€ฆ    20
##  2 ESTADISโ€ฆ          70          75 0.9         2.5          1136 DERECHO     18
##  3 PROBABIโ€ฆ          85          95 3.9         3.8          2314 F_NEGOCโ€ฆ    19
##  4 PROBABIโ€ฆ           5           5 2.9         0.5          2314 MECANICA    18
##  5 ESTADISโ€ฆ          20          70 3.7         0.55         1009 PSICOLOโ€ฆ    19
##  6 ESTADISโ€ฆ         100         100 0.9         2.95         2313 PSICOLOโ€ฆ    20
##  7 PROBABIโ€ฆ          50          75 3.7         1.7          1010 C_DATOS     18
##  8 PROBABIโ€ฆ         100          95 3           3.3          2314 F_NEGOCโ€ฆ    19
##  9 ESTADISโ€ฆ         100         100 3.8         3.3          1009 PSICOLOโ€ฆ    18
## 10 PROBABIโ€ฆ          95          85 3           2.9          2314 SISTEMAS    22
## # โ„น 64 more rows
## # โ„น 8 more variables: PESO <dbl>, ESTATURA <dbl>, SEXO <chr>,
## #   ESTADO_CIVIL <chr>, ESTRATO <chr>, URBANO <chr>, TRANSPORTE <chr>,
## #   GR_SANGUINEO <chr>

๐Ÿš€๐Ÿš€๐Ÿš€๐Ÿš€๐Ÿš€๐Ÿš€๐Ÿš€๐Ÿš€๐Ÿš€๐Ÿš€๐Ÿš€๐Ÿš€๐Ÿš€๐Ÿš€๐Ÿš€๐Ÿš€๐Ÿš€๐Ÿš€๐Ÿš€๐Ÿš€๐Ÿš€๐Ÿš€๐Ÿš€๐Ÿš€๐Ÿš€๐Ÿš€๐Ÿš€๐Ÿš€๐Ÿš€๐Ÿš€๐Ÿš€๐Ÿš€๐Ÿš€๐Ÿš€๐Ÿš€๐Ÿš€๐Ÿš€๐Ÿš€๐Ÿš€๐Ÿš€

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

(2i)Usando la aplicaciรณn para hacer la tabla

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

๐Ÿš€๐Ÿš€๐Ÿš€๐Ÿš€๐Ÿš€๐Ÿš€๐Ÿš€๐Ÿš€๐Ÿš€๐Ÿš€๐Ÿš€๐Ÿš€๐Ÿš€๐Ÿš€๐Ÿš€๐Ÿš€๐Ÿš€๐Ÿš€๐Ÿš€๐Ÿš€๐Ÿš€๐Ÿš€๐Ÿš€๐Ÿš€๐Ÿš€๐Ÿš€๐Ÿš€๐Ÿš€๐Ÿš€๐Ÿš€๐Ÿš€๐Ÿš€๐Ÿš€๐Ÿš€๐Ÿš€๐Ÿš€๐Ÿš€๐Ÿš€๐Ÿš€๐Ÿš€

๐Ÿš€๐Ÿš€๐Ÿš€๐Ÿš€๐Ÿš€๐Ÿš€๐Ÿš€๐Ÿš€๐Ÿš€๐Ÿš€๐Ÿš€๐Ÿš€๐Ÿš€๐Ÿš€๐Ÿš€๐Ÿš€๐Ÿš€๐Ÿš€๐Ÿš€๐Ÿš€๐Ÿš€๐Ÿš€๐Ÿš€๐Ÿš€๐Ÿš€๐Ÿš€๐Ÿš€๐Ÿš€๐Ÿš€๐Ÿš€๐Ÿš€๐Ÿš€๐Ÿš€๐Ÿš€๐Ÿš€๐Ÿš€๐Ÿš€๐Ÿš€๐Ÿš€๐Ÿš€

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

(3i)Grรกfico de torta para SEXO

pie_1<-pie(table_sexo, col=c("lightblue","pink"),
        main="Estudio de Pastel. Stephanie Banquez \n Distribuciรณn por sexos.", labels = table_sexo)

๐Ÿš€๐Ÿš€๐Ÿš€๐Ÿš€๐Ÿš€๐Ÿš€๐Ÿš€๐Ÿš€๐Ÿš€๐Ÿš€๐Ÿš€๐Ÿš€๐Ÿš€๐Ÿš€๐Ÿš€๐Ÿš€๐Ÿš€๐Ÿš€๐Ÿš€๐Ÿš€๐Ÿš€๐Ÿš€๐Ÿš€๐Ÿš€๐Ÿš€๐Ÿš€๐Ÿš€๐Ÿš€๐Ÿš€๐Ÿš€๐Ÿš€๐Ÿš€๐Ÿš€๐Ÿš€๐Ÿš€๐Ÿš€๐Ÿš€๐Ÿš€๐Ÿš€๐Ÿš€

#####<-========== PASO 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 STEPHANIE BANQUEZ ",sub = "UTB",xlab = "SEXO", ylab = "Conteo")
text(barp, table_sexo-30, labels = table_sexo)

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

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

table_sexo2<-round(table(DATOS2026$SEXO)/74*100)
table_sexo2
## 
##  Femenino Masculino 
##        57        43

#####<-========== PASO 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 STEPHANIE BANQUEZ ",sub = "UTB",xlab = "SEXO", ylab = "Porcentaje")
text(barp2, table_sexo2-30, labels = table_sexo2)

###<-========== PASO 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.", labels = table_sexo2)

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


### [**(8i)**]{style="color:red"}[**Usando la aplicaciรณn para hacer la tabla con dos varibles SEXO y CURSO**]{style="color:blue"}
table_3<-table(DATOS2026$SEXO, DATOS2026$CURSO)
table_3
##            
##             ESTADISTICAI PROBABILIDAD
##   Femenino            16           26
##   Masculino           10           22

#####<-========== PASO 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",
        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. =========->

(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. =========->

(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",
        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. =========->

(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. =========->

(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",
        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. =========->

(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. =========->

(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",
        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. ==========->

(16i) Tabla de Frecuencias Usando el paquete summarytools: observamos ya una tabla mรกs completa

if (!requireNamespace("summarytools", quietly = TRUE)) {
  install.packages("summarytools", repos = "https://cloud.r-project.org")
}
## Warning in fun(libname, pkgname): couldn't connect to display ":0"
library(summarytools)
## 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. =========->

(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. =========->

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

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

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

(19i)Identificamos donde queda la mediana

x = DATOS2026$EDAD
boxplot(x, notch = FALSE, horizontal = FALSE, col = rainbow(3))

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

(20i)EDAD vs SEXO

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

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

(21i)EDAD vs ESTRATO

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

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

(22i)EDAD vs ESTRATO vs SEXO

if (!requireNamespace("ggplot2", quietly = TRUE)) {
  install.packages("ggplot2", repos = "https://cloud.r-project.org")
}

library(ggplot2)

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

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

(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. =========->

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

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

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

(25i)Identificamos donde queda la mediana

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

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

(26i)EDAD vs SEXO

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

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

(27)EDAD vs ESTRATO

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

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

(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. ==========->

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

Usando la librerรญa โ€œagricolaeโ€
# Instalar la librerรญa
install.packages("agricolae", repos = "https://cloud.r-project.org")
## Installing package into '/cloud/lib/x86_64-pc-linux-gnu-library/4.6'
## (as 'lib' is unspecified)
# Cargar la librerรญa
library(agricolae)

# Crear el histograma
h2 <- graph.freq(DATOS2026$EDAD, col = colors()[75])

# Mostrar el resultado
h2
## $breaks
## [1] 17.0 17.7 18.4 19.1 19.8 20.5 21.2 21.9 22.6
## 
## $counts
## [1]  7 32 21  0  7  4  0  3
## 
## $mids
## [1] 17.35 18.05 18.75 19.45 20.15 20.85 21.55 22.25
## 
## $relative
## [1] 0.0946 0.4324 0.2838 0.0000 0.0946 0.0541 0.0000 0.0405
## 
## $density
## [1] 0.13514286 0.61771429 0.40542857 0.00000000 0.13514286 0.07728571 0.00000000
## [8] 0.05785714
## 
## attr(,"class")
## [1] "graph.freq" "histogram"

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

(30i)Tabla de fecuencias agrupadas Regla de Sturges

Usando la libreria โ€œagricolaeโ€
summary(h2)
##   Lower Upper  Main Frequency Percentage CF   CPF
## 1  17.0  17.7 17.35         7        9.5  7   9.5
## 2  17.7  18.4 18.05        32       43.2 39  52.7
## 3  18.4  19.1 18.75        21       28.4 60  81.1
## 4  19.1  19.8 19.45         0        0.0 60  81.1
## 5  19.8  20.5 20.15         7        9.5 67  90.5
## 6  20.5  21.2 20.85         4        5.4 71  95.9
## 7  21.2  21.9 21.55         0        0.0 71  95.9
## 8  21.9  22.6 22.25         3        4.1 74 100.0

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

(31i)Polรญgono de frecuencia absolutas

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

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

(32i)Polรญgono de frecuencia relativas

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

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

(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. =========->

(34i)Ojivas - frecuencias porcentuales

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

๐ŸŒˆ๐Ÿงช๐ŸŒŸ๐Ÿ’ปโœจ๐Ÿง ๐Ÿ“ˆ๐Ÿ”ฌโš—๏ธ๐Ÿ“š๐Ÿ’ป๐ŸŒˆ๐Ÿงช๐ŸŒŸ๐Ÿ’ปโœจ๐Ÿง ๐Ÿ“ˆ๐ŸŒˆ๐Ÿงช๐ŸŒŸ๐Ÿ’ปโœจ๐Ÿง ๐Ÿ“ˆ๐Ÿ”ฌโš—๏ธ๐Ÿ“š๐Ÿ’ป๐ŸŒˆ๐Ÿงช๐ŸŒŸ๐Ÿ’ปโœจ๐Ÿง ๐Ÿ“ˆ

####<-========== AQUI FINALIZA EL LABORATORIO 7. =========-> ๐ŸŒˆ๐Ÿงช๐ŸŒŸ๐Ÿ’ปโœจ๐Ÿง ๐Ÿ“ˆ๐Ÿ”ฌโš—๏ธ๐Ÿ“š๐Ÿ’ป๐ŸŒˆ๐Ÿงช๐ŸŒŸ๐Ÿ’ปโœจ๐Ÿง ๐Ÿ“ˆ๐ŸŒˆ๐Ÿงช๐ŸŒŸ๐Ÿ’ปโœจ๐Ÿง ๐Ÿ“ˆ๐Ÿ”ฌโš—๏ธ๐Ÿ“š๐Ÿ’ป๐ŸŒˆ๐Ÿงช๐ŸŒŸ๐Ÿ’ปโœจ๐Ÿง ๐Ÿ“ˆ