
Instalar y cargar las bibliotecas necesarias
library(tidyverse)
## ── Attaching core tidyverse packages ──────────────────────── tidyverse 2.0.0 ──
## ✔ dplyr 1.1.2 ✔ readr 2.1.4
## ✔ forcats 1.0.0 ✔ stringr 1.5.0
## ✔ ggplot2 3.4.2 ✔ tibble 3.2.1
## ✔ lubridate 1.9.2 ✔ tidyr 1.3.0
## ✔ purrr 1.0.1
## ── Conflicts ────────────────────────────────────────── tidyverse_conflicts() ──
## ✖ dplyr::filter() masks stats::filter()
## ✖ dplyr::lag() masks stats::lag()
## ℹ Use the conflicted package (<http://conflicted.r-lib.org/>) to force all conflicts to become errors
library(ggplot2)
library(readxl)
library(gtsummary)
library(gt)
Leer la base de datos
base_datos <- read_excel("E:/OneDrive - CINVESTAV/PROYECTO MDatos/TRABAJOS/DraIrisHernándezMDatos/BASE DE DATOS IRIS.xlsx")
# 1. Análisis Descriptivo
summary(base_datos)
## # FICHA NOMBRE DE PACIENTE
## Min. : 1.0 Length:386 Length:386
## 1st Qu.: 97.0 Class :character Class :character
## Median :194.0 Mode :character Mode :character
## Mean :193.6
## 3rd Qu.:290.0
## Max. :386.0
## NA's :1
## FECHA DE NACIMIENTO EDAD >30 SDG SI/NO
## Min. :1968-10-05 00:00:00.000 Min. :12.0 Length:386
## 1st Qu.:1984-01-24 06:00:00.000 1st Qu.:30.0 Class :character
## Median :1987-12-20 00:00:00.000 Median :34.0 Mode :character
## Mean :1988-02-17 02:32:57.202 Mean :33.5
## 3rd Qu.:1991-08-06 00:00:00.000 3rd Qu.:38.0
## Max. :2020-11-27 00:00:00.000 Max. :53.0
##
## TALLA PESO AL INICIO DEL EMBARAZO IMC PREVIO AL EMBARAZO
## Min. :1.490 Min. : 44.50 Min. :17.63
## 1st Qu.:1.560 1st Qu.: 60.38 1st Qu.:23.82
## Median :1.590 Median : 68.00 Median :26.81
## Mean :1.594 Mean : 68.53 Mean :26.94
## 3rd Qu.:1.623 3rd Qu.: 75.00 3rd Qu.:29.50
## Max. :1.760 Max. :125.00 Max. :47.05
## NA's :214 NA's :214 NA's :214
## PESO AL FINAL DEL EMBARAZO INCREMENTO PONDERAL DURANTE EMBARAZO
## Min. : 53.70 Min. :-4.700
## 1st Qu.: 70.35 1st Qu.: 6.000
## Median : 77.45 Median :10.000
## Mean : 77.72 Mean : 9.188
## 3rd Qu.: 84.50 3rd Qu.:13.000
## Max. :133.00 Max. :22.500
## NA's :214 NA's :214
## CONTROL PRENATAL INSTITUCIONAL DIABETES GESTACIONAL (SI/NO)
## Length:386 Length:386
## Class :character Class :character
## Mode :character Mode :character
##
##
##
##
## PREECLAMPSIA (SI/NO) RESOLUCION DE LA GESTACION (PARTO/CESAREA)
## Length:386 Length:386
## Class :character Class :character
## Mode :character Mode :character
##
##
##
##
## EDAD GESTACIONAL AL MOMENTO DE LA RESOLUCION PESO DEL RN (GR)
## Min. :29.20 Min. :1130
## 1st Qu.:37.50 1st Qu.:2780
## Median :38.40 Median :3080
## Mean :38.21 Mean :2986
## 3rd Qu.:39.30 3rd Qu.:3290
## Max. :41.10 Max. :4200
## NA's :215 NA's :215
## RECIEN NACIDO (VIVO/MUERTO) SEXO DE RECIEN NACIDO (FEMENINO/MASCULINO)
## Length:386 Length:386
## Class :character Class :character
## Mode :character Mode :character
##
##
##
##
glimpse(base_datos)
## Rows: 386
## Columns: 19
## $ `#` <dbl> 1, 2, 3, 4, 5, 6, 7, 8,…
## $ FICHA <chr> "001197-08-1", "004085-…
## $ `NOMBRE DE PACIENTE` <chr> "LIDIA ANAHI GARCIA GAR…
## $ `FECHA DE NACIMIENTO` <dttm> 1988-08-06, 1981-04-23…
## $ EDAD <dbl> 32, 39, 44, 26, 42, 40,…
## $ `>30 SDG SI/NO` <chr> "RESOLUCION EXTRAPEMEX"…
## $ TALLA <dbl> NA, 1.57, NA, NA, NA, 1…
## $ `PESO AL INICIO DEL EMBARAZO` <dbl> NA, 72, NA, NA, NA, 63,…
## $ `IMC PREVIO AL EMBARAZO` <dbl> NA, 29.21011, NA, NA, N…
## $ `PESO AL FINAL DEL EMBARAZO` <dbl> NA, 92.0, NA, NA, NA, 7…
## $ `INCREMENTO PONDERAL DURANTE EMBARAZO` <dbl> NA, 20.0, NA, NA, NA, 7…
## $ `CONTROL PRENATAL INSTITUCIONAL` <chr> NA, "SI", NA, NA, NA, "…
## $ `DIABETES GESTACIONAL (SI/NO)` <chr> NA, "NO", NA, NA, NA, "…
## $ `PREECLAMPSIA (SI/NO)` <chr> NA, "NO", NA, NA, NA, "…
## $ `RESOLUCION DE LA GESTACION (PARTO/CESAREA)` <chr> NA, "CESAREA", NA, NA, …
## $ `EDAD GESTACIONAL AL MOMENTO DE LA RESOLUCION` <dbl> NA, 37.4, NA, NA, NA, 3…
## $ `PESO DEL RN (GR)` <dbl> NA, 3420, NA, NA, NA, 3…
## $ `RECIEN NACIDO (VIVO/MUERTO)` <chr> NA, "VIVO", NA, NA, NA,…
## $ `SEXO DE RECIEN NACIDO (FEMENINO/MASCULINO)` <chr> NA, "FEMENINO", NA, NA,…
dbiris<-base_datos %>% drop_na()
#Elimine los datos que estaban en blanco se redujo a 171 la n
glimpse(dbiris)
## Rows: 171
## Columns: 19
## $ `#` <dbl> 2, 6, 7, 8, 10, 11, 12,…
## $ FICHA <chr> "004085-08-3", "361925-…
## $ `NOMBRE DE PACIENTE` <chr> "AZUCENA MORADO SOLIS",…
## $ `FECHA DE NACIMIENTO` <dttm> 1981-04-23, 1980-11-07…
## $ EDAD <dbl> 39, 40, 42, 28, 42, 39,…
## $ `>30 SDG SI/NO` <chr> "SI", "SI", "SI", "SI",…
## $ TALLA <dbl> 1.57, 1.49, 1.50, 1.67,…
## $ `PESO AL INICIO DEL EMBARAZO` <dbl> 72.0, 63.0, 78.0, 60.0,…
## $ `IMC PREVIO AL EMBARAZO` <dbl> 29.21011, 28.37710, 34.…
## $ `PESO AL FINAL DEL EMBARAZO` <dbl> 92.0, 70.2, 77.0, 79.5,…
## $ `INCREMENTO PONDERAL DURANTE EMBARAZO` <dbl> 20.0, 7.2, -1.0, 19.5, …
## $ `CONTROL PRENATAL INSTITUCIONAL` <chr> "SI", "SI", "SI", "SI",…
## $ `DIABETES GESTACIONAL (SI/NO)` <chr> "NO", "SI", "SI", "NO",…
## $ `PREECLAMPSIA (SI/NO)` <chr> "NO", "NO", "NO", "NO",…
## $ `RESOLUCION DE LA GESTACION (PARTO/CESAREA)` <chr> "CESAREA", "CESAREA", "…
## $ `EDAD GESTACIONAL AL MOMENTO DE LA RESOLUCION` <dbl> 37.4, 38.5, 37.6, 38.4,…
## $ `PESO DEL RN (GR)` <dbl> 3420, 3080, 3080, 3540,…
## $ `RECIEN NACIDO (VIVO/MUERTO)` <chr> "VIVO", "VIVO", "VIVO",…
## $ `SEXO DE RECIEN NACIDO (FEMENINO/MASCULINO)` <chr> "FEMENINO", "FEMENINO",…
colnames(dbiris)
## [1] "#"
## [2] "FICHA"
## [3] "NOMBRE DE PACIENTE"
## [4] "FECHA DE NACIMIENTO"
## [5] "EDAD"
## [6] ">30 SDG SI/NO"
## [7] "TALLA"
## [8] "PESO AL INICIO DEL EMBARAZO"
## [9] "IMC PREVIO AL EMBARAZO"
## [10] "PESO AL FINAL DEL EMBARAZO"
## [11] "INCREMENTO PONDERAL DURANTE EMBARAZO"
## [12] "CONTROL PRENATAL INSTITUCIONAL"
## [13] "DIABETES GESTACIONAL (SI/NO)"
## [14] "PREECLAMPSIA (SI/NO)"
## [15] "RESOLUCION DE LA GESTACION (PARTO/CESAREA)"
## [16] "EDAD GESTACIONAL AL MOMENTO DE LA RESOLUCION"
## [17] "PESO DEL RN (GR)"
## [18] "RECIEN NACIDO (VIVO/MUERTO)"
## [19] "SEXO DE RECIEN NACIDO (FEMENINO/MASCULINO)"
Tabla 1: Resumen de estadísticas descriptivas.
library(gtsummary)
dbiris <- subset(dbiris, `RECIEN NACIDO (VIVO/MUERTO)` %in% c("VIVO"))
dbiris %>% select(EDAD:`SEXO DE RECIEN NACIDO (FEMENINO/MASCULINO)`) %>% tbl_summary(by=`DIABETES GESTACIONAL (SI/NO)`,) %>% add_p() %>% modify_caption("**Diabetes Gestacional** (N = {N})") %>% modify_header(label = "**Variables**", p.value = "**valor p**") %>% add_overall()
## There was an error in 'add_p()/add_difference()' for variable '>30 SDG SI/NO', p-value omitted:
## Error in stats::chisq.test(x = c("SI", "SI", "SI", "SI", "SI", "SI", "SI", : 'x' and 'y' must have at least 2 levels
## There was an error in 'add_p()/add_difference()' for variable 'RECIEN NACIDO (VIVO/MUERTO)', p-value omitted:
## Error in stats::chisq.test(x = c("VIVO", "VIVO", "VIVO", "VIVO", "VIVO", : 'x' and 'y' must have at least 2 levels
Diabetes Gestacional (N = 170)
| Variables |
Overall, N = 170 |
NO, N = 128 |
SI, N = 42 |
valor p |
| EDAD |
32.0 (29.0, 36.0) |
31.0 (28.0, 36.0) |
34.0 (31.0, 37.0) |
0.008 |
| >30 SDG SI/NO |
|
|
|
|
| SI |
170 (100%) |
128 (100%) |
42 (100%) |
|
| TALLA |
1.59 (1.56, 1.62) |
1.59 (1.56, 1.62) |
1.59 (1.56, 1.63) |
0.4 |
| PESO AL INICIO DEL EMBARAZO |
68 (61, 75) |
67 (59, 75) |
73 (64, 78) |
0.035 |
| IMC PREVIO AL EMBARAZO |
26.8 (23.8, 29.6) |
26.7 (23.6, 29.3) |
28.2 (25.5, 30.4) |
0.042 |
| PESO AL FINAL DEL EMBARAZO |
77 (70, 85) |
78 (69, 85) |
77 (73, 84) |
0.6 |
| INCREMENTO PONDERAL DURANTE EMBARAZO |
10.0 (6.0, 13.0) |
10.5 (6.5, 13.5) |
6.8 (3.6, 10.2) |
<0.001 |
| CONTROL PRENATAL INSTITUCIONAL |
|
|
|
>0.9 |
| NO |
1 (0.6%) |
1 (0.8%) |
0 (0%) |
|
| SI |
169 (99%) |
127 (99%) |
42 (100%) |
|
| PREECLAMPSIA (SI/NO) |
|
|
|
0.090 |
| NO |
157 (92%) |
121 (95%) |
36 (86%) |
|
| SI |
13 (7.6%) |
7 (5.5%) |
6 (14%) |
|
| RESOLUCION DE LA GESTACION (PARTO/CESAREA) |
|
|
|
0.4 |
| CESAREA |
83 (49%) |
60 (47%) |
23 (55%) |
|
| PARTO |
87 (51%) |
68 (53%) |
19 (45%) |
|
| EDAD GESTACIONAL AL MOMENTO DE LA RESOLUCION |
38.40 (37.50, 39.30) |
38.40 (37.50, 39.40) |
38.50 (37.50, 39.10) |
0.7 |
| PESO DEL RN (GR) |
3,080 (2,780, 3,295) |
3,030 (2,760, 3,265) |
3,160 (2,865, 3,401) |
0.057 |
| RECIEN NACIDO (VIVO/MUERTO) |
|
|
|
|
| VIVO |
170 (100%) |
128 (100%) |
42 (100%) |
|
| SEXO DE RECIEN NACIDO (FEMENINO/MASCULINO) |
|
|
|
>0.9 |
| FEMENINO |
92 (54%) |
69 (54%) |
23 (55%) |
|
| MASCULINO |
78 (46%) |
59 (46%) |
19 (45%) |
|
dbiris %>% select(EDAD:`SEXO DE RECIEN NACIDO (FEMENINO/MASCULINO)`) %>% tbl_summary(by=`PREECLAMPSIA (SI/NO)`) %>% add_p() %>% modify_caption("**Preclapsia** (N = {N})") %>% modify_header(label = "**Variables**", p.value = "**valor p**") %>% add_overall()
## There was an error in 'add_p()/add_difference()' for variable '>30 SDG SI/NO', p-value omitted:
## Error in stats::chisq.test(x = c("SI", "SI", "SI", "SI", "SI", "SI", "SI", : 'x' and 'y' must have at least 2 levels
## There was an error in 'add_p()/add_difference()' for variable 'RECIEN NACIDO (VIVO/MUERTO)', p-value omitted:
## Error in stats::chisq.test(x = c("VIVO", "VIVO", "VIVO", "VIVO", "VIVO", : 'x' and 'y' must have at least 2 levels
Preclapsia (N = 170)
| Variables |
Overall, N = 170 |
NO, N = 157 |
SI, N = 13 |
valor p |
| EDAD |
32.0 (29.0, 36.0) |
32.0 (29.0, 36.0) |
34.0 (30.0, 37.0) |
0.5 |
| >30 SDG SI/NO |
|
|
|
|
| SI |
170 (100%) |
157 (100%) |
13 (100%) |
|
| TALLA |
1.59 (1.56, 1.62) |
1.59 (1.56, 1.62) |
1.61 (1.60, 1.65) |
0.025 |
| PESO AL INICIO DEL EMBARAZO |
68 (61, 75) |
68 (60, 75) |
71 (68, 80) |
0.079 |
| IMC PREVIO AL EMBARAZO |
26.8 (23.8, 29.6) |
26.8 (23.8, 29.4) |
27.2 (25.0, 29.9) |
0.3 |
| PESO AL FINAL DEL EMBARAZO |
77 (70, 85) |
77 (70, 83) |
85 (82, 90) |
0.018 |
| INCREMENTO PONDERAL DURANTE EMBARAZO |
10.0 (6.0, 13.0) |
9.4 (6.0, 12.9) |
12.5 (4.5, 14.0) |
0.3 |
| CONTROL PRENATAL INSTITUCIONAL |
|
|
|
>0.9 |
| NO |
1 (0.6%) |
1 (0.6%) |
0 (0%) |
|
| SI |
169 (99%) |
156 (99%) |
13 (100%) |
|
| DIABETES GESTACIONAL (SI/NO) |
|
|
|
0.090 |
| NO |
128 (75%) |
121 (77%) |
7 (54%) |
|
| SI |
42 (25%) |
36 (23%) |
6 (46%) |
|
| RESOLUCION DE LA GESTACION (PARTO/CESAREA) |
|
|
|
0.001 |
| CESAREA |
83 (49%) |
71 (45%) |
12 (92%) |
|
| PARTO |
87 (51%) |
86 (55%) |
1 (7.7%) |
|
| EDAD GESTACIONAL AL MOMENTO DE LA RESOLUCION |
38.40 (37.50, 39.30) |
38.50 (37.60, 39.40) |
36.40 (35.20, 38.30) |
<0.001 |
| PESO DEL RN (GR) |
3,080 (2,780, 3,295) |
3,100 (2,840, 3,300) |
2,660 (1,780, 3,020) |
0.007 |
| RECIEN NACIDO (VIVO/MUERTO) |
|
|
|
|
| VIVO |
170 (100%) |
157 (100%) |
13 (100%) |
|
| SEXO DE RECIEN NACIDO (FEMENINO/MASCULINO) |
|
|
|
0.5 |
| FEMENINO |
92 (54%) |
86 (55%) |
6 (46%) |
|
| MASCULINO |
78 (46%) |
71 (45%) |
7 (54%) |
|
Gráfica 2: Distribución de pacientes con y sin diabetes
gestacional
dgbarplot<-ggplot(dbiris, aes(x = `DIABETES GESTACIONAL (SI/NO)`)) +
geom_bar(fill="skyblue", color= "black") +
labs(title = "Distribución de Pacientes con y sin Diabetes Gestacional",x="Diabetes gestacional", y="conteo") +
theme_minimal()
dgbarplot

