install.packages(c("tidyverse","gtsummary", "readxl", "ggpubr","cowplot"))
## Installing packages into '/cloud/lib/x86_64-pc-linux-gnu-library/4.4'
## (as 'lib' is unspecified)
# Cargar las librerías necesarias
library(tidyverse)
## ── Attaching core tidyverse packages ──────────────────────── tidyverse 2.0.0 ──
## ✔ dplyr     1.1.4     ✔ readr     2.1.5
## ✔ forcats   1.0.0     ✔ stringr   1.5.1
## ✔ ggplot2   3.5.1     ✔ tibble    3.2.1
## ✔ lubridate 1.9.3     ✔ tidyr     1.3.1
## ✔ purrr     1.0.2     
## ── 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(gtsummary)
library(readxl)
library(readxl)
data <- read_excel("base de datos polimorfismos gen RAGE.xlsx")
#View(data)
# Ensure `data` is a data frame
data <- as.data.frame(data)

# Recodificar las variables de interés incluyendo "Renal"
data <- data %>%
  mutate(
    Sexo = recode(Sexo, "M" = "Másculino", "F" = "Femenino"))

data$`Peso (kg)` <- as.numeric(data$`Peso (kg)`)
summary_table <- data %>%
  select(Grup,Sexo, Edad, `Peso (kg)`, `Talla (M)`, `Cintura (cm)`, `Cadera (cm)`,IMC  
  ) %>%
  tbl_summary(
    by =Grup, # Agrupar por la variable dependiente "Renal_Dysfunction"
    missing = "no" # Excluye valores faltantes
  ) %>% add_overall() %>% 
  add_p() %>%
  modify_header(label = "**Variables**") %>%
  modify_caption("**Table: Características Clínicas y Demograficas de pacientes con SD**") %>%
  as_gt() %>%
  gt::tab_style(
    style = gt::cell_text(weight = "bold"),
    locations = gt::cells_column_labels()
  )


summary_table
Table: Características Clínicas y Demograficas de pacientes con SD
Variables Overall
N = 105
1
CTRL
N = 55
1
SD
N = 50
1
p-value2
Sexo


0.6
    Femenino 51 (49%) 28 (51%) 23 (46%)
    Másculino 54 (51%) 27 (49%) 27 (54%)
Edad 10.0 (7.0, 12.0) 10.0 (8.0, 12.0) 10.0 (6.0, 13.0) 0.8
Peso (kg) 32 (22, 43) 31 (24, 41) 32 (18, 46) 0.9
Talla (M) 1.33 (1.17, 1.45) 1.38 (1.26, 1.48) 1.28 (1.05, 1.40) 0.002
Cintura (cm) 61 (54, 71) 58 (53, 63) 65 (56, 75) 0.005
Cadera (cm) 72 (62, 84) 70 (64, 81) 78 (61, 86) 0.4
IMC 17.1 (15.7, 20.5) 16.5 (15.4, 18.2) 19.1 (16.8, 24.0) <0.001
1 n (%); Median (Q1, Q3)
2 Pearson’s Chi-squared test; Wilcoxon rank sum test
summary_table <- data %>%
  select(Grup, HBA1c, `Acido Urico (mg/dL)`, `Glucosa (mg/dL)`, `Urea (mg/dL)`,
        `Creatinina (mg/dL)`, 
  ) %>%
  tbl_summary(
    by =Grup, # Agrupar por la variable dependiente "Sindrome Down"
    missing = "ifany" # Excluye valores faltantes
  ) %>% add_overall() %>% 
  add_p() %>%
  modify_header(label = "**Variables**") %>%
  modify_caption("**Table: Laboratorios química Sanguínea de pacientes con SD**") %>%
  as_gt() %>%
  gt::tab_style(
    style = gt::cell_text(weight = "bold"),
    locations = gt::cells_column_labels()
  )


summary_table
Table: Laboratorios química Sanguínea de pacientes con SD
Variables Overall
N = 105
1
CTRL
N = 55
1
SD
N = 50
1
p-value2
HBA1c 5.10 (4.88, 5.40) 5.20 (4.90, 5.30) 5.06 (4.70, 5.50) 0.6
Acido Urico (mg/dL) 4.46 (3.70, 5.40) 3.86 (3.30, 4.50) 5.35 (4.50, 5.80) <0.001
    Unknown 4 0 4
Glucosa (mg/dL) 92 (86, 100) 93 (85, 104) 92 (86, 99) 0.3
Urea (mg/dL) 25 (20, 30) 23 (17, 29) 28 (23, 31) <0.001
Creatinina (mg/dL) 0.47 (0.39, 0.60) 0.45 (0.38, 0.53) 0.50 (0.40, 0.63) 0.11
1 Median (Q1, Q3)
2 Wilcoxon rank sum test
install.packages(c("ggpubr", "cowplot"))
## Installing packages into '/cloud/lib/x86_64-pc-linux-gnu-library/4.4'
## (as 'lib' is unspecified)
library(ggpubr)
library(cowplot)
## 
## Attaching package: 'cowplot'
## The following object is masked from 'package:ggpubr':
## 
##     get_legend
## The following object is masked from 'package:lubridate':
## 
##     stamp
# Definir los colores personalizados
custom_colors <- c("Control" = "#1f77b4", "SD" = "#ff7f0e")

# Crear un tema común para asegurarse de que todos los gráficos tengan el mismo tamaño de ejes
theme_custom <- theme_pubr() + 
  theme(axis.title.x = element_blank(), axis.title.y = element_blank(),
        axis.text = element_text(size = 10), legend.position = "none")

# Crear las gráficas de boxplot para cada variable, agrupadas por Grup
p1 <- ggplot(data, aes(x = Grup, y = `HBA1c`, fill = Grup)) +
  geom_boxplot(outlier.shape = NA) +
  geom_jitter(width = 0.2, alpha = 0.5, color = "black") +
  stat_compare_means(aes(label = ..p.signif..), label.x = 1.5, label.y = 15) +
  labs(title = "HBA1c", y = "HBA1c (%)") +
  scale_x_discrete(labels = c("Control", "SD")) +
  scale_fill_manual(values = custom_colors) +
  ylim(0, 20) +  # Asegurar la misma escala para el eje y
  theme_custom

