Paquetes

install.packages(“readxl”) install.packages(“ggplot2”) install.packages(“dplyr”) install.packages(“corrplot”) install.packages(“psych”)

Carga de paquetes

library(readxl) library(ggplot2) library(dplyr) library(corrplot) library(psych)

Leyendo Datos

data <- Datos_taller

Descripción básica de las variables numéricas

summary(Datos_taller\(Edad) describe(Datos_taller\)Edad)

View(Datos_taller) ################################################################################ # UNIVARIADA

#Edad describe(Datos_taller\(Edad) Edmo<-table(Datos_taller\)Edad) print(Edmo) quantile(Datos_taller$Edad,0.50, type = 6)

var(Datos_taller\(Edad) sd(Datos_taller\)Edad) sd(Datos_taller\(Edad)/mean(Datos_taller\)Edad)

Coloesterol

describe(Datos_taller\(Colesterol) como<-table(Datos_taller\)Colesterol) print(como) quantile(Datos_taller$Colesterol,0.50, type = 6)

var(Datos_taller\(Colesterol) sd(Datos_taller\)Colesterol) sd(Datos_taller\(Colesterol)/mean(Datos_taller\)Colesterol)

#Indice De M C describe(Datos_taller\(`Indice de masa corporal`) mcmo<-table(Datos_taller\)Indice de masa corporal) print(mcmo) quantile(Datos_taller$Indice de masa corporal,0.50, type = 6)

var(Datos_taller\(`Indice de masa corporal`) sd(Datos_taller\)Indice de masa corporal) sd(Datos_taller\(`Indice de masa corporal`)/ mean(Datos_taller\)Indice de masa corporal)

T A D

describe(Datos_taller\(`Tension arterial diastólica`) TADmo<-table(Datos_taller\)Tension arterial diastólica) print(TADmo) quantile(Datos_taller$Tension arterial diastólica,0.50, type = 6)

var(Datos_taller\(`Tension arterial diastólica`) sd(Datos_taller\)Tension arterial diastólica) sd(Datos_taller\(`Tension arterial diastólica`)/ mean(Datos_taller\)Tension arterial diastólica)

Estrato

describe(Datos_taller\(Estrato) Esmo<-table(Datos_taller\)Estrato) print(Esmo) quantile(Datos_taller$Estrato,0.50, type = 6)

var(Datos_taller\(Estrato) sd(Datos_taller\)Estrato) sd(Datos_taller\(`Tension arterial diastólica`)/ mean(Datos_taller\)Tension arterial diastólica)

#Histogramas # Edad ggplot(data, aes(x = Edad)) + geom_histogram(aes(y = ..density..), bins = 10, fill = “skyblue”, color = “black”) + geom_density(color = “red”) + ggtitle(“Distribución de Edad”)

Colesterol

ggplot(data, aes(x = Colesterol)) + geom_histogram(aes(y = ..density..), bins = 10, fill = “lightgreen”, color = “black”) + geom_density(color = “red”) + ggtitle(“Distribución de Colesterol”)

Indice de Masa Corporal

ggplot(data, aes(x = Indice de masa corporal)) + geom_histogram(aes(y = ..density..), bins = 10, fill = “white”, color = “black”) + geom_density(color = “red”) + ggtitle(“Distribución del I M C”)

Tension Arterial Diastolica

ggplot(data, aes(x = Tension arterial diastólica)) + geom_histogram(aes(y = ..density..), bins = 10, fill = “yellow”, color = “black”) + geom_density(color = “red”) + ggtitle(“Distribución de Tension Arterial Diastólica”)

Boxplots (Datos Atipicos)

Edad

ggplot(data, aes(y = Edad)) + geom_boxplot(fill = “lightblue”) + ggtitle(“Boxplot de Edad”)

Colesterol

ggplot(data, aes(y = Colesterol)) + geom_boxplot(fill = “lightgreen”) + ggtitle(“Boxplot de Colesterol”)

Indice de masa corporal

ggplot(data, aes(y = Indice de masa corporal)) + geom_boxplot(fill = “red”) + ggtitle(“Boxplot del I M C”)

Tension Arterial Diastolica

ggplot(data, aes(y = Tension arterial diastólica)) + geom_boxplot(fill = “yellow”) + ggtitle(“Boxplot del I M C”)

Calcular correlación y graficar el mapa de calor