Gráfica 3: Distribución de pacientes con y sin preeclampsia
preebarplot<-ggplot(dbiris, aes(x = `PREECLAMPSIA (SI/NO)`)) +
geom_bar(fill = "salmon", color= "black") +
labs(title = "Distribución de Pacientes con y sin Preeclampsia", x="Preeclampsia", y="conteo") +
theme_minimal()
preebarplot

2. Relación entre Ganancia de Peso, Diabetes Gestacional y
Preeclampsia
pC<-ggplot(dbiris, aes(x = `DIABETES GESTACIONAL (SI/NO)`, y = `INCREMENTO PONDERAL DURANTE EMBARAZO`)) +
geom_boxplot(fill = "skyblue") +
labs(title = "Ganancia de Peso en Pacientes con y sin Diabetes Gestacional",x="Diabetes Gestacional",y="Incremento preponderal durante el embarazo (Kg)") +
theme_minimal()
pd<-ggplot(dbiris, aes(x = `PREECLAMPSIA (SI/NO)`, y = `INCREMENTO PONDERAL DURANTE EMBARAZO`)) +
geom_boxplot(fill ="salmon") +
labs(title = "Ganancia de Peso en Pacientes con y sin Preeclampsia", x="Preeclampsia",y="Incremento preponderal durante el embarazo (Kg)") +
theme_minimal()
library(cowplot)
##
## Attaching package: 'cowplot'
## The following object is masked from 'package:lubridate':
##
## stamp
diabetesgest<-plot_grid(dgbarplot, pC, nrow = 2, ncol= 1, labels = c('A', 'C'), label_size = 12)
diabetesgest

