Carga de datos
Se puede cargar la base de datos de dos formas equivalentes:
Opción A — paquete del curso
(paquetePROB):
install.packages("devtools") # solo una vez
devtools::install_github("dgonxalex80/paquetePROB") # descarga el paquete
library(paquetePROB)
data("beer")
Opción B — archivo beer.csv (el que se usa en
este informe):
beer <- read_csv("beer.csv", show_col_types = FALSE)
# Recodificación de variables categóricas para lectura más clara
beer <- beer %>%
mutate(
origen_lbl = factor(origen, levels = c(0, 1),
labels = c("Nacional", "Importada")),
tipo_lbl = factor(tipo, levels = 1:5,
labels = c("Lager artesanal", "Clara artesanal",
"Lager importada", "Normal y helada",
"Baja en calorías / sin alcohol"))
)
glimpse(beer)
## Rows: 69
## Columns: 8
## $ marca <chr> "m1", "m2", "m3", "m4", "m5", "m6", "m7", "m8", "m9", "m10"…
## $ precio <dbl> 624, 479, 596, 47, 411, 385, 252, 546, 6, 371, 67, 499, 41,…
## $ calorias <dbl> 159, 160, 160, 162, 157, 151, 155, 135, 162, 142, 146, 148,…
## $ poralcoh <dbl> 52, 5, 49, 49, 55, 49, 47, 51, 54, 48, 44, 43, 51, 5, 58, 5…
## $ tipo <dbl> 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 2, 2,…
## $ origen <dbl> 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,…
## $ origen_lbl <fct> Importada, Importada, Importada, Importada, Importada, Impo…
## $ tipo_lbl <fct> Lager artesanal, Lager artesanal, Lager artesanal, Lager ar…
Análisis
descriptivo
Precio
beer %>%
summarise(
n = n(), media = mean(precio), mediana = median(precio),
desv_std = sd(precio), min = min(precio), max = max(precio),
Q1 = quantile(precio, 0.25), Q3 = quantile(precio, 0.75),
CV = sd(precio) / mean(precio) * 100
) %>%
kable(digits = 2, caption = "Indicadores estadísticos del precio") %>%
kable_styling(bootstrap_options = c("striped", "hover"), full_width = FALSE)
Indicadores estadísticos del precio
|
n
|
media
|
mediana
|
desv_std
|
min
|
max
|
Q1
|
Q3
|
CV
|
|
69
|
424.58
|
425
|
212.37
|
4
|
779
|
319
|
596
|
50.02
|
ggplot(beer, aes(x = precio)) +
geom_histogram(bins = 10, fill = "#B8860B", color = "white") +
labs(title = "Distribución del precio", x = "Precio (USD)", y = "Frecuencia") +
theme_minimal()

Calorías
beer %>%
summarise(
n = n(), media = mean(calorias), mediana = median(calorias),
desv_std = sd(calorias), min = min(calorias), max = max(calorias),
Q1 = quantile(calorias, 0.25), Q3 = quantile(calorias, 0.75),
CV = sd(calorias) / mean(calorias) * 100
) %>%
kable(digits = 2, caption = "Indicadores estadísticos de las calorías") %>%
kable_styling(bootstrap_options = c("striped", "hover"), full_width = FALSE)
Indicadores estadísticos de las calorías
|
n
|
media
|
mediana
|
desv_std
|
min
|
max
|
Q1
|
Q3
|
CV
|
|
69
|
142.35
|
148
|
29.9
|
58
|
201
|
142
|
160
|
21.01
|
ggplot(beer, aes(x = calorias)) +
geom_histogram(bins = 10, fill = "#8B4513", color = "white") +
labs(title = "Distribución de las calorías", x = "Calorías", y = "Frecuencia") +
theme_minimal()

Porcentaje de
alcohol
beer %>%
summarise(
n = n(), media = mean(poralcoh), mediana = median(poralcoh),
desv_std = sd(poralcoh), min = min(poralcoh), max = max(poralcoh),
Q1 = quantile(poralcoh, 0.25), Q3 = quantile(poralcoh, 0.75),
CV = sd(poralcoh) / mean(poralcoh) * 100
) %>%
kable(digits = 2, caption = "Indicadores estadísticos del % de alcohol") %>%
kable_styling(bootstrap_options = c("striped", "hover"), full_width = FALSE)
Indicadores estadísticos del % de alcohol
|
n
|
media
|
mediana
|
desv_std
|
min
|
max
|
Q1
|
Q3
|
CV
|
|
69
|
36.25
|
46
|
21.09
|
0
|
59
|
5
|
51
|
58.18
|
ggplot(beer, aes(x = poralcoh)) +
geom_histogram(bins = 10, fill = "#CD853F", color = "white") +
labs(title = "Distribución del % de alcohol", x = "% Alcohol", y = "Frecuencia") +
theme_minimal()