cor_data <- cor(data %>% select_if(is.numeric), use = “complete.obs”)

Graficar el mapa de calor

corrplot(cor_data, method = “color”, addCoef.col = “black”, tl.cex = 0.8, number.cex = 0.7)

Relación entre Edad y Colesterol

ggplot(data, aes(x = Edad, y = Colesterol)) + geom_point(color = “blue”) + geom_smooth(method = “lm”, color = “red”) + ggtitle(“Relación entre Edad y Colesterol”)

Relación entre T A D y Colesterol

ggplot(data, aes(x = Tension arterial diastólica, y = Colesterol)) + geom_point(color = “blue”) + geom_smooth(method = “lm”, color = “red”) + ggtitle(“Relación entre T A D y Colesterol”)

Relación entre I M C y Colesterol

ggplot(data, aes(x = Indice de masa corporal, y = Colesterol)) + geom_point(color = “blue”) + geom_smooth(method = “lm”, color = “red”) + ggtitle(“Relación I M C y Colesterol”)

Relación entre T A D y Edad

ggplot(data, aes(x = Tension arterial diastólica, y = Edad)) + geom_point(color = “blue”) + geom_smooth(method = “lm”, color = “red”) + ggtitle(“Relación entre T A D y Edad”) ################################################################################ #Edad vs Colesterol boxplot( Edad~Colesterol, Datos_taller, main= “Edad vs Colesterol” ) ## boxplot( Colesterol~Edad, Datos_taller, main= “Colesterol vs Edad” ) #IMC vs Colesterol boxplot( Colesterol~Indice de masa corporal, Datos_taller, main=“Colesterol vs I M C” ) ## boxplot( Indice de masa corporal~Colesterol, Datos_taller, main=“I M C vs Colesterol” )

T A D VS Colesterol

boxplot( Colesterol~Tension arterial diastólica, Datos_taller, main=“Colesterol vs T A D” )

Genero Vs Colesterol

boxplot( Colesterol~Genero, Datos_taller, main=“Colesterol vs Genero” )

Tablas cruzadas

Promedio de Colesterol por Género

data %>% group_by(Genero) %>% summarise(Colesterol_promedio = mean(Colesterol, na.rm = TRUE))

Boxplot Colesterol por Género

ggplot(data, aes(x = Genero, y = Colesterol)) + geom_boxplot(fill = c(“pink”, “lightblue”)) + ggtitle(“Boxplot de Colesterol por Género”)

Leyendo Muestra

dat <- Muestra

Descripción básica de las variables numéricas (Muestra)

summary(Muestra\(Edad) describe(Muestra\)Edad)

View(Muestra) ################################################################################ # UNIVARIADA

#Edad describe(Muestra\(Edad) Edmo<-table(Muestra\)Edad) print(Edmo) quantile(Muestra$Edad,0.50, type = 6)

var(Muestra\(Edad) sd(Muestra\)Edad) sd(Muestra\(Edad)/mean(Muestra\)Edad)

Coloesterol

describe(Muestra\(Colesterol) como<-table(Muestra\)Colesterol) print(como) quantile(Muestra$Colesterol,0.50, type = 6)

var(Muestra\(Colesterol) sd(Muestra\)Colesterol) sd(Muestra\(Colesterol)/mean(Muestra\)Colesterol)

#Indice De M C describe(Muestra\(`Indice de masa corporal`) mcmo<-table(Muestra\)Indice de masa corporal) print(mcmo) quantile(Muestra$Indice de masa corporal,0.50, type = 6)

var(Muestra\(`Indice de masa corporal`) sd(Muestra\)Indice de masa corporal) sd(Muestra\(`Indice de masa corporal`)/ mean(Muestra\)Indice de masa corporal)

T A D

describe(Muestra\(`Tension arterial diastólica`) TADmo<-table(Muestra\)Tension arterial diastólica) print(TADmo) quantile(Muestra$Tension arterial diastólica,0.50, type = 6)

var(Muestra\(`Tension arterial diastólica`) sd(Muestra\)Tension arterial diastólica) sd(Muestra\(`Tension arterial diastólica`)/ mean(Muestra\)Tension arterial diastólica)

Estrato

describe(Muestra\(Estrato) Esmo<-table(Muestra\)Estrato) print(Esmo) quantile(Muestra$Estrato,0.50, type = 6)