preclampsia<-plot_grid(preebarplot, pd, nrow = 2, ncol= 1, labels = c('B', 'D'), label_size = 12)
preclampsia

plot_grid(diabetesgest,preclampsia)

library(gtsummary)
dbiris %>% select(`DIABETES GESTACIONAL (SI/NO)`, `PREECLAMPSIA (SI/NO)`, `INCREMENTO PONDERAL DURANTE EMBARAZO`) %>% tbl_summary()
| Characteristic |
N = 170 |
| DIABETES GESTACIONAL (SI/NO) |
|
| NO |
128 (75%) |
| SI |
42 (25%) |
| PREECLAMPSIA (SI/NO) |
|
| NO |
157 (92%) |
| SI |
13 (7.6%) |
| INCREMENTO PONDERAL DURANTE EMBARAZO |
10.0 (6.0, 13.0) |
dbiris %>% select(`DIABETES GESTACIONAL (SI/NO)`, `INCREMENTO PONDERAL DURANTE EMBARAZO`) %>% tbl_summary(by=`DIABETES GESTACIONAL (SI/NO)`) %>% add_overall() %>% add_p()
| Characteristic |
Overall, N = 170 |
NO, N = 128 |
SI, N = 42 |
p-value |
| INCREMENTO PONDERAL DURANTE EMBARAZO |
10.0 (6.0, 13.0) |
10.5 (6.5, 13.5) |
6.8 (3.6, 10.2) |
<0.001 |
dbiris %>% select(`PREECLAMPSIA (SI/NO)`, `INCREMENTO PONDERAL DURANTE EMBARAZO`) %>% tbl_summary(by=`PREECLAMPSIA (SI/NO)`) %>% add_overall() %>% add_p()
| Characteristic |
Overall, N = 170 |
NO, N = 157 |
SI, N = 13 |
p-value |
| INCREMENTO PONDERAL DURANTE EMBARAZO |
10.0 (6.0, 13.0) |
9.4 (6.0, 12.9) |
12.5 (4.5, 14.0) |
0.3 |
Gráfica 1: Histograma de la distribución del incremento ponderal
durante el embarazo
ggplot(dbiris, aes(x = `INCREMENTO PONDERAL DURANTE EMBARAZO`)) +
geom_histogram(fill= "skyblue", color = "black", binwidth = 1) +
labs(title = "Distribución del Incremento Ponderal del IMC durante el Embarazo", y="Conteo") +
theme_minimal()

