Este informe presenta el análisis de la base de datos Smokers Health Data, enfocándose en la aplicación de pruebas de hipótesis estadísticas y visualización interactiva para comparar variables clínicas y fisiológicas entre personas fumadoras y no fumadoras. Las pruebas y visualizaciones buscan identificar diferencias significativas que permitan fundamentar decisiones en contextos médicos y de salud pública.
summary(datos)
## age sex current_smoker heart_rate
## Min. :32.00 Length:3900 Length:3900 Min. : 44.00
## 1st Qu.:42.00 Class :character Class :character 1st Qu.: 68.00
## Median :49.00 Mode :character Mode :character Median : 75.00
## Mean :49.54 Mean : 75.69
## 3rd Qu.:56.00 3rd Qu.: 82.00
## Max. :70.00 Max. :143.00
##
## blood_pressure cigs_per_day chol current_smoker_bin
## Length:3900 Min. : 0.000 Min. :113.0 Mode :logical
## Class :character 1st Qu.: 0.000 1st Qu.:206.0 FALSE:1968
## Mode :character Median : 0.000 Median :234.0 TRUE :1932
## Mean : 9.169 Mean :236.6
## 3rd Qu.:20.000 3rd Qu.:263.0
## Max. :70.000 Max. :696.0
## NA's :14 NA's :7
## chol_high taquicardia
## Mode :logical Mode :logical
## FALSE:2224 FALSE:3807
## TRUE :1669 TRUE :93
## NA's :7
##
##
##
str(datos)
## 'data.frame': 3900 obs. of 10 variables:
## $ age : int 54 45 58 42 42 57 43 42 37 49 ...
## $ sex : chr "male" "male" "male" "male" ...
## $ current_smoker : chr "yes" "yes" "yes" "yes" ...
## $ heart_rate : int 95 64 81 90 62 62 75 66 65 93 ...
## $ blood_pressure : chr "110/72" "121/72" "127.5/76" "122.5/80" ...
## $ cigs_per_day : int NA NA NA NA NA NA NA NA NA NA ...
## $ chol : int 219 248 235 225 226 223 222 196 188 256 ...
## $ current_smoker_bin: logi TRUE TRUE TRUE TRUE TRUE TRUE ...
## $ chol_high : logi FALSE TRUE FALSE FALSE FALSE FALSE ...
## $ taquicardia : logi FALSE FALSE FALSE FALSE FALSE FALSE ...
p_hist <- ggplot(datos, aes(x = chol)) +
geom_histogram(aes(y = ..density..), bins = 30, fill = "skyblue", color = "black", alpha = 0.7) +
geom_density(color = "red", size = 1) +
labs(title = "Distribución de colesterol total", x = "Colesterol (mg/dL)", y = "Densidad") +
theme_minimal()
ggplotly(p_hist)
datos$chol_z <- scale(datos$chol)
p_hist_norm <- ggplot(datos, aes(x = chol_z)) +
geom_histogram(aes(y = ..density..), bins = 30, fill = "seagreen2", color = "black", alpha = 0.7) +
geom_density(color = "blue", size = 1) +
labs(title = "Distribución normalizada (z-score) de colesterol", x = "Colesterol normalizado (z)", y = "Densidad") +
theme_minimal()
ggplotly(p_hist_norm)
p_heat <- ggplot(datos, aes(x = chol, y = heart_rate)) +
stat_bin2d(bins = 20, aes(fill = ..count..)) +
scale_fill_viridis_c() +
labs(title = "Mapa de calor: colesterol vs frecuencia cardíaca", x = "Colesterol (mg/dL)", y = "Frecuencia cardíaca (lpm)", fill = "Cantidad") +
theme_minimal()
ggplotly(p_heat)
Hipótesis:
t_test_hr <- t.test(datos$heart_rate, mu = 75)
t_test_hr
##
## One Sample t-test
##
## data: datos$heart_rate
## t = 3.5809, df = 3899, p-value = 0.0003465
## alternative hypothesis: true mean is not equal to 75
## 95 percent confidence interval:
## 75.31176 76.06619
## sample estimates:
## mean of x
## 75.68897
Interpretación:
El valor-p es 3.47^{-4}.
Si es menor a 0.05, rechazamos la hipótesis nula y concluimos que la
frecuencia cardíaca promedio difiere de 75 lpm.
Con base en este resultado, existe una diferencia significativa respecto
a la referencia poblacional.
Hipótesis:
t_test_chol <- t.test(datos$chol, mu = 200, alternative = "greater")
t_test_chol
##
## One Sample t-test
##
## data: datos$chol
## t = 51.456, df = 3892, p-value < 2.2e-16
## alternative hypothesis: true mean is greater than 200
## 95 percent confidence interval:
## 235.4258 Inf
## sample estimates:
## mean of x
## 236.5959
Interpretación:
El valor-p es 0.
Rechazamos H0: el colesterol medio es significativamente mayor a 200
mg/dL.
Hipótesis:
n_chol <- sum(!is.na(datos$chol))
x_high <- sum(datos$chol_high, na.rm=TRUE)
prop_test_chol <- prop.test(x_high, n_chol, p=0.20, alternative="greater")
prop_test_chol
##
## 1-sample proportions test with continuity correction
##
## data: x_high out of n_chol, null probability 0.2
## X-squared = 1271.4, df = 1, p-value < 2.2e-16
## alternative hypothesis: true p is greater than 0.2
## 95 percent confidence interval:
## 0.4155977 1.0000000
## sample estimates:
## p
## 0.4287182
Proporción observada: 0.429
Interpretación:
El valor-p es 9.33^{-279}.
La proporción de personas con colesterol alto es significativamente
mayor al 20%.
Hipótesis:
n_hr <- sum(!is.na(datos$heart_rate))
x_taq <- sum(datos$taquicardia, na.rm=TRUE)
prop_test_taq <- prop.test(x_taq, n_hr, p=0.05)
prop_test_taq
##
## 1-sample proportions test with continuity correction
##
## data: x_taq out of n_hr, null probability 0.05
## X-squared = 55.613, df = 1, p-value = 8.825e-14
## alternative hypothesis: true p is not equal to 0.05
## 95 percent confidence interval:
## 0.01939026 0.02926409
## sample estimates:
## p
## 0.02384615
Proporción observada: 0.024
Interpretación:
El valor-p es 8.83^{-14}.
La proporción de taquicardia difiere significativamente del 5%.
Hipótesis:
t_test_chol_smoke <- t.test(chol ~ current_smoker_bin, data=datos)
t_test_chol_smoke
##
## Welch Two Sample t-test
##
## data: chol by current_smoker_bin
## t = 2.9119, df = 3884.8, p-value = 0.003612
## alternative hypothesis: true difference in means between group FALSE and group TRUE is not equal to 0
## 95 percent confidence interval:
## 1.352281 6.925837
## sample estimates:
## mean in group FALSE mean in group TRUE
## 238.6458 234.5067
Interpretación:
El valor-p es 0.00361.
Existen diferencias significativas en los niveles medios de
colesterol.
Hipótesis:
t_test_hr_smoke <- t.test(heart_rate ~ current_smoker_bin, data=datos, alternative="greater")
t_test_hr_smoke
##
## Welch Two Sample t-test
##
## data: heart_rate by current_smoker_bin
## t = -3.5809, df = 3896.4, p-value = 0.9998
## alternative hypothesis: true difference in means between group FALSE and group TRUE is greater than 0
## 95 percent confidence interval:
## -2.007336 Inf
## sample estimates:
## mean in group FALSE mean in group TRUE
## 75.00762 76.38302
Interpretación:
El valor-p es 1.
No hay evidencia de que los fumadores tengan mayor frecuencia cardíaca
promedio.
Hipótesis:
tabla_chol_smoke <- table(datos$current_smoker_bin, datos$chol_high)
prop_test_chol_smoke <- prop.test(tabla_chol_smoke)
prop_test_chol_smoke
##
## 2-sample test for equality of proportions with continuity correction
##
## data: tabla_chol_smoke
## X-squared = 5.4583, df = 1, p-value = 0.01948
## alternative hypothesis: two.sided
## 95 percent confidence interval:
## -0.069158628 -0.005995786
## sample estimates:
## prop 1 prop 2
## 0.5526718 0.5902490
Interpretación:
El valor-p es 0.0195.
La proporción de colesterol alto difiere significativamente entre
fumadores y no fumadores.
p1 <- ggplot(datos, aes(x = current_smoker, y = chol, fill = current_smoker)) +
geom_boxplot() +
labs(title = "Colesterol según hábito de fumar", y = "Colesterol (mg/dL)", x = "Fumador Actual") +
theme_minimal()
ggplotly(p1)
p2 <- ggplot(datos, aes(x = current_smoker, y = heart_rate, fill = current_smoker)) +
geom_boxplot() +
labs(title = "Frecuencia cardíaca según hábito de fumar", y = "Frecuencia cardíaca (lpm)", x = "Fumador Actual") +
theme_minimal()
ggplotly(p2)
df_prop <- datos %>%
group_by(current_smoker) %>%
summarise(ProporcionColesterolAlto = mean(chol_high, na.rm=TRUE))
p3 <- ggplot(df_prop, aes(x = current_smoker, y = ProporcionColesterolAlto, fill = current_smoker)) +
geom_col() +
labs(title = "Proporción de colesterol alto por grupo", y = "Proporción", x = "Fumador Actual") +
theme_minimal()
ggplotly(p3)