p2 <- ggplot(data, aes(x = Grup, y = `Acido Urico (mg/dL)`, fill = Grup)) +
  geom_boxplot(outlier.shape = NA) +
  geom_jitter(width = 0.2, alpha = 0.5, color = "black") +
  stat_compare_means(aes(label = ..p.signif..), label.x = 1.5, label.y = 15) +
  labs(title = "Ácido Úrico", y = "Ácido Úrico (mg/dL)") +
  scale_x_discrete(labels = c("Control", "SD")) +
  scale_fill_manual(values = custom_colors) +
  ylim(0, 20) +  # Asegurar la misma escala para el eje y
  theme_custom

p3 <- ggplot(data, aes(x = Grup, y = `Glucosa (mg/dL)`, fill = Grup)) +
  geom_boxplot(outlier.shape = NA) +
  geom_jitter(width = 0.2, alpha = 0.5, color = "black") +
  stat_compare_means(aes(label = ..p.signif..), label.x = 1.5, label.y = 500) +
  labs(title = "Glucosa", y = "Glucosa (mg/dL)") +
  scale_x_discrete(labels = c("Control", "SD")) +
  scale_fill_manual(values = custom_colors) +
  ylim(0, 600) +  # Asegurar la misma escala para el eje y
  theme_custom

p4 <- ggplot(data, aes(x = Grup, y = `Urea (mg/dL)`, fill = Grup)) +
  geom_boxplot(outlier.shape = NA) +
  geom_jitter(width = 0.2, alpha = 0.5, color = "black") +
  stat_compare_means(aes(label = ..p.signif..), label.x = 1.5, label.y = 200) +
  labs(title = "Urea", y = "Urea (mg/dL)") +
  scale_x_discrete(labels = c("Control", "SD")) +
  scale_fill_manual(values = custom_colors) +
  ylim(0, 250) +  # Asegurar la misma escala para el eje y
  theme_custom

p5 <- ggplot(data, aes(x = Grup, y = `Creatinina (mg/dL)`, fill = Grup)) +
  geom_boxplot(outlier.shape = NA) +
  geom_jitter(width = 0.2, alpha = 0.5, color = "black") +
  stat_compare_means(aes(label = ..p.signif..), label.x = 1.5, label.y = 10) +
  labs(title = "Creatinina", y = "Creatinina (mg/dL)") +
  scale_x_discrete(labels = c("Control", "SD")) +
  scale_fill_manual(values = custom_colors) +
  ylim(0, 15) +  # Asegurar la misma escala para el eje y
  theme_custom

# Crear la leyenda personalizada con el título "Grup"
legend <- get_legend(
  ggplot(data, aes(x = Grup, y = `Creatinina (mg/dL)`, fill = Grup)) +
    geom_boxplot() +
    labs(fill = "Grup") +  # Cambiar la etiqueta de la leyenda aquí
    scale_x_discrete(labels = c("Control", "SD")) +
    scale_fill_manual(values = custom_colors) +
    theme(legend.position = "bottom")
)
## Warning in get_plot_component(plot, "guide-box"): Multiple components found;
## returning the first one. To return all, use `return_all = TRUE`.
# Ajustar las proporciones relativas de los gráficos para garantizar el mismo tamaño de las celdas
top_row <- plot_grid(p1, p2, labels = c('A', 'B'), label_size = 12, ncol = 2, rel_widths = c(1, 1))
## Warning: Removed 4 rows containing non-finite outside the scale range
## (`stat_boxplot()`).
## Warning: Removed 4 rows containing non-finite outside the scale range
## (`stat_compare_means()`).
## Warning: Removed 4 rows containing missing values or values outside the scale range
## (`geom_point()`).
bottom_row <- plot_grid(p3, p4, p5, labels = c('C', 'D', 'E'), label_size = 12, ncol = 3, rel_widths = c(1, 1, 1))

# Combinar ambas filas y agregar la leyenda
combined_plot <- plot_grid(top_row, bottom_row, legend, ncol = 1, rel_heights = c(1, 1, 0.2))

# Mostrar el gráfico
print(combined_plot)

summary_table <- data %>%
  select(Grup, `Colesterol (mg/dL)`, `Trigliceridos (mg/dL)`, `C - HDL (mg/dL)`,`C-LDL (mg/dL)`,`C -VLDL (mg/dL)`) %>%
  tbl_summary(
    by =Grup, # Agrupar por la variable dependiente "Sindrome Down"
    missing = "ifany", # Excluye valores faltantes
   statistic = list(
      all_continuous() ~ "{median} ({IQR})"
    )) %>%  # Agregar el IQR a las estadísticas %>% add_overall() %>% 
  add_p() %>% add_overall() %>% 
  modify_header(label = "**Variables**") %>%
  modify_caption("**Table: Laboratorios química Sanguínea de pacientes con SD**") %>%
  as_gt() %>%
  gt::tab_style(
    style = gt::cell_text(weight = "bold"),
    locations = gt::cells_column_labels()
  )


summary_table
Table: Laboratorios química Sanguínea de pacientes con SD
Variables Overall
N = 105
1
CTRL
N = 55
1
SD
N = 50
1
p-value2
Colesterol (mg/dL) 157 (48) 158 (44) 154 (44) 0.4
Trigliceridos (mg/dL) 76 (41) 63 (22) 97 (33) <0.001
C - HDL (mg/dL) 53 (21) 58 (17) 45 (16) <0.001
C-LDL (mg/dL) 88 (32) 88 (31) 87 (34) >0.9
C -VLDL (mg/dL) 15 (8) 13 (4) 19 (6) <0.001
1 Median (IQR)
2 Wilcoxon rank sum test
library(ggpubr)
library(cowplot)

# Definir los colores personalizados
custom_colors <- c("Control" = "#1f77b4", "SD" = "#ff7f0e")

# Crear un tema común para asegurarse de que todos los gráficos tengan el mismo tamaño de ejes
theme_custom <- theme_classic2() + 
  theme(axis.title.x = element_blank(), axis.title.y = element_blank(),
        axis.text = element_text(size = 12), legend.position = "none")