library(dplyr)
# Resumen de estadísticas descriptivas
summary_stats <- dbiris %>%
summarise(
Media = mean(`INCREMENTO PONDERAL DURANTE EMBARAZO`, na.rm = TRUE),
Mediana = median(`INCREMENTO PONDERAL DURANTE EMBARAZO`, na.rm = TRUE),
Desviacion_Estandar = sd(`INCREMENTO PONDERAL DURANTE EMBARAZO`, na.rm = TRUE),
Minimo = min(`INCREMENTO PONDERAL DURANTE EMBARAZO`, na.rm = TRUE),
Maximo = max(`INCREMENTO PONDERAL DURANTE EMBARAZO`, na.rm = TRUE),
Rango_Intercuartil = IQR(`INCREMENTO PONDERAL DURANTE EMBARAZO`, na.rm = TRUE)
)
#install.packages("dlookr")
library(dlookr)
##
## Attaching package: 'dlookr'
## The following object is masked from 'package:tidyr':
##
## extract
## The following object is masked from 'package:base':
##
## transform
hist<-dbiris %>% describe(`INCREMENTO PONDERAL DURANTE EMBARAZO`)
hist %>% gt()
| described_variables |
n |
na |
mean |
sd |
se_mean |
IQR |
skewness |
kurtosis |
p00 |
p01 |
p05 |
p10 |
p20 |
p25 |
p30 |
p40 |
p50 |
p60 |
p70 |
p75 |
p80 |
p90 |
p95 |
p99 |
p100 |
| INCREMENTO PONDERAL DURANTE EMBARAZO |
170 |
0 |
9.107647 |
5.637869 |
0.4324048 |
7 |
-0.1310246 |
-0.3166283 |
-4.7 |
-3.017 |
-0.775 |
1 |
4.9 |
6 |
6.47 |
7.66 |
9.95 |
10.78 |
12.5 |
13 |
14 |
15.91 |
18.73 |
21.127 |
22.5 |
print(summary_stats)
## # A tibble: 1 × 6
## Media Mediana Desviacion_Estandar Minimo Maximo Rango_Intercuartil
## <dbl> <dbl> <dbl> <dbl> <dbl> <dbl>
## 1 9.11 9.95 5.64 -4.7 22.5 7
3. investigar la Relación entre Ganancia de Peso y Categorías de IMC
Pregestacional:
Basandonos en la siguiente tabla estableceremos los límites: 
# Cargar las bibliotecas necesarias
library(ggplot2)
library(gt)
# Definir límites de ganancia de peso según IMC pregestacional
limites_ganancia <- data.frame(
IMC_categoria = c("Bajo peso", "Peso normal", "Sobrepeso", "Obesidad"),
min_ganancia = c(12.5, 11.5, 7, 5),
max_ganancia = c(18, 16, 11.5, 9)
)
# Categorizar IMC
dbiris$IMC_categoria <- cut(dbiris$`IMC PREVIO AL EMBARAZO`,
breaks = c(-Inf, 18.5, 24.9, 29.9, Inf),
labels = c("Bajo peso", "Peso normal", "Sobrepeso", "Obesidad"),
right = FALSE)
# Unir con limites_ganancia
dbiris <- merge(dbiris, limites_ganancia, by = "IMC_categoria", all.x = TRUE)
# Calcular pacientes con ganancia de peso excesiva
dbiris$ganancia_excesiva <- with(dbiris, `INCREMENTO PONDERAL DURANTE EMBARAZO` > max_ganancia)
# Tabla de prevalencia
tabla_prevalencia <- table(dbiris$ganancia_excesiva)
porcentaje_excesivo <- (tabla_prevalencia["TRUE"] / sum(tabla_prevalencia)) * 100
# Crear y dibujar la tabla
tabla_final <- data.frame(
`Ganancia de Peso` = c("Dentro de lo recomendado", "Excesiva"),
`Número de Pacientes` = c(tabla_prevalencia["FALSE"], tabla_prevalencia["TRUE"]),
`Porcentaje (%)` = c(100 - porcentaje_excesivo, porcentaje_excesivo)
)
tabla_final %>%
gt() %>%
tab_header(
title = "Tabla 2: Número y porcentaje de pacientes con ganancia de peso excesiva."
)
| Tabla 2: Número y porcentaje de pacientes con ganancia de peso excesiva. |
| Ganancia.de.Peso |
Número.de.Pacientes |
Porcentaje.... |
| Dentro de lo recomendado |
124 |
72.94118 |
| Excesiva |
46 |
27.05882 |
124 pacientes (o el 72.94%) tuvieron una ganancia de peso dentro
de los límites recomendados.
46 pacientes (o el 27.06%) tuvieron una ganancia de peso
excesiva, es decir, por encima de lo recomendado.
Puedes presentar estos resultados en una tabla:
Tabla 2: Número y porcentaje de pacientes con ganancia de
peso excesiva.
| Dentro de lo recomendado |
124 |
72.94 |
| Excesiva |
46 |
27.06 |
Con estos resultados, tienes una idea clara de la prevalencia de
ganancia de peso excesiva en tu muestra. Ahora, puedes continuar con el
análisis de la relación entre la ganancia de peso y las categorías de
IMC pregestacional, y luego la relación entre la ganancia de peso,
diabetes gestacional y preeclampsia. # 2. Determinación de la
Prevalencia de Ganancia de Peso Excesiva
(Nota: Necesitarás definir un umbral para “ganancia de peso
excesiva”)
Gráfica 4: Boxplot mostrando la distribución de la ganancia de peso
por categorías de IMC pregestacional.
# Cargar las bibliotecas necesarias
library(ggplot2)
library(RColorBrewer)
library(ggpubr) # Para agregar significancias estadísticas
##
## Attaching package: 'ggpubr'
## The following object is masked from 'package:cowplot':
##
## get_legend
library(PMCMRplus) # Para comparaciones múltiples post-hoc
# Reordenar las categorías de IMC
dbiris$IMC_categoria <- factor(dbiris$IMC_categoria, levels = c("Peso normal", "Bajo peso", "Sobrepeso", "Obesidad"))
# Realizar la prueba Kruskal-Wallis
kw_test <- kruskal.test(`INCREMENTO PONDERAL DURANTE EMBARAZO` ~ IMC_categoria, data = dbiris)
# Comparaciones múltiples post-hoc
posthoc_test <- PMCMRplus::kwAllPairsNemenyiTest(dbiris$`INCREMENTO PONDERAL DURANTE EMBARAZO`, dbiris$IMC_categoria)
## Warning in kwAllPairsNemenyiTest.default(dbiris$`INCREMENTO PONDERAL DURANTE
## EMBARAZO`, : Ties are present, p-values are not corrected.
# Gráfica de boxplot
grafica <- ggplot(dbiris, aes(x = IMC_categoria, y = `INCREMENTO PONDERAL DURANTE EMBARAZO`, fill = IMC_categoria)) +
geom_boxplot(outlier.shape = NA) +
labs(title = "Gráfica 4: Distribución de la ganancia de peso por categorías de IMC pregestacional",
x = "Categoría de IMC pregestacional",
y = "Ganancia de peso durante el embarazo (kg)") +
theme_minimal() +
theme(legend.text = element_text(size = 10, color = "black", face = "bold"),
legend.position = "none",
plot.title = element_text(hjust = 0.5),
axis.text.x = element_text(size= 10,color="black", angle = 45, hjust = 1))
# Agregar significancias manualmente
comparisons <- list(c("Peso normal", "Bajo peso"),
c("Peso normal", "Sobrepeso"),
c("Peso normal", "Obesidad"))
pvalues <- posthoc_test$p.value
grafica + stat_compare_means(comparisons = comparisons,label = "p.signif")+ # Add pairwise comparisons p-value
stat_compare_means(label.y = 40, label.x= 3) # Add global p-value

