Cargue base de datos

library(readxl)
BASE <- read_excel("Base de datos completas Ingles PIDOT TAR 09.02.26 COMPLETA LB-T-MONOS.xlsx")

Exploración básica base de datos

library(dlookr)
library(DT)
library(janitor)
library(dplyr)

diagnose(BASE) %>% 
  mutate(across(where(is.numeric), ~round(., 1))) %>% #redondear a 1
  datatable(options = list(pageLength = 25))

Selección de variables de interés (dado que había repetidas se hizo un primer análisis con todas las variables)

BASEprof <- BASE %>% select(`1_Code`, `10_Total Lymphocytes Cell/μL`,`11_BL Cell/μL`, `8_MON Cell/μL`, `12_Naive BL Cell/μL`, `13_USMBCs Cell/μL`, `14_SMBCs Cell/μL`, `92_Linf_B_Memory_IgM_ABS_Analysis`, `94_Linf_B_Memory_IgA1_ABS_Analysis`, `95_Linf_B_Memory_IgA2_ABS_Analysis`, `96_Linf_B_Memory_IgG1_ABS_Analysis`, `97_Linf_B_Memory_IgG2_ABS_Analysis`, `98_Linf_B_Memory_IgG3_ABS_Analysis`, `99_Linf_B_Memory_IgG4_ABS_Analysis`, `6_EOS Cell/μL`, `7_NEUT Cell/μL`, `9_BASO Cell/μL`, `15_TL ABS Cell/μL`, `85_Intermediate monocytes Cell/μL`, `83_Classical monocytes Cell/μL`, `17_TLH Cell/μL`, `18_TLC Cell/μL`, `23_TLH CM Cell/μL`, `24_TLH EM Cell/μL`, `25_TLH TD Cell/μL`) #24 variables

#se eliminan variables con datos perdidos 

PROFILES <- BASEprof%>% 
  filter(if_all(2:25, ~ !is.na(.)))

#sapply(PROFILES, class) todas son de tipo numérico 

library(mclust)
library(factoextra)
p1<-Mclust(PROFILES[,2:25])
summary(p1) # 3 PERFILES 
## ---------------------------------------------------- 
## Gaussian finite mixture model fitted by EM algorithm 
## ---------------------------------------------------- 
## 
## Mclust VVE (ellipsoidal, equal orientation) model with 3 components: 
## 
##  log-likelihood   n  df       BIC       ICL
##       -34154.18 302 422 -70718.15 -70727.58
## 
## Clustering table:
##   1   2   3 
## 114  39 149

Graficando la solución

model <- Mclust(PROFILES[,2:25], modelNames = "VVE", G = 3)

library(tibble)
library(tidyr)
library(dplyr)

means_prof <- data.frame(model$parameters$mean) %>%
  rownames_to_column() %>%
  rename(PROFILES = rowname) %>%
  pivot_longer(cols = c(X1, X2, X3), names_to = "Profile", values_to = "Mean") %>%
  mutate(
    Mean = round(Mean, 2),
    Mean_z = as.numeric(scale(Mean))
  )

p_model <- means_prof %>%
  mutate(Profile = recode(Profile, 
                          X1 = "Prof 1 (114)",
                          X2 = "Prof 2 (39)", 
                          X3 = "Prof 3 (149)")) %>%
  ggplot(aes(PROFILES, Mean_z, group = Profile, color = Profile)) +
  geom_point(size = 2.25) +
  geom_line(size = 1.25) +
  scale_x_discrete(limits = c("10_Total Lymphocytes Cell/μL", "11_BL Cell/μL", "8_MON Cell/μL", "12_Naive BL Cell/μL", "13_USMBCs Cell/μL", "14_SMBCs Cell/μL", "92_Linf_B_Memory_IgM_ABS_Analysis", "94_Linf_B_Memory_IgA1_ABS_Analysis", "95_Linf_B_Memory_IgA2_ABS_Analysis", "96_Linf_B_Memory_IgG1_ABS_Analysis", "97_Linf_B_Memory_IgG2_ABS_Analysis", "98_Linf_B_Memory_IgG3_ABS_Analysis", "99_Linf_B_Memory_IgG4_ABS_Analysis", "6_EOS Cell/μL", "7_NEUT Cell/μL", "9_BASO Cell/μL", "15_TL ABS Cell/μL", "85_Intermediate monocytes Cell/μL", "83_Classical monocytes Cell/μL", "17_TLH Cell/μL", "18_TLC Cell/μL", "23_TLH CM Cell/μL", "24_TLH EM Cell/μL", "25_TLH TD Cell/μL" )) +
  labs(x = "variables", y = "media estandarizada", title = "Perfiles") +
  theme_bw(base_size = 14) +
  theme(
    axis.text.x = element_text(angle = 90, hjust = 1, size = 10, face = "bold"),   # Letras eje X más grandes y en negrita
    axis.text.y = element_text(size = 14, face = "bold"),                         # Letras eje Y más grandes y en negrita
    axis.title.x = element_text(size = 16, face = "bold"),                       # Aumentar tamaño de la etiqueta del eje X
    axis.title.y = element_text(size = 16, face = "bold"),                       # Aumentar tamaño de la etiqueta del eje Y
    legend.position = "right", 
    legend.text = element_text(size = 10, face = "bold"),                        # Aumentar el tamaño de la leyenda y ponerla en negrita
    legend.title = element_text(size = 16, face = "bold")                       # Aumentar tamaño del título de la leyenda
  )
p_model