# Crear las gráficas de boxplot para cada variable, agrupadas por Grup
p1 <- ggplot(data, aes(x = Grup, y = `Colesterol (mg/dL)`, fill = Grup)) +
  geom_boxplot(outlier.shape = NA) +
  geom_jitter(width = 0.2, alpha = 0.5, color = "black") +
  stat_compare_means(aes(label = ..p.signif..), label.x = 1.5, label.y = 400) +
  labs(title = "Colesterol", y = "Colesterol (mg/dL)") +
  scale_x_discrete(labels = c("Control", "SD")) +
  scale_fill_manual(values = custom_colors) +
  ylim(0, 600) +  # Asegurar la misma escala para el eje y
  theme_custom

p2 <- ggplot(data, aes(x = Grup, y = `Trigliceridos (mg/dL)`, fill = Grup)) +
  geom_boxplot(outlier.shape = NA) +
  geom_jitter(width = 0.2, alpha = 0.5, color = "black") +
  stat_compare_means(aes(label = ..p.signif..), label.x = 1.5, label.y = 400) +
  labs(title = "Triglicéridos", y = "Triglicéridos (mg/dL)") +
  scale_x_discrete(labels = c("Control", "SD")) +
  scale_fill_manual(values = custom_colors) +
  ylim(0, 600) +  # Asegurar la misma escala para el eje y
  theme_custom

p3 <- ggplot(data, aes(x = Grup, y = `C - HDL (mg/dL)`, fill = Grup)) +
  geom_boxplot(outlier.shape = NA) +
  geom_jitter(width = 0.2, alpha = 0.5, color = "black") +
  stat_compare_means(aes(label = ..p.signif..), label.x = 1.5, label.y = 150) +
  labs(title = "C - HDL", y = "C - HDL (mg/dL)") +
  scale_x_discrete(labels = c("Control", "SD")) +
  scale_fill_manual(values = custom_colors) +
  ylim(0, 200) +  # Asegurar la misma escala para el eje y
  theme_custom

p4 <- ggplot(data, aes(x = Grup, y = `C-LDL (mg/dL)`, fill = Grup)) +
  geom_boxplot(outlier.shape = NA) +
  geom_jitter(width = 0.2, alpha = 0.5, color = "black") +
  stat_compare_means(aes(label = ..p.signif..), label.x = 1.5, label.y = 500) +
  labs(title = "C - LDL", y = "C - LDL (mg/dL)") +
  scale_x_discrete(labels = c("Control", "SD")) +
  scale_fill_manual(values = custom_colors) +
  ylim(0, 600) +  # Asegurar la misma escala para el eje y
  theme_custom

p5 <- ggplot(data, aes(x = Grup, y = `C -VLDL (mg/dL)`, fill = Grup)) +
  geom_boxplot(outlier.shape = NA) +
  geom_jitter(width = 0.2, alpha = 0.5, color = "black") +
  stat_compare_means(aes(label = ..p.signif..), label.x = 1.5, label.y = 200) +
  labs(title = "C - VLDL", y = "C - VLDL (mg/dL)") +
  scale_x_discrete(labels = c("Control", "SD")) +
  scale_fill_manual(values = custom_colors) +
  ylim(0, 300) +  # Asegurar la misma escala para el eje y
  theme_custom

# Crear la leyenda personalizada con el título "Grup"
legend <- get_legend(
  ggplot(data, aes(x = Grup, y = `C -VLDL (mg/dL)`, fill = Grup)) +
    geom_boxplot() +
    labs(fill = "Grup") +  # Cambiar la etiqueta de la leyenda aquí
    scale_x_discrete(labels = c("Control", "SD")) +
    scale_fill_manual(values = custom_colors) +
    theme(legend.position = "bottom")
)
## Warning in get_plot_component(plot, "guide-box"): Multiple components found;
## returning the first one. To return all, use `return_all = TRUE`.
# Ajustar las proporciones relativas de los gráficos para garantizar el mismo tamaño de las celdas
top_row <- plot_grid(p1, p2, labels = c('A', 'B'), label_size = 12, ncol = 2, rel_widths = c(1, 1))

bottom_row <- plot_grid(p3, p4, p5, labels = c('C', 'D', 'E'), label_size = 12, ncol = 3, rel_widths = c(1, 1, 1))

# Combinar ambas filas y agregar la leyenda
combined_plot <- plot_grid(top_row, bottom_row, legend, ncol = 1, rel_heights = c(1, 1, 0.2))

# Mostrar el gráfico
print(combined_plot)

## RAGE SOLUBLE

ggplot(data, aes(x = Grup, y = `niveles de AGEs circulantes Final` , fill = Grup)) +
  geom_boxplot(outlier.shape = NA) +
  geom_jitter(width = 0.2, alpha = 0.5, color = "black") +
  stat_compare_means(aes(label = ..p.signif..), label.x = 1.5, label.y = 200) +
  labs(title = "AGEs circulante", y = "C - VLDL (mg/dL)") +
  scale_x_discrete(labels = c("Control", "SD")) +
  scale_fill_manual(values = custom_colors) +
  ylim(-1000, 500) +  # Asegurar la misma escala para el eje y
  theme_custom
## Warning: Removed 7 rows containing non-finite outside the scale range
## (`stat_boxplot()`).
## Warning: Removed 7 rows containing non-finite outside the scale range
## (`stat_compare_means()`).
## Warning: Removed 7 rows containing missing values or values outside the scale range
## (`geom_point()`).

summary_table <- data %>%
  select(Grup, `niveles de AGEs circulantes Final`) %>%
  tbl_summary(
    by =Grup, # Agrupar por la variable dependiente "Sindrome Down"
    missing = "ifany", # Excluye valores faltantes
   statistic = list(
      all_continuous() ~ "{median} ({IQR})"
    )) %>%  # Agregar el IQR a las estadísticas %>% add_overall() %>% 
  add_p() %>% add_overall() %>% 
  modify_header(label = "**Variables**") %>%
  modify_caption("**Tabla: niveles de AGEs circulantes de pacientes con SD y control**") %>%
  as_gt() %>%
  gt::tab_style(
    style = gt::cell_text(weight = "bold"),
    locations = gt::cells_column_labels()
  )

Polymorphism association