#tabla con los valores:
dbiris %>% select(`INCREMENTO PONDERAL DURANTE EMBARAZO`, IMC_categoria) %>% tbl_summary(by=IMC_categoria) %>% add_p() %>% add_overall()
| Characteristic |
Overall, N = 170 |
Peso normal, N = 56 |
Bajo peso, N = 1 |
Sobrepeso, N = 73 |
Obesidad, N = 40 |
p-value |
| INCREMENTO PONDERAL DURANTE EMBARAZO |
10.0 (6.0, 13.0) |
11.0 (8.4, 14.7) |
14.5 (14.5, 14.5) |
9.4 (5.9, 12.8) |
6.9 (1.0, 10.5) |
<0.001 |
5. Análisis Multivariado
Para realizar un análisis multivariado, podemos utilizar un modelo de
regresión logística, ya que la variable de interés (Diabetes
Gestacional) es binaria (Sí/No).
Dado que la tabla proporcionada muestra diferencias en varias
variables entre los grupos con y sin diabetes gestacional, estas
variables se pueden considerar como posibles predictores en el
modelo.
Vamos a construir un modelo de regresión logística utilizando las
variables que mostraron diferencias estadísticamente significativas (p
< 0.05) y otras que podrían ser clínicamente relevantes.
Variables a considerar en el modelo:
EDAD PESO AL INICIO DEL EMBARAZO IMC PREVIO AL EMBARAZO INCREMENTO
PONDERAL DURANTE EMBARAZO PREECLAMPSIA (SI/NO) PESO DEL RN (GR) Aquí
está el código en R para construir el modelo de regresión logística:
# Crear un nuevo dataframe
dbirisrl <- dbiris
# Transformar las variables dicotómicas y agregarlas como nuevas columnas
dbirisrl$DG_binario <- ifelse(dbirisrl$`DIABETES GESTACIONAL (SI/NO)` == "SI", 1, 0)
dbirisrl$PE_binario <- ifelse(dbirisrl$`PREECLAMPSIA (SI/NO)` == "SI", 1, 0)
# Construir el modelo de regresión logística
modelo <- glm(DG_binario ~ EDAD + `PESO AL INICIO DEL EMBARAZO` + `IMC PREVIO AL EMBARAZO` + `INCREMENTO PONDERAL DURANTE EMBARAZO` + `PREECLAMPSIA (SI/NO)` + `PESO DEL RN (GR)`,
data = dbirisrl,
family = binomial())
# Mostrar el resumen del modelo
summary(modelo)
##
## Call:
## glm(formula = DG_binario ~ EDAD + `PESO AL INICIO DEL EMBARAZO` +
## `IMC PREVIO AL EMBARAZO` + `INCREMENTO PONDERAL DURANTE EMBARAZO` +
## `PREECLAMPSIA (SI/NO)` + `PESO DEL RN (GR)`, family = binomial(),
## data = dbirisrl)
##
## Coefficients:
## Estimate Std. Error z value Pr(>|z|)
## (Intercept) -8.3120543 2.5846779 -3.216 0.00130
## EDAD 0.0920483 0.0390435 2.358 0.01839
## `PESO AL INICIO DEL EMBARAZO` 0.0203172 0.0405306 0.501 0.61617
## `IMC PREVIO AL EMBARAZO` -0.0127184 0.1129718 -0.113 0.91036
## `INCREMENTO PONDERAL DURANTE EMBARAZO` -0.1094081 0.0405218 -2.700 0.00693
## `PREECLAMPSIA (SI/NO)`SI 1.7391873 0.7662026 2.270 0.02321
## `PESO DEL RN (GR)` 0.0012706 0.0004905 2.591 0.00958
##
## (Intercept) **
## EDAD *
## `PESO AL INICIO DEL EMBARAZO`
## `IMC PREVIO AL EMBARAZO`
## `INCREMENTO PONDERAL DURANTE EMBARAZO` **
## `PREECLAMPSIA (SI/NO)`SI *
## `PESO DEL RN (GR)` **
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## (Dispersion parameter for binomial family taken to be 1)
##
## Null deviance: 190.09 on 169 degrees of freedom
## Residual deviance: 160.38 on 163 degrees of freedom
## AIC: 174.38
##
## Number of Fisher Scoring iterations: 5
# Crear la tabla con gtsummary
tabla_modelo <- tbl_regression(modelo, exponentiate = TRUE)
# Mostrar la tabla
tabla_modelo
| Characteristic |
OR |
95% CI |
p-value |
| EDAD |
1.10 |
1.02, 1.19 |
0.018 |
| PESO AL INICIO DEL EMBARAZO |
1.02 |
0.94, 1.11 |
0.6 |
| IMC PREVIO AL EMBARAZO |
0.99 |
0.79, 1.23 |
>0.9 |
| INCREMENTO PONDERAL DURANTE EMBARAZO |
0.90 |
0.82, 0.97 |
0.007 |
| PREECLAMPSIA (SI/NO) |
|
|
|
| NO |
— |
— |
|
| SI |
5.69 |
1.31, 27.8 |
0.023 |
| PESO DEL RN (GR) |
1.00 |
1.00, 1.00 |
0.010 |
#forestplot
library(bstfun)
##
## Attaching package: 'bstfun'
## The following object is masked from 'package:ggpubr':
##
## as_ggplot
## The following object is masked from 'package:gtsummary':
##
## trial
as_forest_plot(tabla_modelo, col_names = c("estimate","ci", "p.value"))