var(Muestra\(Estrato) sd(Muestra\)Estrato) sd(Muestra\(`Tension arterial diastólica`)/ mean(Muestra\)Tension arterial diastólica)

#Histogramas # Edad ggplot(dat, aes(x = Edad)) + geom_histogram(aes(y = ..density..), bins = 10, fill = “skyblue”, color = “black”) + geom_density(color = “red”) + ggtitle(“Distribución de Edad”)

Colesterol

ggplot(dat, aes(x = Colesterol)) + geom_histogram(aes(y = ..density..), bins = 10, fill = “lightgreen”, color = “black”) + geom_density(color = “red”) + ggtitle(“Distribución de Colesterol”)

Indice de Masa Corporal

ggplot(dat, aes(x = Indice de masa corporal)) + geom_histogram(aes(y = ..density..), bins = 10, fill = “white”, color = “black”) + geom_density(color = “red”) + ggtitle(“Distribución del I M C”)

Tension Arterial Diastolica

ggplot(dat, aes(x = Tension arterial diastólica)) + geom_histogram(aes(y = ..density..), bins = 10, fill = “yellow”, color = “black”) + geom_density(color = “red”) + ggtitle(“Distribución de Tension Arterial Diastólica”)

Boxplots (Datos Atipicos)

Edad

ggplot(dat, aes(y = Edad)) + geom_boxplot(fill = “lightblue”) + ggtitle(“Boxplot de Edad”)

Colesterol

ggplot(dat, aes(y = Colesterol)) + geom_boxplot(fill = “lightgreen”) + ggtitle(“Boxplot de Colesterol”)

Indice de masa corporal

ggplot(dat, aes(y = Indice de masa corporal)) + geom_boxplot(fill = “red”) + ggtitle(“Boxplot del I M C”)

Tension Arterial Diastolica

ggplot(dat, aes(y = Tension arterial diastólica)) + geom_boxplot(fill = “yellow”) + ggtitle(“Boxplot del I M C”)

Calcular correlación y graficar el mapa de calor

cor_dat <- cor(dat %>% select_if(is.numeric), use = “complete.obs”)

Graficar el mapa de calor

corrplot(cor_dat, method = “color”, addCoef.col = “black”, tl.cex = 0.8, number.cex = 0.7)

Relación entre Edad y Colesterol

ggplot(dat, aes(x = Edad, y = Colesterol)) + geom_point(color = “blue”) + geom_smooth(method = “lm”, color = “red”) + ggtitle(“Relación entre Edad y Colesterol”)

Relación entre T A D y Colesterol

ggplot(dat, aes(x = Tension arterial diastólica, y = Colesterol)) + geom_point(color = “blue”) + geom_smooth(method = “lm”, color = “red”) + ggtitle(“Relación entre T A D y Colesterol”)

Relación entre I M C y Colesterol

ggplot(dat, aes(x = Indice de masa corporal, y = Colesterol)) + geom_point(color = “blue”) + geom_smooth(method = “lm”, color = “red”) + ggtitle(“Relación I M C y Colesterol”)

Relación entre T A D y Edad

ggplot(dat, aes(x = Tension arterial diastólica, y = Edad)) + geom_point(color = “blue”) + geom_smooth(method = “lm”, color = “red”) + ggtitle(“Relación entre T A D y Edad”) ################################################################################ #Edad vs Colesterol boxplot( Edad~Colesterol, Muestra, main= “Edad vs Colesterol” ) ## boxplot( Colesterol~Edad, Muestra, main= “Colesterol vs Edad” ) #IMC vs Colesterol boxplot( Colesterol~Indice de masa corporal, Muestra, main=“Colesterol vs I M C” ) ## boxplot( Indice de masa corporal~Colesterol, Muestra, main=“I M C vs Colesterol” )

T A D VS Colesterol

boxplot( Colesterol~Tension arterial diastólica, Muestra, main=“Colesterol vs T A D” )

Genero Vs Colesterol

boxplot( Colesterol~Genero, Muestra, main=“Colesterol vs Genero” )

Tablas cruzadas

Promedio de Colesterol por Género

dat %>% group_by(Genero) %>% summarise(Colesterol_promedio = mean(Colesterol, na.rm = TRUE))

Boxplot Colesterol por Género

ggplot(dat, aes(x = Genero, y = Colesterol)) + geom_boxplot(fill = c(“pink”, “lightblue”)) + ggtitle(“Boxplot de Colesterol por Género”)