# Install and load SNPassoc
#install.packages("SNPassoc")
library(SNPassoc)
## Registered S3 method overwritten by 'SNPassoc':
##   method            from       
##   summary.haplo.glm haplo.stats
# Assuming your data is in a data frame called 'genotype_data'
# and you have loaded the data into R, with the genotype columns and Renal_Dysfunction status
# Example data loading
# genotype_data <- read.csv("your_data_file.csv")
str(data)
## 'data.frame':    105 obs. of  34 variables:
##  $ #                                                                        : num  1 2 3 4 5 6 7 8 9 10 ...
##  $ Grup                                                                     : chr  "SD" "SD" "SD" "SD" ...
##  $ Registro                                                                 : chr  "SD001" "SD004" "SD005" "SD006" ...
##  $ Nombre                                                                   : chr  "Rayli Emmanuel Caballero Gámez" "Ilda Elizabeth Hernandez Monero" "Jose Alberto Camacho Alvarez" "Charbet Valeria Valenzuela Requeña" ...
##  $ Sexo                                                                     : chr  "Másculino" "Femenino" "Másculino" "Femenino" ...
##  $ Edad                                                                     : num  11 4 14 13 16 11 11 4 10 11 ...
##  $ Peso (kg)                                                                : num  32.6 16.4 64.5 72.5 66 27.5 46.5 15 34 31.6 ...
##  $ Talla (M)                                                                : num  1.52 0.949 1.495 1.403 1.444 ...
##  $ Cintura (cm)                                                             : num  62 57.5 93 91.1 91 60.2 74.5 52.5 74.1 64.5 ...
##  $ Cadera (cm)                                                              : num  72.5 58 93.5 110.5 102 ...
##  $ ICC (calculada)                                                          : num  0.855 0.991 0.995 0.824 0.892 ...
##  $ IMC                                                                      : num  14.1 18.2 28.9 36.8 31.7 ...
##  $ HBA1c                                                                    : num  5.2 5.08 6.54 5.7 5.85 5.81 5.58 5.39 5.93 5.59 ...
##  $ Acido Urico (mg/dL)                                                      : num  NA 4.1 7.3 6.3 NA NA NA 5 5 4.8 ...
##  $ Glucosa (mg/dL)                                                          : num  88 72 100 85 98 101 101 90 99 91 ...
##  $ Urea (mg/dL)                                                             : num  26.6 34.3 31.1 28 35.1 36.5 20.4 21.3 41.3 28.3 ...
##  $ Creatinina (mg/dL)                                                       : num  0.6 0.3 0.8 0.8 0.6 0.5 0.5 0.4 0.5 0.4 ...
##  $ Colesterol (mg/dL)                                                       : num  115 153 171 163 134 138 110 135 196 131 ...
##  $ Trigliceridos (mg/dL)                                                    : num  47 79 91 142 72 30 104 54 137 86 ...
##  $ C - HDL (mg/dL)                                                          : num  44 44 76 55 46 72 28 31 52 63 ...
##  $ C -VLDL (mg/dL)                                                          : num  9.4 15.8 18.2 48.4 14.4 6 20.8 10.8 27.4 17.2 ...
##  $ C-LDL (mg/dL)                                                            : num  61.6 93.2 76.8 79.6 73.6 ...
##  $ CG                                                                       : num  278.3 270.8 164.3 99.6 143.5 ...
##  $ 260/230                                                                  : num  1.91 1.83 1.7 1.83 1.8 1.84 1.62 1.26 1.83 1.64 ...
##  $ 260/280                                                                  : num  2 1.51 0.89 1.05 1.1 1.19 1.85 0.84 2.6 1.75 ...
##  $ Genotipo RAGE 625                                                        : chr  "A/A" "A/A" "A/A" "A/A" ...
##  $ Genotipo RAGE 624                                                        : chr  "A/A" "A/A" "A/A" "A/T" ...
##  $ Cuantificacion de AGEs fluorecentes (370nm/455nm)                        : num  204 183 174 249 228 ...
##  $ Cuantificacion de AGEs fluorecentes (485nm/535nm)                        : num  218 178 171 246 218 ...
##  $ Cuantificacion de proteina total                                         : num  0.665 0.595 0.748 0.695 0.789 ...
##  $ cantidad de proteina total ug/mL usando la formula de la recta           : num  1304 1129 1511 1378 1613 ...
##  $ cantidad de proteina total ug/mL usando la formula de la recta entre 1000: num  1.3 1.13 1.51 1.38 1.61 ...
##  $ niveles de AGEs circulantes Final                                        : num  156 162 115 181 142 ...
##  $ Promedio Srage final                                                     : num  1865 2142 1856 1093 888 ...
# Convert the columns to factors
data$`Genotipo RAGE 624` <- as.factor(data$`Genotipo RAGE 624`)
data$`Genotipo RAGE 625` <- as.factor(data$`Genotipo RAGE 625`)
data$Grup <- factor(data$Grup, levels = c("CTRL", "SD"))

# Hay Nas, en los SNP hay que eliminarlos
 #Remove NAs
#data <- na.omit(data)

# Alternatively, if using column indices
# You can also identify the indices of these columns manually if needed:
# For example:
snp_indices <- match(c("Genotipo RAGE 625", "Genotipo RAGE 624"), colnames(data))

# Then use these indices in setupSNP
SNPs <- setupSNP(data, colSNPs = snp_indices, sep = "/")

Visualize SNP summary

plot(SNPs$Genotipo.RAGE.624)

plot(SNPs$Genotipo.RAGE.625)

# You can also change the plot type to pie chart
plot(SNPs$Genotipo.RAGE.624, type = pie)

plot(SNPs$Genotipo.RAGE.625, type = pie)

### Perform association analysis for each SNP

RAGE 624