(Nota: Necesitarás la biblioteca ‘lm’ para modelos de
regresión)
6. Prueba de Hipótesis
# Cargar las bibliotecas necesarias
library(gtsummary)
# Realizar la prueba t para la ganancia de peso entre los grupos con y sin diabetes gestacional
test_dg <- t.test(`INCREMENTO PONDERAL DURANTE EMBARAZO` ~ `DIABETES GESTACIONAL (SI/NO)`, data = dbiris)
# Realizar la prueba t para la ganancia de peso entre los grupos con y sin preeclampsia
test_pe <- t.test(`INCREMENTO PONDERAL DURANTE EMBARAZO` ~ `PREECLAMPSIA (SI/NO)`, data = dbirisrl)
# Crear una tabla resumen con gtsummary
tabla_resumen <- dbirisrl %>%
select(`INCREMENTO PONDERAL DURANTE EMBARAZO`, `DIABETES GESTACIONAL (SI/NO)`, `PREECLAMPSIA (SI/NO)`) %>%
tbl_summary(by = `DIABETES GESTACIONAL (SI/NO)`) %>%
add_p()
tabla_resumen
| Characteristic |
NO, N = 128 |
SI, N = 42 |
p-value |
| INCREMENTO PONDERAL DURANTE EMBARAZO |
10.5 (6.5, 13.5) |
6.8 (3.6, 10.2) |
<0.001 |
| PREECLAMPSIA (SI/NO) |
|
|
0.090 |
| NO |
121 (95%) |
36 (86%) |
|
| SI |
7 (5.5%) |
6 (14%) |
|
(Nota: Necesitarás la biblioteca ‘t.test’ para pruebas t)
7. Relación entre Ganancia de Peso y Resultados Perinatales
Gráfica 7: Boxplot de ganancia de peso según el tipo de resolución
de la gestación
# Cargar las bibliotecas necesarias
library(ggplot2)
# Gráfica 7
grafica7 <- ggplot(dbirisrl, aes(x = `RESOLUCION DE LA GESTACION (PARTO/CESAREA)`, y = `INCREMENTO PONDERAL DURANTE EMBARAZO`)) +
geom_boxplot(outlier.shape = NA, fill = "skyblue") +
labs(title = "Gráfica 7: Distribución de la ganancia de peso según el tipo de resolución de la gestación",
x = "Tipo de resolución de la gestación",
y = "Ganancia de peso durante el embarazo (kg)") +
theme_minimal() +
theme(plot.title = element_text(hjust = 0.5))
print(grafica7)