Tipo de cerveza
beer %>%
count(tipo_lbl) %>%
mutate(porcentaje = round(n / sum(n) * 100, 1)) %>%
kable(col.names = c("Tipo", "Frecuencia", "Porcentaje (%)"),
caption = "Distribución por tipo de cerveza") %>%
kable_styling(bootstrap_options = c("striped", "hover"), full_width = FALSE)
Distribución por tipo de cerveza
|
Tipo
|
Frecuencia
|
Porcentaje (%)
|
|
Lager artesanal
|
13
|
18.8
|
|
Clara artesanal
|
17
|
24.6
|
|
Lager importada
|
10
|
14.5
|
|
Normal y helada
|
16
|
23.2
|
|
Baja en calorías / sin alcohol
|
13
|
18.8
|
ggplot(beer, aes(x = tipo_lbl, fill = tipo_lbl)) +
geom_bar() +
labs(title = "Frecuencia por tipo de cerveza", x = "Tipo", y = "Frecuencia") +
theme_minimal() +
theme(axis.text.x = element_text(angle = 25, hjust = 1), legend.position = "none")

Origen
beer %>%
count(origen_lbl) %>%
mutate(porcentaje = round(n / sum(n) * 100, 1)) %>%
kable(col.names = c("Origen", "Frecuencia", "Porcentaje (%)"),
caption = "Distribución por origen") %>%
kable_styling(bootstrap_options = c("striped", "hover"), full_width = FALSE)
Distribución por origen
|
Origen
|
Frecuencia
|
Porcentaje (%)
|
|
Nacional
|
15
|
21.7
|
|
Importada
|
54
|
78.3
|
ggplot(beer, aes(x = origen_lbl, fill = origen_lbl)) +
geom_bar() +
labs(title = "Frecuencia por origen", x = "Origen", y = "Frecuencia") +
theme_minimal() +
theme(legend.position = "none")

Análisis cruzado (apoyo
para validar hipótesis)
Precio según
origen
beer %>%
group_by(origen_lbl) %>%
summarise(media_precio = mean(precio), sd_precio = sd(precio), n = n()) %>%
kable(digits = 2, caption = "Precio promedio según origen") %>%
kable_styling(bootstrap_options = c("striped", "hover"), full_width = FALSE)
Precio promedio según origen
|
origen_lbl
|
media_precio
|
sd_precio
|
n
|
|
Nacional
|
539.47
|
146.9
|
15
|
|
Importada
|
392.67
|
217.7
|
54
|
ggplot(beer, aes(x = origen_lbl, y = precio, fill = origen_lbl)) +
geom_boxplot(alpha = 0.7) +
labs(title = "Precio según origen", x = "Origen", y = "Precio") +
theme_minimal() +
theme(legend.position = "none")

Calorías según tipo
de cerveza
beer %>%
group_by(tipo_lbl) %>%
summarise(media_calorias = mean(calorias), sd_calorias = sd(calorias), n = n()) %>%
kable(digits = 2, caption = "Calorías promedio según tipo") %>%
kable_styling(bootstrap_options = c("striped", "hover"), full_width = FALSE)
Calorías promedio según tipo
|
tipo_lbl
|
media_calorias
|
sd_calorias
|
n
|
|
Lager artesanal
|
154.38
|
9.59
|
13
|
|
Clara artesanal
|
165.41
|
15.56
|
17
|
|
Lager importada
|
151.20
|
6.68
|
10
|
|
Normal y helada
|
145.75
|
6.44
|
16
|
|
Baja en calorías / sin alcohol
|
89.15
|
22.59
|
13
|
ggplot(beer, aes(x = tipo_lbl, y = calorias, fill = tipo_lbl)) +
geom_boxplot(alpha = 0.7) +
labs(title = "Calorías según tipo de cerveza", x = "Tipo", y = "Calorías") +
theme_minimal() +
theme(axis.text.x = element_text(angle = 25, hjust = 1), legend.position = "none")

Relación precio -
porcentaje de alcohol
ggplot(beer, aes(x = poralcoh, y = precio, color = origen_lbl)) +
geom_point(size = 2.5, alpha = 0.8) +
labs(title = "Precio vs. % de alcohol", x = "% de alcohol", y = "Precio",
color = "Origen") +
theme_minimal()