association(Grup ~ Genotipo.RAGE.624, data = SNPs)
## 
## SNP: Genotipo.RAGE.624  adjusted by: 
##              CTRL    % SD    %   OR lower upper p-value   AIC
## Codominant                                                   
## A/A            28 50.9 27 54.0 1.00              0.9224 151.2
## A/T            23 41.8 19 38.0 0.86  0.38  1.92              
## T/T             4  7.3  4  8.0 1.04  0.24  4.57              
## Dominant                                                     
## A/A            28 50.9 27 54.0 1.00              0.7514 149.2
## A/T-T/T        27 49.1 23 46.0 0.88  0.41  1.90              
## Recessive                                                    
## A/A-A/T        51 92.7 46 92.0 1.00              0.8885 149.3
## T/T             4  7.3  4  8.0 1.11  0.26  4.69              
## Overdominant                                                 
## A/A-T/T        32 58.2 31 62.0 1.00              0.6899 149.2
## A/T            23 41.8 19 38.0 0.85  0.39  1.87              
## log-Additive                                                 
## 0,1,2          55 52.4 50 47.6 0.94  0.51  1.73  0.8482 149.3

RAGE 625

# Perform association analysis for one SNP
association(Grup ~ Genotipo.RAGE.625, data = SNPs)
## 
## SNP: Genotipo.RAGE.625  adjusted by: 
##              CTRL     % SD    %   OR lower upper p-value   AIC
## Codominant                                                    
## A/A            45  81.8 32 64.0 1.00             0.05481 145.2
## A/G            10  18.2 16 32.0 2.25  0.90  5.59              
## G/G             0   0.0  2  4.0       0.00                    
## Dominant                                                      
## A/A            45  81.8 32 64.0 1.00             0.03845 145.0
## A/G-G/G        10  18.2 18 36.0 2.53  1.03  6.20              
## Recessive                                                     
## A/A-A/G        55 100.0 48 96.0 1.00             0.22436 146.3
## G/G             0   0.0  2  4.0       0.00                    
## Overdominant                                                  
## A/A-G/G        45  81.8 34 68.0 1.00             0.10062 146.6
## A/G            10  18.2 16 32.0 2.12  0.85  5.24              
## log-Additive                                                  
## 0,1,2          55  52.4 50 47.6 2.58  1.11  5.99 0.05481 144.1

HWE

summary(SNPs, print=FALSE)
##                   alleles major.allele.freq HWE missing (%)
## Genotipo.RAGE.625 A/G     85.7              1   0          
## Genotipo.RAGE.624 A/T     72.4              1   0

gene-gene interactions

association(Grup ~ dominant(Genotipo.RAGE.625), data = SNPs)
## 
## SNP: dominant(Genotipo.RAGE.625  adjusted by: 
##              CTRL    % SD    %   OR lower upper p-value AIC
## Codominant                                                 
## A/A            45 81.8 32 64.0 1.00             0.03845 145
## A/G-G/G        10 18.2 18 36.0 2.53  1.03   6.2            
## log-Additive                                               
## 0,1,2          55 52.4 50 47.6 2.53  1.03   6.2         145
association(Grup ~ Genotipo.RAGE.625 + Sexo, data = SNPs)
## Warning in terms.formula(formula, data = data): 'varlist' has changed (from
## nvar=2) to new 3 after EncodeVars() -- should no longer happen!
## Warning in terms.formula(formula, data = data): 'varlist' has changed (from
## nvar=2) to new 3 after EncodeVars() -- should no longer happen!
## Warning in terms.formula(formula, data = data): 'varlist' has changed (from
## nvar=2) to new 3 after EncodeVars() -- should no longer happen!
## Warning in terms.formula(formula, data = data): 'varlist' has changed (from
## nvar=2) to new 3 after EncodeVars() -- should no longer happen!
## 
## SNP: Genotipo.RAGE.625  adjusted by: Sexo 
##              CTRL     % SD    %   OR lower upper p-value   AIC
## Codominant                                                    
## A/A            45  81.8 32 64.0 1.00             0.04528 146.9
## A/G            10  18.2 16 32.0 2.27  0.91  5.64              
## G/G             0   0.0  2  4.0       0.00                    
## Dominant                                                      
## A/A            45  81.8 32 64.0 1.00             0.03735 146.7
## A/G-G/G        10  18.2 18 36.0 2.55  1.04  6.26              
## Recessive                                                     
## A/A-A/G        55 100.0 48 96.0 1.00             0.08213 148.0
## G/G             0   0.0  2  4.0       0.00                    
## Overdominant                                                  
## A/A-G/G        45  81.8 34 68.0 1.00             0.09842 148.3
## A/G            10  18.2 16 32.0 2.13  0.86  5.29              
## log-Additive                                                  
## 0,1,2          55  52.4 50 47.6 2.60  1.12  6.04 0.02107 145.7
glimpse(SNPs)
## Rows: 105
## Columns: 34
## $ `#`                                                                         <dbl> …
## $ Grup                                                                        <fct> …
## $ Registro                                                                    <chr> …
## $ Nombre                                                                      <chr> …
## $ Sexo                                                                        <chr> …
## $ Edad                                                                        <dbl> …
## $ `Peso (kg)`                                                                 <dbl> …
## $ `Talla (M)`                                                                 <dbl> …
## $ `Cintura (cm)`                                                              <dbl> …
## $ `Cadera (cm)`                                                               <dbl> …
## $ `ICC (calculada)`                                                           <dbl> …
## $ IMC                                                                         <dbl> …
## $ HBA1c                                                                       <dbl> …
## $ `Acido Urico (mg/dL)`                                                       <dbl> …
## $ `Glucosa (mg/dL)`                                                           <dbl> …
## $ `Urea (mg/dL)`                                                              <dbl> …
## $ `Creatinina (mg/dL)`                                                        <dbl> …
## $ `Colesterol (mg/dL)`                                                        <dbl> …
## $ `Trigliceridos (mg/dL)`                                                     <dbl> …
## $ `C - HDL (mg/dL)`                                                           <dbl> …
## $ `C -VLDL (mg/dL)`                                                           <dbl> …
## $ `C-LDL (mg/dL)`                                                             <dbl> …
## $ CG                                                                          <dbl> …
## $ `260/230`                                                                   <dbl> …
## $ `260/280`                                                                   <dbl> …
## $ `Cuantificacion de AGEs fluorecentes (370nm/455nm)`                         <dbl> …
## $ `Cuantificacion de AGEs fluorecentes (485nm/535nm)`                         <dbl> …
## $ `Cuantificacion de proteina total`                                          <dbl> …
## $ `cantidad de proteina total ug/mL usando la formula de la recta`            <dbl> …
## $ `cantidad de proteina total ug/mL usando la formula de la recta entre 1000` <dbl> …
## $ `niveles de AGEs circulantes Final`                                         <dbl> …
## $ `Promedio Srage final`                                                      <dbl> …
## $ Genotipo.RAGE.625                                                           <fct> …
## $ Genotipo.RAGE.624                                                           <fct> …
association(`niveles de AGEs circulantes Final`  ~ Genotipo.RAGE.624, data = SNPs)
## 
## SNP: Genotipo.RAGE.624  adjusted by: 
##               n     me     se     dif  lower  upper p-value  AIC
## Codominant                                                      
## A/A          55 -257.4  65.76    0.00                0.6345 1622
## A/T          42 -325.4  78.96  -67.96 -282.6 146.70             
## T/T           8 -429.8 315.08 -172.41 -568.8 223.98             
## Dominant                                                        
## A/A          55 -257.4  65.76    0.00                0.4177 1620
## A/T-T/T      50 -342.1  81.74  -84.67 -288.6 119.28             
## Recessive                                                       
## A/A-A/T      97 -286.9  50.44    0.00                0.4674 1620
## T/T           8 -429.8 315.08 -142.98 -527.2 241.20             
## Overdominant                                                    
## A/A-T/T      63 -279.3  69.02    0.00                0.6657 1621
## A/T          42 -325.4  78.96  -46.07 -254.5 162.33             
## log-Additive                                                    
## 0,1,2                          -78.03 -239.0  82.91  0.3442 1620
association(`niveles de AGEs circulantes Final`  ~ Genotipo.RAGE.625, data = SNPs)
## 
## SNP: Genotipo.RAGE.625  adjusted by: 
##                n     me     se     dif  lower  upper p-value  AIC
## Codominant                                                       
## A/A           77 -298.6  46.54   0.000                0.5827 1622
## A/G           26 -324.5 158.91 -25.866 -263.3  211.5             
## G/G            2   83.7  15.29 382.325 -367.3 1132.0             
## Dominant                                                         
## A/A           77 -298.6  46.54   0.000                0.9778 1621
## A/G-G/G       28 -295.3 148.73   3.291 -227.8  234.4             
## Recessive                                                        
## A/A-A/G      103 -305.2  52.63   0.000                0.3079 1620
## G/G            2   83.7  15.29 388.854 -354.9 1132.7             
## Overdominant                                                     
## A/A-G/G       79 -288.9  45.86   0.000                0.7691 1621
## A/G           26 -324.5 158.91 -35.545 -272.2  201.1             
## log-Additive                                                     
## 0,1,2                           32.659 -174.9  240.2  0.7584 1621
# Cargar las librerías necesarias
library(ggplot2)
library(ggpubr)
library(dplyr)