Gráfica 8: Scatterplot de ganancia de peso vs. peso del recién
nacido
# Calcular la correlación de Spearman
cor_test <- cor.test(dbirisrl$`INCREMENTO PONDERAL DURANTE EMBARAZO`, dbirisrl$`PESO DEL RN (GR)`, method = "spearman")
## Warning in cor.test.default(dbirisrl$`INCREMENTO PONDERAL DURANTE EMBARAZO`, :
## Cannot compute exact p-value with ties
# Mostrar el resultado
cor_test
##
## Spearman's rank correlation rho
##
## data: dbirisrl$`INCREMENTO PONDERAL DURANTE EMBARAZO` and dbirisrl$`PESO DEL RN (GR)`
## S = 774493, p-value = 0.4834
## alternative hypothesis: true rho is not equal to 0
## sample estimates:
## rho
## 0.05411785
# Gráfica 8
library(ggpubr) # Para agregar el valor de p y rho
# Calcular la correlación de Spearman
cor_test <- cor.test(dbirisrl$`INCREMENTO PONDERAL DURANTE EMBARAZO`, dbirisrl$`PESO DEL RN (GR)`, method = "spearman")
## Warning in cor.test.default(dbirisrl$`INCREMENTO PONDERAL DURANTE EMBARAZO`, :
## Cannot compute exact p-value with ties
# Gráfica 8: Scatterplot con valor de p y rho
grafica8 <- ggplot(dbirisrl, aes(x = `INCREMENTO PONDERAL DURANTE EMBARAZO`, y = `PESO DEL RN (GR)`)) +
geom_point(aes(color = `INCREMENTO PONDERAL DURANTE EMBARAZO`), alpha = 0.6) +
geom_smooth(method = "lm", se = FALSE, color = "red") + # Línea de regresión
scale_color_gradient(low = "blue", high = "red") +
labs(title = "Gráfica 8: Relación entre la ganancia de peso y el peso del recién nacido",
x = "Ganancia de peso durante el embarazo (kg)",
y = "Peso del recién nacido (gr)",
color = "Incremento ponderal") +
theme_minimal() +
theme(plot.title = element_text(hjust = 0.5)) +
stat_cor(method = "spearman", label.x = 3, label.y = 4000) # Agregar valor de p y rho
print(grafica8)
## `geom_smooth()` using formula = 'y ~ x'
