library(readxl)
library(plotrix)
library(modeest)
library(ggplot2)
library(tidyr)
library(car)
library(corrplot)
# Cargar archivo Excel
exam_4_esta_imc <- read_excel("exam 4 esta imc.xlsx")
# Visualizar datos
head(exam_4_esta_imc)
## # A tibble: 6 × 4
## Sayula Gomezfarias Zacoalco Techaluta
## <dbl> <dbl> <dbl> <dbl>
## 1 25 29 29 27
## 2 25 25 29 31
## 3 29 25 29 27
## 4 27 29 29 25
## 5 25 25 29 27
## 6 29 29 27 25
qqnorm(exam_4_esta_imc$Sayula)
qqline(exam_4_esta_imc$Sayula, col = 2)
a <- exam_4_esta_imc$Sayula
xb <- mean(a)
s <- sd(a)
hist(a,
freq = FALSE,
col = "lightblue",
xlab = "IMC Sayula",
main = "Histograma con curva normal")
curve(dnorm(x, mean = xb, sd = s),
col = "red",
lwd = 2,
add = TRUE)
ks.test(exam_4_esta_imc$Sayula,
"pnorm",
mean = mean(exam_4_esta_imc$Sayula),
sd = sd(exam_4_esta_imc$Sayula))
##
## Asymptotic one-sample Kolmogorov-Smirnov test
##
## data: exam_4_esta_imc$Sayula
## D = 0.30135, p-value = 0.008604
## alternative hypothesis: two-sided
shapiro.test(exam_4_esta_imc$Sayula)
##
## Shapiro-Wilk normality test
##
## data: exam_4_esta_imc$Sayula
## W = 0.81358, p-value = 0.0001171
qqnorm(exam_4_esta_imc$Gomezfarias)
qqline(exam_4_esta_imc$Gomezfarias, col = 2)
b <- exam_4_esta_imc$Gomezfarias
xb <- mean(b)
s <- sd(b)
hist(b,
freq = FALSE,
col = "lightgreen",
xlab = "IMC Gómez Farías",
main = "Histograma con curva normal")
curve(dnorm(x, mean = xb, sd = s),
col = "red",
lwd = 2,
add = TRUE)
ks.test(exam_4_esta_imc$Gomezfarias,
"pnorm",
mean = mean(exam_4_esta_imc$Gomezfarias),
sd = sd(exam_4_esta_imc$Gomezfarias))
##
## Asymptotic one-sample Kolmogorov-Smirnov test
##
## data: exam_4_esta_imc$Gomezfarias
## D = 0.26396, p-value = 0.03058
## alternative hypothesis: two-sided
shapiro.test(exam_4_esta_imc$Gomezfarias)
##
## Shapiro-Wilk normality test
##
## data: exam_4_esta_imc$Gomezfarias
## W = 0.79961, p-value = 6.449e-05
qqnorm(exam_4_esta_imc$Zacoalco)
qqline(exam_4_esta_imc$Zacoalco, col = 2)
c <- exam_4_esta_imc$Zacoalco
xb <- mean(c)
s <- sd(c)
hist(c,
freq = FALSE,
col = "yellow",
xlab = "IMC Zacoalco",
main = "Histograma con curva normal")
curve(dnorm(x, mean = xb, sd = s),
col = "red",
lwd = 2,
add = TRUE)
ks.test(exam_4_esta_imc$Zacoalco,
"pnorm",
mean = mean(exam_4_esta_imc$Zacoalco),
sd = sd(exam_4_esta_imc$Zacoalco))
##
## Asymptotic one-sample Kolmogorov-Smirnov test
##
## data: exam_4_esta_imc$Zacoalco
## D = 0.25167, p-value = 0.04472
## alternative hypothesis: two-sided
shapiro.test(exam_4_esta_imc$Zacoalco)
##
## Shapiro-Wilk normality test
##
## data: exam_4_esta_imc$Zacoalco
## W = 0.84349, p-value = 0.0004543
qqnorm(exam_4_esta_imc$Techaluta)
qqline(exam_4_esta_imc$Techaluta, col = 2)
d <- exam_4_esta_imc$Techaluta
xb <- mean(d)
s <- sd(d)
hist(d,
freq = FALSE,
col = "pink",
xlab = "IMC Techaluta",
main = "Histograma con curva normal")
curve(dnorm(x, mean = xb, sd = s),
col = "red",
lwd = 2,
add = TRUE)
ks.test(exam_4_esta_imc$Techaluta,
"pnorm",
mean = mean(exam_4_esta_imc$Techaluta),
sd = sd(exam_4_esta_imc$Techaluta))
##
## Asymptotic one-sample Kolmogorov-Smirnov test
##
## data: exam_4_esta_imc$Techaluta
## D = 0.28437, p-value = 0.01563
## alternative hypothesis: two-sided
shapiro.test(exam_4_esta_imc$Techaluta)
##
## Shapiro-Wilk normality test
##
## data: exam_4_esta_imc$Techaluta
## W = 0.80207, p-value = 7.153e-05
datos_largos <- pivot_longer(
exam_4_esta_imc,
cols = c(Sayula, Gomezfarias, Zacoalco, Techaluta),
names_to = "Municipio",
values_to = "IMC"
)
head(datos_largos)
## # A tibble: 6 × 2
## Municipio IMC
## <chr> <dbl>
## 1 Sayula 25
## 2 Gomezfarias 29
## 3 Zacoalco 29
## 4 Techaluta 27
## 5 Sayula 25
## 6 Gomezfarias 25
leveneTest(IMC ~ Municipio, data = datos_largos)
## Levene's Test for Homogeneity of Variance (center = median)
## Df F value Pr(>F)
## group 3 0.1938 0.9005
## 116
boxplot(IMC ~ Municipio,
data = datos_largos,
col = c("lightblue", "lightgreen", "lightyellow", "lightpink"),
main = "Comparación de varianzas entre municipios",
xlab = "Municipio",
ylab = "IMC")
kruskal.test(IMC ~ Municipio, data = datos_largos)
##
## Kruskal-Wallis rank sum test
##
## data: IMC by Municipio
## Kruskal-Wallis chi-squared = 3.2423, df = 3, p-value = 0.3557
cor.test(exam_4_esta_imc$Sayula,
exam_4_esta_imc$Gomezfarias,
method = "spearman")
##
## Spearman's rank correlation rho
##
## data: exam_4_esta_imc$Sayula and exam_4_esta_imc$Gomezfarias
## S = 2519.5, p-value = 0.0151
## alternative hypothesis: true rho is not equal to 0
## sample estimates:
## rho
## 0.4394987
cor.test(exam_4_esta_imc$Sayula,
exam_4_esta_imc$Zacoalco,
method = "spearman")
##
## Spearman's rank correlation rho
##
## data: exam_4_esta_imc$Sayula and exam_4_esta_imc$Zacoalco
## S = 5437.4, p-value = 0.2662
## alternative hypothesis: true rho is not equal to 0
## sample estimates:
## rho
## -0.209651
cor.test(exam_4_esta_imc$Sayula,
exam_4_esta_imc$Techaluta,
method = "spearman")
##
## Spearman's rank correlation rho
##
## data: exam_4_esta_imc$Sayula and exam_4_esta_imc$Techaluta
## S = 4817.3, p-value = 0.7065
## alternative hypothesis: true rho is not equal to 0
## sample estimates:
## rho
## -0.07171149
cor_matrix <- cor(
exam_4_esta_imc[, c("Sayula", "Gomezfarias", "Zacoalco", "Techaluta")],
method = "spearman"
)
cor_matrix
## Sayula Gomezfarias Zacoalco Techaluta
## Sayula 1.00000000 0.43949872 -0.2096510 -0.07171149
## Gomezfarias 0.43949872 1.00000000 -0.1105363 0.04836494
## Zacoalco -0.20965100 -0.11053628 1.0000000 0.17187935
## Techaluta -0.07171149 0.04836494 0.1718793 1.00000000
corrplot(
cor_matrix,
method = "color",
col = colorRampPalette(c("red", "white", "blue"))(200),
addCoef.col = "black",
number.cex = 0.7,
tl.col = "black",
tl.srt = 45,
title = "Matriz de correlaciones IMC entre municipios",
mar = c(0, 0, 2, 0)
)
Los cuatro municipios presentan distribución no normal, ya que las pruebas gráficas y formales rechazan la hipótesis de normalidad.
El valor de p de Kruskal-Wallis indica que no existen diferencias significativas entre las medianas de IMC de los municipios.
Gómez Farías y Sayula presentan la correlación más alta entre los municipios analizados, con un valor aproximado de 0.44, lo que indica una correlación moderada positiva.
Techaluta y Gómez Farías muestran una correlación muy débil cercana a 0.05. Además, existe una ligera correlación negativa entre Zacoalco y Sayula.
En general, los resultados sugieren que existe poca correlación entre los municipios, indicando una alta variabilidad regional en los valores de IMC.