# Crear un tema común para asegurarse de que todos los gráficos tengan el mismo tamaño de ejes
theme_custom1 <- theme_classic2() + labs(x = "Genotipo", y = "Niveles de AGEs circulantes Final") +
  theme(axis.title.x = element_blank(), axis.title.y = element_blank(),
        axis.text = element_text(size = 12), legend.position = "none")


# Supongamos que tus datos están en un dataframe llamado `SNPs`
# Crear una nueva variable para el modelo dominante
SNPsSD <- SNPs %>% filter(Grup == "SD") %>% 
  mutate(Genotipo_Dominante = ifelse(`Genotipo.RAGE.625` == "A/A", "A/A", "A/G-G/G"))

# Definir los colores personalizados
custom_colors <- c("A/A" = "#1f77b4", "A/G-G/G" = "#ff7f0e")

# Crear el boxplot
boxplot_ages <- ggplot(SNPsSD, aes(x = Genotipo_Dominante, y = `niveles de AGEs circulantes Final`, fill = Genotipo_Dominante)) +
  geom_boxplot(outlier.shape = NA) +  # Sin mostrar outliers para mayor claridad
  geom_jitter(width = 0.2, alpha = 0.5) +  # Agregar puntos para cada muestra
  scale_fill_manual(values = custom_colors) +  # Aplicar los colores personalizados
  stat_compare_means(aes(label = ..p.signif..), label.x = 1.5, method = "t.test") +  # Comparación de medias con t-test Etiquetas de los ejes
  theme_custom +  # Aplicar el tema personalizado
  theme(axis.text.x = element_text(size = 12))  # Ajustar tamaño del texto en eje X

# Mostrar el gráfico
print(boxplot_ages)

boxplot_agesprom <- ggplot(SNPsSD, aes(x = Genotipo_Dominante, y = `Promedio Srage final`, fill = Genotipo_Dominante)) +
  geom_boxplot(outlier.shape = NA) +  # Sin mostrar outliers para mayor claridad
  geom_jitter(width = 0.2, alpha = 0.5) +  # Agregar puntos para cada muestra
  scale_fill_manual(values = custom_colors) +  # Aplicar los colores personalizados
  stat_compare_means(aes(label = ..p.signif..), label.x = 1.5, method = "t.test") +  # Comparación de medias con t-tes# Etiquetas de los ejes
  theme_custom +  # Aplicar el tema personalizado
  theme(axis.text.x = element_text(size = 12))+  # Ajustar tamaño del texto en eje X
  labs(x = "Genotipo", y = "Niveles de AGEs promedio")
print(boxplot_agesprom)

plot_grid(boxplot_ages,boxplot_agesprom, labels = c('A', 'B'), label_size = 12, ncol = 2, rel_widths = c(1, 1))

#A=`niveles de AGEs circulantes Final y B=`Promedio Srage final` 
summary_table <- SNPsSD %>%
  select(Genotipo_Dominante,`Promedio Srage final`, `niveles de AGEs circulantes Final`) %>%
  tbl_summary(
    by =Genotipo_Dominante, # Agrupar por la variable dependiente "Sindrome Down"
    missing = "ifany", # Excluye valores faltantes
   statistic = list(
      all_continuous() ~ "{median} ({IQR})"
    )) %>%  # Agregar el IQR a las estadísticas %>% add_overall() %>% 
  add_p() %>% add_overall() %>% 
  modify_header(label = "**Variables**") %>%
  modify_caption("**Tabla: niveles de AGEs circulantes y Niveles de AGEs promedio de pacientes SD polimorfismo RAGE 625**") %>%
  as_gt() %>%
  gt::tab_style(
    style = gt::cell_text(weight = "bold"),
    locations = gt::cells_column_labels()
  )
