##Base de datos

Sayula <- c(25,25,29,27,25,29,29,29,25,29,29,29,25,25,29,29,31,31,29,27,25,25,27,29,31,29,31,29,25,29)

GomezFarias <- c(29,25,25,29,25,29,29,29,27,29,31,25,25,25,29,25,29,31,29,25,27,25,25,25,25,29,29,27,27,29)

Zacoalco <- c(29,29,29,29,29,27,27,25,29,25,31,29,25,29,27,29,25,25,29,27,27,27,25,31,25,29,29,25,27,25)

Techaluta <- c(27,31,27,25,27,25,29,27,27,25,29,29,25,25,25,25,25,29,29,25,29,27,25,25,31,29,25,25,31,25)

IMC <- c(Sayula, GomezFarias, Zacoalco, Techaluta)

Municipio <- factor(rep(c(“Sayula”,“GomezFarias”,“Zacoalco”,“Techaluta”), each=30))

datos <- data.frame(Municipio, IMC)

head(datos)

#Estadística descriptiva

library(dplyr)

datos %>% group_by(Municipio) %>% summarise( Media = mean(IMC), DE = sd(IMC), Min = min(IMC), Max = max(IMC) ) install.packages(“ggplot2”) library(ggplot2)

#Gráficas de normalidad

par(mfrow=c(2,2))

hist(Sayula, main=“Sayula”) hist(GomezFarias, main=“Gomez Farías”) hist(Zacoalco, main=“Zacoalco”) hist(Techaluta, main=“Techaluta”)

par(mfrow=c(2,2))

qqnorm(Sayula) qqline(Sayula) qqnorm(GomezFarias) qqline(GomezFarias) qqnorm(Zacoalco) qqline(Zacoalco) qqnorm(Techaluta) qqline(Techaluta)

#Pruebas de normalidad

shapiro.test(Sayula) shapiro.test(GomezFarias) shapiro.test(Zacoalco) shapiro.test(Techaluta) #Gráfica boxplot(IMC ~ Municipio, data=datos, col=“lightblue”, main=“Distribución del IMC”)

#Prueba formal

library(car)

leveneTest(IMC ~ Municipio, data=datos)

#Anova de una vía

modelo_anova <- aov(IMC ~ Municipio, data=datos)

summary(modelo_anova)

#Prueba post-hoc

TukeyHSD(modelo_anova)

#Correlación

matriz <- data.frame(Sayula, GomezFarias, Zacoalco, Techaluta)

cor(matriz, method=“pearson”)

#Correlación específica

cor.test(Sayula, GomezFarias, method=“pearson”)

#Regresión líneal

modelo_regresion <- lm(GomezFarias ~ Sayula)

summary(modelo_regresion)

#Análisis de residuos

par(mfrow=c(2,2)) plot(modelo_regresion)

R Markdown

This is an R Markdown document. Markdown is a simple formatting syntax for authoring HTML, PDF, and MS Word documents. For more details on using R Markdown see http://rmarkdown.rstudio.com.

When you click the Knit button a document will be generated that includes both content as well as the output of any embedded R code chunks within the document. You can embed an R code chunk like this:

summary(cars)
##      speed           dist       
##  Min.   : 4.0   Min.   :  2.00  
##  1st Qu.:12.0   1st Qu.: 26.00  
##  Median :15.0   Median : 36.00  
##  Mean   :15.4   Mean   : 42.98  
##  3rd Qu.:19.0   3rd Qu.: 56.00  
##  Max.   :25.0   Max.   :120.00

Including Plots

You can also embed plots, for example:

Note that the echo = FALSE parameter was added to the code chunk to prevent printing of the R code that generated the plot.