summary_table
Tabla: niveles de AGEs circulantes y Niveles de AGEs promedio de pacientes SD polimorfismo RAGE 625
Variables Overall
N = 50
1
A/A
N = 32
1
A/G-G/G
N = 18
1
p-value2
Promedio Srage final 830 (540) 867 (412) 717 (594) 0.5
niveles de AGEs circulantes Final 137 (55) 129 (39) 144 (70) 0.4
1 Median (IQR)
2 Wilcoxon rank sum exact test
summary_table <- SNPsSD %>%
  select(Genotipo_Dominante,`Promedio Srage final`, `niveles de AGEs circulantes Final`,`Colesterol (mg/dL)`, `Trigliceridos (mg/dL)`, `C - HDL (mg/dL)`,`C-LDL (mg/dL)`,`C -VLDL (mg/dL)`,HBA1c,`Acido Urico (mg/dL)`, `Glucosa (mg/dL)`, `Urea (mg/dL)`) %>%
  tbl_summary(
    by =Genotipo_Dominante, # Agrupar por la variable dependiente "Sindrome Down"
    missing = "ifany", # Excluye valores faltantes
   statistic = list(
      all_continuous() ~ "{median} ({IQR})"
    )) %>%  # Agregar el IQR a las estadísticas %>% add_overall() %>% 
  add_p() %>% add_overall() %>% 
  modify_header(label = "**Variables**") %>%
  modify_caption("**Tabla: niveles de AGEs circulantes de pacientes con SD polimorfismo RAGE 625**") %>%
  as_gt() %>%
  gt::tab_style(
    style = gt::cell_text(weight = "bold"),
    locations = gt::cells_column_labels()
  )
## The following warnings were returned during `as_gt()`:
## ! For variable `Acido Urico (mg/dL)` (`Genotipo_Dominante`) and "estimate",
##   "statistic", "p.value", "conf.low", and "conf.high" statistics: cannot
##   compute exact p-value with ties
## ! For variable `Acido Urico (mg/dL)` (`Genotipo_Dominante`) and "estimate",
##   "statistic", "p.value", "conf.low", and "conf.high" statistics: cannot
##   compute exact confidence intervals with ties
## ! For variable `C - HDL (mg/dL)` (`Genotipo_Dominante`) and "estimate",
##   "statistic", "p.value", "conf.low", and "conf.high" statistics: cannot
##   compute exact p-value with ties
## ! For variable `C - HDL (mg/dL)` (`Genotipo_Dominante`) and "estimate",
##   "statistic", "p.value", "conf.low", and "conf.high" statistics: cannot
##   compute exact confidence intervals with ties
## ! For variable `C -VLDL (mg/dL)` (`Genotipo_Dominante`) and "estimate",
##   "statistic", "p.value", "conf.low", and "conf.high" statistics: cannot
##   compute exact p-value with ties
## ! For variable `C -VLDL (mg/dL)` (`Genotipo_Dominante`) and "estimate",
##   "statistic", "p.value", "conf.low", and "conf.high" statistics: cannot
##   compute exact confidence intervals with ties
## ! For variable `C-LDL (mg/dL)` (`Genotipo_Dominante`) and "estimate",
##   "statistic", "p.value", "conf.low", and "conf.high" statistics: cannot
##   compute exact p-value with ties
## ! For variable `C-LDL (mg/dL)` (`Genotipo_Dominante`) and "estimate",
##   "statistic", "p.value", "conf.low", and "conf.high" statistics: cannot
##   compute exact confidence intervals with ties
## ! For variable `Colesterol (mg/dL)` (`Genotipo_Dominante`) and "estimate",
##   "statistic", "p.value", "conf.low", and "conf.high" statistics: cannot
##   compute exact p-value with ties
## ! For variable `Colesterol (mg/dL)` (`Genotipo_Dominante`) and "estimate",
##   "statistic", "p.value", "conf.low", and "conf.high" statistics: cannot
##   compute exact confidence intervals with ties
## ! For variable `Glucosa (mg/dL)` (`Genotipo_Dominante`) and "estimate",
##   "statistic", "p.value", "conf.low", and "conf.high" statistics: cannot
##   compute exact p-value with ties
## ! For variable `Glucosa (mg/dL)` (`Genotipo_Dominante`) and "estimate",
##   "statistic", "p.value", "conf.low", and "conf.high" statistics: cannot
##   compute exact confidence intervals with ties
## ! For variable `HBA1c` (`Genotipo_Dominante`) and "estimate", "statistic",
##   "p.value", "conf.low", and "conf.high" statistics: cannot compute exact
##   p-value with ties
## ! For variable `HBA1c` (`Genotipo_Dominante`) and "estimate", "statistic",
##   "p.value", "conf.low", and "conf.high" statistics: cannot compute exact
##   confidence intervals with ties
## ! For variable `Trigliceridos (mg/dL)` (`Genotipo_Dominante`) and "estimate",
##   "statistic", "p.value", "conf.low", and "conf.high" statistics: cannot
##   compute exact p-value with ties
## ! For variable `Trigliceridos (mg/dL)` (`Genotipo_Dominante`) and "estimate",
##   "statistic", "p.value", "conf.low", and "conf.high" statistics: cannot
##   compute exact confidence intervals with ties
## ! For variable `Urea (mg/dL)` (`Genotipo_Dominante`) and "estimate",
##   "statistic", "p.value", "conf.low", and "conf.high" statistics: cannot
##   compute exact p-value with ties
## ! For variable `Urea (mg/dL)` (`Genotipo_Dominante`) and "estimate",
##   "statistic", "p.value", "conf.low", and "conf.high" statistics: cannot
##   compute exact confidence intervals with ties
summary_table
Tabla: niveles de AGEs circulantes de pacientes con SD polimorfismo RAGE 625
Variables Overall
N = 50
1
A/A
N = 32
1
A/G-G/G
N = 18
1
p-value2
Promedio Srage final 830 (540) 867 (412) 717 (594) 0.5
niveles de AGEs circulantes Final 137 (55) 129 (39) 144 (70) 0.4
Colesterol (mg/dL) 154 (44) 150 (38) 172 (52) 0.041
Trigliceridos (mg/dL) 97 (33) 91 (28) 104 (47) 0.2
C - HDL (mg/dL) 45 (16) 43 (11) 53 (15) 0.035
C-LDL (mg/dL) 87 (34) 83 (22) 98 (41) 0.3
C -VLDL (mg/dL) 19 (6) 18 (6) 20 (9) 0.2
HBA1c 5.06 (0.77) 5.20 (0.71) 5.00 (0.65) 0.11
Acido Urico (mg/dL) 5.35 (1.30) 5.00 (1.33) 5.40 (0.82) 0.4
    Unknown 4 3 1
Glucosa (mg/dL) 92 (13) 92 (9) 90 (17) 0.3
Urea (mg/dL) 28 (8) 28 (6) 25 (14) 0.7
1 Median (IQR)
2 Wilcoxon rank sum exact test; Wilcoxon rank sum test
library(gtsummary)
# Convertir los elementos de la variable Genotipo_Dominante en SNPsSD
SNPsSDlr <- SNPsSD %>%
  mutate(Genotipo_Dominante = recode(Genotipo_Dominante, "A/A" = 0, "A/G-G/G" = 1))


# build logistic regression model



m1 <- glm(Genotipo_Dominante ~ Sexo+Edad+IMC+`Colesterol (mg/dL)`++`C - HDL (mg/dL)`+`niveles de AGEs circulantes Final` +`Promedio Srage final`, data=SNPsSDlr, family = binomial)
print(m1)
## 
## Call:  glm(formula = Genotipo_Dominante ~ Sexo + Edad + IMC + `Colesterol (mg/dL)` + 
##     +`C - HDL (mg/dL)` + `niveles de AGEs circulantes Final` + 
##     `Promedio Srage final`, family = binomial, data = SNPsSDlr)
## 
## Coefficients:
##                         (Intercept)                        SexoMásculino  
##                           -7.193459                            -0.478843  
##                                Edad                                  IMC  
##                           -0.069513                            -0.075266  
##                `Colesterol (mg/dL)`                    `C - HDL (mg/dL)`  
##                            0.025504                             0.047231  
## `niveles de AGEs circulantes Final`               `Promedio Srage final`  
##                            0.021243                            -0.000341  
## 
## Degrees of Freedom: 49 Total (i.e. Null);  42 Residual
## Null Deviance:       65.34 
## Residual Deviance: 51.48     AIC: 67.48
# view raw model results
summary(m1)$coefficients
##                                          Estimate  Std. Error    z value
## (Intercept)                         -7.1934593977 3.545547495 -2.0288713
## SexoMásculino                       -0.4788431071 0.741335229 -0.6459198
## Edad                                -0.0695131092 0.125331829 -0.5546325
## IMC                                 -0.0752663171 0.098813889 -0.7616977
## `Colesterol (mg/dL)`                 0.0255041111 0.014128927  1.8050989
## `C - HDL (mg/dL)`                    0.0472305196 0.028061855  1.6830862
## `niveles de AGEs circulantes Final`  0.0212425048 0.010771320  1.9721356
## `Promedio Srage final`              -0.0003410134 0.000831004 -0.4103631
##                                       Pr(>|z|)
## (Intercept)                         0.04247141
## SexoMásculino                       0.51833129
## Edad                                0.57914604
## IMC                                 0.44624042
## `Colesterol (mg/dL)`                0.07105921
## `C - HDL (mg/dL)`                   0.09235841
## `niveles de AGEs circulantes Final` 0.04859413
## `Promedio Srage final`              0.68153959
tbl_regression(m1, exponentiate = TRUE)
Characteristic OR1 95% CI1 p-value
Sexo


    Femenino
    Másculino 0.62 0.14, 2.63 0.5
Edad 0.93 0.71, 1.18 0.6
IMC 0.93 0.75, 1.12 0.4
Colesterol (mg/dL) 1.03 1.00, 1.06 0.071
C - HDL (mg/dL) 1.05 0.99, 1.11 0.092
niveles de AGEs circulantes Final 1.02 1.00, 1.05 0.049
Promedio Srage final 1.00 1.00, 1.00 0.7
1 OR = Odds Ratio, CI = Confidence Interval
# Cargar las librerías necesarias
library(pROC)
## Type 'citation("pROC")' for a citation.
## 
## Attaching package: 'pROC'
## The following objects are masked from 'package:stats':
## 
##     cov, smooth, var
library(dplyr)
library(ggplot2)

# Asumiendo que SNPsSD es tu dataframe y que tienes una variable "outcome" que es el resultado a predecir (0 o 1)
# Aquí "outcome" debería ser tu variable dependiente o de respuesta.

# Crear el objeto ROC
roc_obj <- roc(SNPsSDlr$Genotipo_Dominante, SNPsSDlr$`niveles de AGEs circulantes Final`)
## Setting levels: control = 0, case = 1
## Setting direction: controls < cases
# Calcular el punto de corte óptimo usando el índice de Youden
optimal_cutoff <- coords(roc_obj, "best", ret = "threshold", best.method = "youden")

# Calcular el AUC, IC 95%, sensibilidad y especificidad
auc_value <- auc(roc_obj)
ci_auc <- ci.auc(roc_obj)

# Usar coords para extraer la sensibilidad y especificidad en el punto de corte óptimo
optimal_coords <- coords(roc_obj, x = "best", best.method = "youden", ret = c("sensitivity", "specificity"))

sensitivity <- optimal_coords[1]
specificity <- optimal_coords[2]

# Crear la curva ROC con ajustes en la posición de las anotaciones
roc_plot <- ggroc(roc_obj) +
  geom_abline(slope = 1, intercept = 1, linetype = "dashed", color = "gray") +
  theme_minimal() +
  
  ggtitle("Curva ROC para Genotipo mutante A/G G/G ") +
  xlab("1 - Especificidad") +
  ylab("Sensibilidad") 

# Mostrar la curva ROC
print(roc_plot)