library(readxl)
Base_de_datos_ampliada <- read_excel("C:/Users/Administrador/Downloads/Base de datos _ampliada.xlsx")
View(Base_de_datos_ampliada)
datos=Base_de_datos_ampliada
#transformar en factor
#datos <- datos %>%
#  mutate(across(c(sexo, apetito, per_peso, movi, enf_ag, neuro, imc_cat, vive_ind, polim, ulceras, #comidas, lacteos, frutas, agua, forma, bien_nutrido, cir_panto, estado_nutricional_crib_eval, alta_obito, #clasi_dina, estado_nutricional_crib_eval),as.factor))
#puntaje según estado nutricional de las variables
library(dplyr)
library(tidyr)


datos$estado_nutricional_crib_eval<-as.factor(datos$estado_nutricional_crib_eval)

library(purrr)

# Variables a analizar
variables_1 <- c(
  "per_peso", "movi", "enf_ag", "apetito", "neuro",
  "imc_cat", "vive_ind", "polim", "ulceras", "comidas",
  "lacteos", "frutas", "agua", "forma", "bien_nutrido",
  "estado_salud", "cir_braquial", "cir_panto"
)

# ---------------------------------------------------------
# 1. Mediana y RIC para cada grupo nutricional
# ---------------------------------------------------------

tabla_mediana <- Base_de_datos_ampliada %>%
  dplyr::select(
    estado_nutricional_crib_eval,
    dplyr::all_of(variables_1)
  ) %>%
  tidyr::pivot_longer(
    cols = dplyr::all_of(variables_1),
    names_to = "Variable",
    values_to = "valor"
  ) %>%
  dplyr::group_by(Variable, estado_nutricional_crib_eval) %>%
  dplyr::summarise(
    mediana = median(valor, na.rm = TRUE),
    p25 = quantile(valor, 0.25, na.rm = TRUE),
    p75 = quantile(valor, 0.75, na.rm = TRUE),
    .groups = "drop"
  ) %>%
  dplyr::mutate(
    mediana_RIC = sprintf(
      "%.1f [%.1f–%.1f]",
      mediana, p25, p75
    )
  ) %>%
  dplyr::select(
    Variable,
    estado_nutricional_crib_eval,
    mediana_RIC
  ) %>%
  tidyr::pivot_wider(
    names_from = estado_nutricional_crib_eval,
    values_from = mediana_RIC
  )

View(tabla_mediana)
knitr::kable(
  tabla_mediana,
  digits = 2,
  caption = "Mediana de puntajes"
)
Mediana de puntajes
Variable MALNUTRICION NORMAL RIESGO
agua 0.5 [0.4–1.0] 1.0 [0.5–1.0] 1.0 [0.5–1.0]
apetito 0.0 [0.0–0.0] 2.0 [2.0–2.0] 1.0 [0.0–1.2]
bien_nutrido 1.0 [0.0–1.0] 2.0 [1.0–2.0] 1.5 [1.0–2.0]
cir_braquial 1.0 [0.4–1.0] 1.0 [1.0–1.0] 1.0 [1.0–1.0]
cir_panto 0.0 [0.0–1.0] 1.0 [1.0–1.0] 1.0 [1.0–1.0]
comidas 2.0 [0.0–2.0] 2.0 [2.0–2.0] 2.0 [2.0–2.0]
enf_ag 0.0 [0.0–2.0] 2.0 [2.0–2.0] 2.0 [0.0–2.0]
estado_salud 0.5 [0.0–1.0] 2.0 [1.0–2.0] 1.0 [0.5–2.0]
forma 2.0 [0.8–2.0] 2.0 [2.0–2.0] 2.0 [2.0–2.0]
frutas 0.0 [0.0–1.0] 1.0 [0.0–1.0] 1.0 [0.0–1.0]
imc_cat 1.5 [0.0–3.0] 3.0 [3.0–3.0] 3.0 [3.0–3.0]
lacteos 0.5 [0.0–0.5] 0.5 [0.5–1.0] 0.5 [0.0–1.0]
movi 0.0 [0.0–1.0] 2.0 [2.0–2.0] 1.5 [1.0–2.0]
neuro 2.0 [1.8–2.0] 2.0 [2.0–2.0] 2.0 [2.0–2.0]
per_peso 0.0 [0.0–0.0] 3.0 [2.0–3.0] 0.0 [0.0–2.0]
polim 0.0 [0.0–0.0] 1.0 [0.0–1.0] 0.5 [0.0–1.0]
ulceras 1.0 [0.0–1.0] 1.0 [1.0–1.0] 1.0 [1.0–1.0]
vive_ind 0.0 [0.0–0.2] 1.0 [1.0–1.0] 1.0 [0.0–1.0]
# ---------------------------------------------------------
# 2. Kruskal-Wallis para cada variable
# ---------------------------------------------------------


resultados_kw <- purrr::map_dfr(
  variables_1,
  function(v) {
    
    datos_temp <- datos %>%
      dplyr::select(
        estado_nutricional_crib_eval,
        dplyr::all_of(v)
      ) %>%
      dplyr::filter(
        !is.na(estado_nutricional_crib_eval),
        !is.na(.data[[v]])
      )
    
    prueba <- kruskal.test(
      datos_temp[[v]],
      g = datos_temp$estado_nutricional_crib_eval
    )
    
    tibble(
      Variable = v,
      p_KW = prueba$p.value
    )
  }
)
# ---------------------------------------------------------
# 3. Corrección de Holm
# ---------------------------------------------------------

resultados_kw <- resultados_kw %>%
  mutate(
    p_Holm = p.adjust(p_KW, method = "holm")
  )

# ---------------------------------------------------------
# 4. Unir resultados
# ---------------------------------------------------------

tabla_final <- tabla_mediana %>%
  dplyr::left_join(
    resultados_kw,
    by = "Variable"
  ) %>%
  dplyr::mutate(
    p_KW = sprintf("%.4f", p_KW),
    p_Holm = sprintf("%.4f", p_Holm)
  ) %>%
  dplyr::select(
    Variable,
    MALNUTRICION,
    NORMAL,
    RIESGO,
    p_KW,
    p_Holm
  )

View(tabla_final)
library(dplyr)
library(tidyr)
library(ggplot2)

datos_grafico <- datos %>%
  dplyr::select(
    estado_nutricional_crib_eval,
    dplyr::all_of(variables_1)
  ) %>%
  tidyr::pivot_longer(
    cols = dplyr::all_of(variables_1),
    names_to = "Variable",
    values_to = "Valor"
  )
datos_grafico$estado_nutricional_crib_eval <- factor(
  datos_grafico$estado_nutricional_crib_eval,
  levels = c("MALNUTRICION", "RIESGO", "NORMAL")
)
levels(factor(Base_de_datos_ampliada$estado_nutricional_crib_eval))
## [1] "MALNUTRICION" "NORMAL"       "RIESGO"
ggplot(
  datos_grafico,
  aes(
    x = estado_nutricional_crib_eval,
    y = Valor,
    fill = estado_nutricional_crib_eval
  )
) +
  geom_boxplot(
    width = 0.65,
    alpha = 0.75,
    outlier.alpha = 0.4
  ) +
  facet_wrap(
    ~ Variable,
    scales = "free_y",
    ncol = 3
  ) +
  labs(
    title = "Variables según estado nutricional",
    subtitle = "Distribución según la clasificación nutricional",
    x = NULL,
    y = NULL
  ) +
  theme_classic(base_size = 12) +
  theme(
    legend.position = "none",
    axis.text.x = element_text(
      angle = 45,
      hjust = 1
    ),
    strip.text = element_text(
      face = "bold"
    ),
    plot.title = element_text(
      face = "bold"
    )
  )

table(Base_de_datos_ampliada$estado_nutricional_crib_eval, useNA = "ifany")
## 
## MALNUTRICION       NORMAL       RIESGO 
##           24           37           40
#GRÁFICOS POR SEPARADO
grupo1 <- c(
  "agua",
  "apetito",
  "bien_nutrido",
  "cir_braquial",
  "cir_panto",
  "comidas"
)

grupo2 <- c(
  "enf_ag",
  "estado_salud",
  "forma",
  "frutas",
  "imc_cat",
  "lacteos"
)

grupo3 <- c(
  "movi",
  "neuro",
  "per_peso",
  "polim",
  "ulceras",
  "vive_ind"
)
#GRAFICO 1
grafico1 <- datos_grafico %>%
  filter(Variable %in% grupo1) %>%
  mutate(
    Variable = factor(Variable, levels = grupo1)
  ) %>%
  ggplot(
    aes(
      x = estado_nutricional_crib_eval,
      y = Valor,
      fill = estado_nutricional_crib_eval
    )
  ) +
  geom_boxplot(
    width = 0.65,
    alpha = 0.75
  ) +
  facet_wrap(
    ~ Variable,
    scales = "free_y",
    ncol = 3
  ) +
  labs(
    title = "Variables según estado nutricional",
    subtitle = "Distribución según la clasificación nutricional",
    x = NULL,
    y = NULL
  ) +
  theme_classic(base_size = 13) +
  theme(
    legend.position = "none",
    axis.text.x = element_text(
      angle = 40,
      hjust = 1,
      size = 10
    ),
    strip.text = element_text(
      face = "bold",
      size = 11
    ),
    plot.title = element_text(
      face = "bold",
      size = 16
    )
  )

grafico1

#GRAFICO 2
grafico2 <- datos_grafico %>%
  filter(Variable %in% grupo2) %>%
  mutate(
    Variable = factor(Variable, levels = grupo2)
  ) %>%
  ggplot(
    aes(
      x = estado_nutricional_crib_eval,
      y = Valor,
      fill = estado_nutricional_crib_eval
    )
  ) +
  geom_boxplot(
    width = 0.65,
    alpha = 0.75
  ) +
  facet_wrap(
    ~ Variable,
    scales = "free_y",
    ncol = 3
  ) +
  labs(
    title = "Variables según estado nutricional",
    subtitle = "Distribución según la clasificación nutricional",
    x = NULL,
    y = NULL
  ) +
  theme_classic(base_size = 13) +
  theme(
    legend.position = "none",
    axis.text.x = element_text(
      angle = 40,
      hjust = 1,
      size = 10
    ),
    strip.text = element_text(
      face = "bold",
      size = 11
    ),
    plot.title = element_text(
      face = "bold",
      size = 16
    )
  )

grafico2

#GRAFICO 3
grafico3 <- datos_grafico %>%
  filter(Variable %in% grupo3) %>%
  mutate(
    Variable = factor(Variable, levels = grupo3)
  ) %>%
  ggplot(
    aes(
      x = estado_nutricional_crib_eval,
      y = Valor,
      fill = estado_nutricional_crib_eval
    )
  ) +
  geom_boxplot(
    width = 0.65,
    alpha = 0.75
  ) +
  facet_wrap(
    ~ Variable,
    scales = "free_y",
    ncol = 3
  ) +
  labs(
    title = "Variables según estado nutricional",
    subtitle = "Distribución según la clasificación nutricional",
    x = NULL,
    y = NULL
  ) +
  theme_classic(base_size = 13) +
  theme(
    legend.position = "none",
    axis.text.x = element_text(
      angle = 40,
      hjust = 1,
      size = 10
    ),
    strip.text = element_text(
      face = "bold",
      size = 11
    ),
    plot.title = element_text(
      face = "bold",
      size = 16
    )
  )

grafico3

#correlación
cor.test(
  datos$punt_panto,
  datos$dinamom_kg,
  method = "spearman",
  use = "complete.obs",
  exact = FALSE
)
## 
##  Spearman's rank correlation rho
## 
## data:  datos$punt_panto and datos$dinamom_kg
## S = 104891, p-value = 0.00006
## alternative hypothesis: true rho is not equal to 0
## sample estimates:
##   rho 
## 0.389
cor.test(
  datos$punt_panto,
  datos$dinamom_kg,
  method = "pearson",
  use = "complete.obs"
)
## 
##  Pearson's product-moment correlation
## 
## data:  datos$punt_panto and datos$dinamom_kg
## t = 4, df = 99, p-value = 0.00008
## alternative hypothesis: true correlation is not equal to 0
## 95 percent confidence interval:
##  0.202 0.538
## sample estimates:
##   cor 
## 0.383
library(dplyr)
library(ggplot2)
datos_cor <- datos %>%
  dplyr::select(punt_panto, dinamom_kg) %>%
  dplyr::filter(
    !is.na(punt_panto),
    !is.na(dinamom_kg)
  )

cor_spearman <- cor.test(
  datos_cor$punt_panto,
  datos_cor$dinamom_kg,
  method = "spearman",
  exact = FALSE
)

rho <- cor_spearman$estimate
p <- cor_spearman$p.value

etiqueta <- paste0(
  "\u03c1 = ", round(rho, 2),
  "\n",
  "p ", ifelse(p < 0.001, "< 0.001", paste0("= ", round(p, 3)))
)

#corrige por edad
library(ppcor)
## Warning: package 'ppcor' was built under R version 4.4.3
datos_parcial <- datos %>%
  dplyr::select(
    punt_panto,
    dinamom_kg,
    edad
  ) %>%
  tidyr::drop_na()

ppcor::pcor.test(
  x = datos_parcial$punt_panto,
  y = datos_parcial$dinamom_kg,
  z = datos_parcial$edad,
  method = "spearman"
)
##   estimate  p.value statistic   n gp   Method
## 1    0.354 0.000303      3.75 101  1 spearman
ggplot(datos_cor, aes(x = punt_panto, y = dinamom_kg)) +
  geom_point(size = 3, alpha = 0.7) +
  
  annotate(
    "text",
    x = Inf,
    y = Inf,
    label = etiqueta,
    hjust = 1.2,
    vjust = 1.5,
    size = 5
  ) +
  
  labs(
    x = "Puntaje de pantorrilla",
    y = "Dinamometría (kg)",
    title = "Correlación entre puntaje de pantorrilla y dinamometría"
  ) +
  
  theme_classic(base_size = 14) +
  theme(
    plot.title = element_text(face = "bold", hjust = 0.5),
    axis.title = element_text(face = "bold")
  )

#ajustando por la edad
library(lmtest)
## Warning: package 'lmtest' was built under R version 4.4.3
## Cargando paquete requerido: zoo
## 
## Adjuntando el paquete: 'zoo'
## The following objects are masked from 'package:data.table':
## 
##     yearmon, yearqtr
## The following objects are masked from 'package:base':
## 
##     as.Date, as.Date.numeric
## 
## Adjuntando el paquete: 'lmtest'
## The following object is masked from 'package:rms':
## 
##     lrtest
mod0<-lm(dinamom_kg ~ punt_panto , data=datos)
summary(mod0)
## 
## Call:
## lm(formula = dinamom_kg ~ punt_panto, data = datos)
## 
## Residuals:
##    Min     1Q Median     3Q    Max 
## -22.24  -6.97  -1.24   6.87  25.27 
## 
## Coefficients:
##             Estimate Std. Error t value Pr(>|t|)    
## (Intercept)   -4.037      6.289   -0.64     0.52    
## punt_panto     0.757      0.184    4.12 0.000079 ***
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 9.6 on 99 degrees of freedom
## Multiple R-squared:  0.146,  Adjusted R-squared:  0.138 
## F-statistic:   17 on 1 and 99 DF,  p-value: 0.0000789
confint(mod0)
##               2.5 % 97.5 %
## (Intercept) -16.516   8.44
## punt_panto    0.392   1.12
mod1<-lm(dinamom_kg ~ punt_panto + edad, data=datos)
summary(mod1)
## 
## Call:
## lm(formula = dinamom_kg ~ punt_panto + edad, data = datos)
## 
## Residuals:
##    Min     1Q Median     3Q    Max 
## -23.56  -6.89  -1.40   6.20  24.95 
## 
## Coefficients:
##             Estimate Std. Error t value Pr(>|t|)    
## (Intercept)   15.150     13.064    1.16  0.24901    
## punt_panto     0.665      0.190    3.49  0.00072 ***
## edad          -0.236      0.141   -1.67  0.09788 .  
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 9.51 on 98 degrees of freedom
## Multiple R-squared:  0.17,   Adjusted R-squared:  0.153 
## F-statistic:   10 on 2 and 98 DF,  p-value: 0.000108
confint(mod1)
##               2.5 %  97.5 %
## (Intercept) -10.776 41.0757
## punt_panto    0.287  1.0422
## edad         -0.517  0.0443
anova(mod0,mod1)
## Analysis of Variance Table
## 
## Model 1: dinamom_kg ~ punt_panto
## Model 2: dinamom_kg ~ punt_panto + edad
##   Res.Df  RSS Df Sum of Sq    F Pr(>F)  
## 1     99 9118                           
## 2     98 8865  1       253 2.79  0.098 .
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
tab_model(mod1)
  dinamom_kg
Predictors Estimates CI p
(Intercept) 15.15 -10.78 – 41.08 0.249
punt panto 0.66 0.29 – 1.04 0.001
edad -0.24 -0.52 – 0.04 0.098
Observations 101
R2 / R2 adjusted 0.170 / 0.153
#supuestos del modelo
#homocedasticidad no se cumple
#linealidad no se cumple
#
predichos <- fitted.values(mod0)
standres <-rstandard(mod0)
res <- residuals(mod0)

plot(y=datos$punt_panto, x= datos$dinamom_kg)
abline(h=0, lty = 2)

#homocesdasticidad no se cumple
plot(
  x = mod0$fitted.values,
  y = mod0$residuals,
  xlab = "Valores predichos",
  ylab = "Residuos",
  main = "Residuos vs valores predichos"
)
abline(h = 0, lty = 2)

bptest(datos$punt_panto ~ datos$dinamom_kg, data=datos)
## 
##  studentized Breusch-Pagan test
## 
## data:  datos$punt_panto ~ datos$dinamom_kg
## BP = 5, df = 1, p-value = 0.03
#normalidad se cumple
library(car)
## Cargando paquete requerido: carData
## 
## Adjuntando el paquete: 'carData'
## The following object is masked from 'package:vcdExtra':
## 
##     Burt
## 
## Adjuntando el paquete: 'car'
## The following object is masked from 'package:psych':
## 
##     logit
## The following objects are masked from 'package:rms':
## 
##     Predict, vif
## The following object is masked from 'package:dplyr':
## 
##     recode
## The following object is masked from 'package:purrr':
## 
##     some
densityPlot(mod0$residuals)

hist(mod1$residuals)

boxplot(mod0$residuals)

qqPlot(standres) #se utilizan residuos estandarizados

## [1] 38 58
describe(mod0$residuals)
##    vars   n mean   sd median trimmed  mad   min  max range skew kurtosis   se
## X1    1 101    0 9.55  -1.24   -0.41 9.69 -22.2 25.3  47.5 0.33    -0.35 0.95
shapiro.test(mod0$residuals)
## 
##  Shapiro-Wilk normality test
## 
## data:  mod0$residuals
## W = 1, p-value = 0.3
#spearman controlando por la edad
install.packages("ppcor")  # solo la primera vez
## Warning: package 'ppcor' is in use and will not be installed
library(ppcor)
datos_parcial <- datos %>%
  dplyr::select(punt_panto, dinamom_kg, edad) %>%
  tidyr::drop_na()

ppcor::pcor.test(
  x = datos_parcial$punt_panto,
  y = datos_parcial$dinamom_kg,
  z = datos_parcial$edad,
  method = "spearman"
)
##   estimate  p.value statistic   n gp   Method
## 1    0.354 0.000303      3.75 101  1 spearman
#tabla 1
#transformar en factor
Base_de_datos_ampliada$estado_nutricional_crib_eval <- factor(
  Base_de_datos_ampliada$estado_nutricional_crib_eval,
  levels = c("MALNUTRICION", "RIESGO", "NORMAL")
)
psych::describeBy(
  imc ~ estado_nutricional_crib_eval,
  data = Base_de_datos_ampliada
)
## 
##  Descriptive statistics by group 
## estado_nutricional_crib_eval: MALNUTRICION
##     vars  n mean   sd median trimmed  mad  min  max range skew kurtosis   se
## imc    1 24 22.5 7.14   21.2    21.3 5.62 15.6 47.5  31.8 1.86     3.76 1.46
## ------------------------------------------------------------ 
## estado_nutricional_crib_eval: RIESGO
##     vars  n mean   sd median trimmed  mad  min  max range skew kurtosis   se
## imc    1 40   29 7.46   27.5    27.9 4.73 19.4 64.9  45.5 2.79     10.9 1.18
## ------------------------------------------------------------ 
## estado_nutricional_crib_eval: NORMAL
##     vars  n mean   sd median trimmed  mad  min  max range skew kurtosis   se
## imc    1 37 28.3 4.44   27.5    28.1 4.45 19.5 38.1  18.5 0.36    -0.53 0.73
Base_de_datos_ampliada <- Base_de_datos_ampliada %>%
mutate(across(c(sexo,imc_cat, cir_panto, estado_nutricional_crib_eval, alta_obito, clasi_dina, cir_panto),as.factor))

catvars = c( "sexo","imc_cat", "alta_obito", "clasi_dina", "cir_panto")
vars = c("sexo", "cir_panto", "imc_cat", "alta_obito", "clasi_dina","edad","imc","punt_panto", "punt_braquial")

tabla_1 <- CreateTableOne(
  vars = vars,
  strata = "estado_nutricional_crib_eval",
  factorVars = catvars,
  data = Base_de_datos_ampliada,
  addOverall = TRUE
)
print(tabla_1, nonnormal = c("punt_panto", "punt_braquial", "imc"))
##                               Stratified by estado_nutricional_crib_eval
##                                Overall              MALNUTRICION        
##   n                              101                   24               
##   sexo = 2 (%)                    66 (65.3)            15 (62.5)        
##   cir_panto = 1 (%)               78 (77.2)            11 (45.8)        
##   imc_cat (%)                                                           
##      0                            10 ( 9.9)            10 (41.7)        
##      1                             5 ( 5.0)             2 ( 8.3)        
##      2                             8 ( 7.9)             3 (12.5)        
##      3                            78 (77.2)             9 (37.5)        
##   alta_obito = 1 (%)              10 ( 9.9)             5 (20.8)        
##   clasi_dina = NORMAL (%)         43 (42.6)             3 (12.5)        
##   edad (mean (SD))             68.02 (7.03)         71.04 (9.05)        
##   imc (median [IQR])           26.43 [23.45, 30.86] 21.24 [17.51, 24.67]
##   punt_panto (median [IQR])    34.00 [31.00, 38.00] 29.50 [26.38, 31.62]
##   punt_braquial (median [IQR]) 29.00 [25.00, 31.00] 23.75 [20.88, 25.88]
##                               Stratified by estado_nutricional_crib_eval
##                                RIESGO               NORMAL               p     
##   n                               40                   37                      
##   sexo = 2 (%)                    25 (62.5)            26 (70.3)          0.732
##   cir_panto = 1 (%)               32 (80.0)            35 (94.6)         <0.001
##   imc_cat (%)                                                            <0.001
##      0                             0 ( 0.0)             0 ( 0.0)               
##      1                             2 ( 5.0)             1 ( 2.7)               
##      2                             3 ( 7.5)             2 ( 5.4)               
##      3                            35 (87.5)            34 (91.9)               
##   alta_obito = 1 (%)               5 (12.5)             0 ( 0.0)          0.023
##   clasi_dina = NORMAL (%)         17 (42.5)            23 (62.2)          0.001
##   edad (mean (SD))             68.20 (6.36)         65.86 (5.50)          0.017
##   imc (median [IQR])           27.52 [24.63, 31.12] 27.48 [24.97, 31.19] <0.001
##   punt_panto (median [IQR])    34.00 [32.40, 36.88] 36.00 [34.00, 38.50] <0.001
##   punt_braquial (median [IQR]) 29.00 [26.75, 30.12] 30.00 [27.00, 32.90] <0.001
##                               Stratified by estado_nutricional_crib_eval
##                                test   
##   n                                   
##   sexo = 2 (%)                        
##   cir_panto = 1 (%)                   
##   imc_cat (%)                         
##      0                                
##      1                                
##      2                                
##      3                                
##   alta_obito = 1 (%)                  
##   clasi_dina = NORMAL (%)             
##   edad (mean (SD))                    
##   imc (median [IQR])           nonnorm
##   punt_panto (median [IQR])    nonnorm
##   punt_braquial (median [IQR]) nonnorm
kableone(tabla_1, nonnormal = c("punt_panto", "punt_braquial", "imc")) #se visualiza mejor
Overall MALNUTRICION RIESGO NORMAL p test
n 101 24 40 37
sexo = 2 (%) 66 (65.3) 15 (62.5) 25 (62.5) 26 (70.3) 0.732
cir_panto = 1 (%) 78 (77.2) 11 (45.8) 32 (80.0) 35 (94.6) <0.001
imc_cat (%) <0.001
0 10 ( 9.9) 10 (41.7) 0 ( 0.0) 0 ( 0.0)
1 5 ( 5.0) 2 ( 8.3) 2 ( 5.0) 1 ( 2.7)
2 8 ( 7.9) 3 (12.5) 3 ( 7.5) 2 ( 5.4)
3 78 (77.2) 9 (37.5) 35 (87.5) 34 (91.9)
alta_obito = 1 (%) 10 ( 9.9) 5 (20.8) 5 (12.5) 0 ( 0.0) 0.023
clasi_dina = NORMAL (%) 43 (42.6) 3 (12.5) 17 (42.5) 23 (62.2) 0.001
edad (mean (SD)) 68.02 (7.03) 71.04 (9.05) 68.20 (6.36) 65.86 (5.50) 0.017
imc (median [IQR]) 26.43 [23.45, 30.86] 21.24 [17.51, 24.67] 27.52 [24.63, 31.12] 27.48 [24.97, 31.19] <0.001 nonnorm
punt_panto (median [IQR]) 34.00 [31.00, 38.00] 29.50 [26.38, 31.62] 34.00 [32.40, 36.88] 36.00 [34.00, 38.50] <0.001 nonnorm
punt_braquial (median [IQR]) 29.00 [25.00, 31.00] 23.75 [20.88, 25.88] 29.00 [26.75, 30.12] 30.00 [27.00, 32.90] <0.001 nonnorm
pairwise.wilcox.test(
  x = datos$imc,
  g = datos$estado_nutricional_crib_eval,
  p.adjust.method = "bonferroni",
  exact = FALSE
)
## 
##  Pairwise comparisons using Wilcoxon rank sum test with continuity correction 
## 
## data:  datos$imc and datos$estado_nutricional_crib_eval 
## 
##        MALNUTRICION NORMAL
## NORMAL 0.00007      -     
## RIESGO 0.00008      1     
## 
## P value adjustment method: bonferroni
#análisis descriptivo
#total de pacientes 101
table_s<-table(Base_de_datos_ampliada$sexo)
table_s
## 
##  1  2 
## 35 66
prop.table(table_s)
## 
##     1     2 
## 0.347 0.653
prop.test(
  x = 65.3,
  n = 101,
  conf.level = 0.95,
  correct = FALSE
)
## 
##  1-sample proportions test without continuity correction
## 
## data:  65.3 out of 101, null probability 0.5
## X-squared = 9, df = 1, p-value = 0.003
## alternative hypothesis: true p is not equal to 0.5
## 95 percent confidence interval:
##  0.550 0.733
## sample estimates:
##     p 
## 0.647
describe(Base_de_datos_ampliada$edad)
##    vars   n mean   sd median trimmed  mad min max range skew kurtosis  se
## X1    1 101   68 7.03     67    67.1 5.93  60  85    25  0.9    -0.11 0.7
describe(Base_de_datos_ampliada$dias_int)
##    vars   n mean   sd median trimmed  mad min max range skew kurtosis   se
## X1    1 101 16.2 16.2     10      13 5.93   2  91    89 2.39     6.82 1.61
median(Base_de_datos_ampliada$dias_int, na.rm = TRUE)
## [1] 10
quantile(
  Base_de_datos_ampliada$dias_int,
  probs = c(0.25, 0.75),
  na.rm = TRUE
)
## 25% 75% 
##   7  18
table_2 <- table(datos$estado_nutricional_crib_eval)
prop.table(table_2)
## 
## MALNUTRICION       NORMAL       RIESGO 
##        0.238        0.366        0.396
kableone(table_2)
Var1 Freq
MALNUTRICION 24
NORMAL 37
RIESGO 40
datos$estado_nutricional_crib_eval <- factor(
  datos$estado_nutricional_crib_eval,
  levels = c("MALNUTRICION", "RIESGO", "NORMAL")
)
library(dplyr)
library(binom)
## Warning: package 'binom' was built under R version 4.4.3
tabla_2 <- datos %>%
  dplyr::filter(!is.na(estado_nutricional_crib_eval)) %>%
  dplyr::count(estado_nutricional_crib_eval, name = "n") %>%
  dplyr::mutate(
    total = sum(n),
    frecuencia = n / total,
    
    # IC95% de Wilson
    IC_inf = binom::binom.confint(
      n, total,
      methods = "wilson"
    )$lower,
    
    IC_sup = binom::binom.confint(
      n, total,
      methods = "wilson"
    )$upper
  ) %>%
  dplyr::mutate(
    `Frecuencia (%)` = sprintf("%.1f", frecuencia * 100),
    `IC95%` = sprintf(
      "%.1f–%.1f",
      IC_inf * 100,
      IC_sup * 100
    )
  ) %>%
  dplyr::select(
    Estado_nutricional = estado_nutricional_crib_eval,
    n,
    `Frecuencia (%)`,
    `IC95%`
  )

tabla_2
## # A tibble: 3 × 4
##   Estado_nutricional     n `Frecuencia (%)` `IC95%`  
##   <fct>              <int> <chr>            <chr>    
## 1 MALNUTRICION          24 23.8             16.5–32.9
## 2 RIESGO                40 39.6             30.6–49.4
## 3 NORMAL                37 36.6             27.9–46.4
knitr::kable(tabla_2)
Estado_nutricional n Frecuencia (%) IC95%
MALNUTRICION 24 23.8 16.5–32.9
RIESGO 40 39.6 30.6–49.4
NORMAL 37 36.6 27.9–46.4
#análisis de días de internación
#creo subset de vivos
datos_vivos <- subset(datos, alta_obito == "0")
describe(datos_vivos$dias_int)
##    vars  n mean   sd median trimmed  mad min max range skew kurtosis   se
## X1    1 91 16.2 16.6      9    12.9 5.93   2  91    89 2.41     6.83 1.73
median(datos_vivos$dias_int, na.rm = TRUE)
## [1] 9
quantile(
  datos_vivos$dias_int,
  probs = c(0.25, 0.75),
  na.rm = TRUE
)
## 25% 75% 
##   7  18
describeBy(datos_vivos$dias_int, datos_vivos$estado_nutricional_crib_eval)
## 
##  Descriptive statistics by group 
## group: MALNUTRICION
##    vars  n mean   sd median trimmed mad min max range skew kurtosis   se
## X1    1 19 19.7 16.1     13    18.5 8.9   5  55    50 0.92    -0.64 3.68
## ------------------------------------------------------------ 
## group: RIESGO
##    vars  n mean   sd median trimmed  mad min max range skew kurtosis   se
## X1    1 35 13.9 10.7     10    12.1 5.93   2  45    43 1.46     1.41 1.82
## ------------------------------------------------------------ 
## group: NORMAL
##    vars  n mean   sd median trimmed  mad min max range skew kurtosis   se
## X1    1 37 16.5 20.9      8    12.1 4.45   3  91    88 2.44     5.57 3.43
tabla_dias <- datos_vivos %>%
  dplyr::group_by(estado_nutricional_crib_eval) %>%
  dplyr::summarise(
    N = sum(!is.na(dias_int)),
    Mediana_RIC = paste0(
      median(dias_int, na.rm = TRUE),
      " [",
      quantile(dias_int, 0.25, na.rm = TRUE),
      "–",
      quantile(dias_int, 0.75, na.rm = TRUE),
      "]"
    )
  )

View(tabla_dias)
knitr::kable(
  tabla_dias,
  digits = 2,
  caption = "Tabla dias de internacion segun estado de nutricion"
)
Tabla dias de internacion segun estado de nutricion
estado_nutricional_crib_eval N Mediana_RIC
MALNUTRICION 19 13 [8–33]
RIESGO 35 10 [7–17.5]
NORMAL 37 8 [6–17]
#dias de internación según estado nutricional al ingreso: kruskal
kruskal.test(datos_vivos$dias_int, datos_vivos$estado_nutricional_crib_eval)
## 
##  Kruskal-Wallis rank sum test
## 
## data:  datos_vivos$dias_int and datos_vivos$estado_nutricional_crib_eval
## Kruskal-Wallis chi-squared = 4, df = 2, p-value = 0.2
pairwise.wilcox.test(
  x = datos_vivos$dias_int,
  g = datos_vivos$estado_nutricional_crib_eval,
  p.adjust.method = "bonferroni",
  exact = FALSE
)
## 
##  Pairwise comparisons using Wilcoxon rank sum test with continuity correction 
## 
## data:  datos_vivos$dias_int and datos_vivos$estado_nutricional_crib_eval 
## 
##        MALNUTRICION RIESGO
## RIESGO 0.7          -     
## NORMAL 0.2          1.0   
## 
## P value adjustment method: bonferroni
#regresion lineal dias en funcion de estado nutricional ajustando por edad
#ajustando por la edad

mod_dias<-lm(dias_int ~ estado_nutricional_crib_eval , data=datos_vivos)
summary(mod_dias)
## 
## Call:
## lm(formula = dias_int ~ estado_nutricional_crib_eval, data = datos_vivos)
## 
## Residuals:
##    Min     1Q Median     3Q    Max 
## -14.74 -10.19  -5.86   3.31  74.49 
## 
## Coefficients:
##                                    Estimate Std. Error t value  Pr(>|t|)    
## (Intercept)                           19.74       3.81    5.19 0.0000014 ***
## estado_nutricional_crib_evalRIESGO    -5.88       4.73   -1.24      0.22    
## estado_nutricional_crib_evalNORMAL    -3.22       4.68   -0.69      0.49    
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 16.6 on 88 degrees of freedom
## Multiple R-squared:  0.0176, Adjusted R-squared:  -0.00475 
## F-statistic: 0.787 on 2 and 88 DF,  p-value: 0.458
confint(mod_dias)
##                                    2.5 % 97.5 %
## (Intercept)                         12.2  27.30
## estado_nutricional_crib_evalRIESGO -15.3   3.51
## estado_nutricional_crib_evalNORMAL -12.5   6.08
tab_model(mod_dias)
  dias_int
Predictors Estimates CI p
(Intercept) 19.74 12.17 – 27.30 <0.001
estado nutricional crib
eval [RIESGO]
-5.88 -15.27 – 3.51 0.217
estado nutricional crib
eval [NORMAL]
-3.22 -12.53 – 6.08 0.493
Observations 91
R2 / R2 adjusted 0.018 / -0.005
#ajustando por edad
mod_dias_e<-lm(dias_int ~ estado_nutricional_crib_eval + edad , data=datos_vivos)
summary(mod_dias_e)
## 
## Call:
## lm(formula = dias_int ~ estado_nutricional_crib_eval + edad, 
##     data = datos_vivos)
## 
## Residuals:
##    Min     1Q Median     3Q    Max 
## -16.33  -9.57  -5.35   2.76  74.18 
## 
## Coefficients:
##                                    Estimate Std. Error t value Pr(>|t|)  
## (Intercept)                          45.727     19.907    2.30    0.024 *
## estado_nutricional_crib_evalRIESGO   -7.635      4.888   -1.56    0.122  
## estado_nutricional_crib_evalNORMAL   -5.730      5.028   -1.14    0.258  
## edad                                 -0.357      0.268   -1.33    0.187  
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 16.5 on 87 degrees of freedom
## Multiple R-squared:  0.0372, Adjusted R-squared:  0.00395 
## F-statistic: 1.12 on 3 and 87 DF,  p-value: 0.346
confint(mod_dias_e)
##                                      2.5 % 97.5 %
## (Intercept)                          6.159 85.295
## estado_nutricional_crib_evalRIESGO -17.351  2.081
## estado_nutricional_crib_evalNORMAL -15.724  4.264
## edad                                -0.889  0.176
tab_model(mod_dias_e)
  dias_int
Predictors Estimates CI p
(Intercept) 45.73 6.16 – 85.29 0.024
estado nutricional crib
eval [RIESGO]
-7.64 -17.35 – 2.08 0.122
estado nutricional crib
eval [NORMAL]
-5.73 -15.72 – 4.26 0.258
edad -0.36 -0.89 – 0.18 0.187
Observations 91
R2 / R2 adjusted 0.037 / 0.004
anova(mod_dias, mod_dias_e)
## Analysis of Variance Table
## 
## Model 1: dias_int ~ estado_nutricional_crib_eval
## Model 2: dias_int ~ estado_nutricional_crib_eval + edad
##   Res.Df   RSS Df Sum of Sq    F Pr(>F)
## 1     88 24215                         
## 2     87 23733  1       482 1.77   0.19

##Dentro de MALNUTRICIÓN, RIESGO y NORMAL, ¿qué ítems aportaron mayor puntaje a la sumatoria?

#evaluar qué variable contribuye más al puntaje. Correlación item total corregida
maximos <- c(
  per_peso = 3,
  movi = 2,
  enf_ag = 2,
  apetito = 2,
  neuro = 2,
  imc_cat = 3,
  vive_ind = 1,
  polim = 1,
  ulceras = 1,
  comidas = 2,
  lacteos = 1,
  frutas = 1,
  agua = 1,
  forma = 2,
  bien_nutrido = 2,
  estado_salud = 2,
  cir_braquial = 1,
  cir_panto = 1
)
library(dplyr)
library(tidyr)
tabla_aporte <- datos %>%
  dplyr::select(
    estado_nutricional_crib_eval,
    dplyr::all_of(variables_1)
  ) %>%
  
  tidyr::pivot_longer(
    cols = dplyr::all_of(variables_1),
    names_to = "Variable",
    values_to = "Puntaje"
  ) %>%
  
  dplyr::group_by(
    estado_nutricional_crib_eval,
    Variable
  ) %>%
  
  dplyr::summarise(
    N = sum(!is.na(Puntaje)),
    Media = mean(Puntaje, na.rm = TRUE),
    Mediana = median(Puntaje, na.rm = TRUE),
    .groups = "drop"
  ) %>%
  
  dplyr::mutate(
    Maximo = maximos[Variable],
    Aporte_porcentaje = Media / Maximo * 100
  ) %>%
  
  dplyr::arrange(
    estado_nutricional_crib_eval,
    dplyr::desc(Aporte_porcentaje)
  )

View(tabla_aporte)
#malnutricion
tabla_malnutricion <- tabla_aporte %>%
  filter(estado_nutricional_crib_eval == "MALNUTRICION") %>%
  arrange(desc(Aporte_porcentaje))

View(tabla_malnutricion)
#riesgo
tabla_riesgo <- tabla_aporte %>%
  filter(estado_nutricional_crib_eval == "RIESGO") %>%
  arrange(desc(Aporte_porcentaje))

View(tabla_riesgo)
#normal
tabla_normal <- tabla_aporte %>%
  filter(estado_nutricional_crib_eval == "NORMAL") %>%
  arrange(desc(Aporte_porcentaje))

View(tabla_normal)


knitr::kable(
  tabla_malnutricion,
  digits = 2,
  caption = "Aporte relativo de los componentes en pacientes con malnutrición"
)
Aporte relativo de los componentes en pacientes con malnutrición
estado_nutricional_crib_eval Variable N Media Mediana Maximo Aporte_porcentaje
MALNUTRICION neuro 24 1.58 2.0 2 79.17
MALNUTRICION cir_braquial 24 0.73 1.0 1 72.92
MALNUTRICION forma 24 1.33 2.0 2 66.67
MALNUTRICION comidas 24 1.17 2.0 2 58.33
MALNUTRICION ulceras 24 0.54 1.0 1 54.17
MALNUTRICION agua 24 0.52 0.5 1 52.08
MALNUTRICION imc_cat 24 1.46 1.5 3 48.61
MALNUTRICION bien_nutrido 24 0.92 1.0 2 45.83
MALNUTRICION cir_panto 24 0.46 0.0 1 45.83
MALNUTRICION enf_ag 24 0.83 0.0 2 41.67
MALNUTRICION lacteos 24 0.38 0.5 1 37.50
MALNUTRICION frutas 24 0.33 0.0 1 33.33
MALNUTRICION estado_salud 24 0.56 0.5 2 28.12
MALNUTRICION movi 24 0.50 0.0 2 25.00
MALNUTRICION vive_ind 24 0.25 0.0 1 25.00
MALNUTRICION polim 24 0.21 0.0 1 20.83
MALNUTRICION apetito 24 0.33 0.0 2 16.67
MALNUTRICION per_peso 24 0.21 0.0 3 6.94
knitr::kable(
  tabla_riesgo,
  digits = 2,
  caption = "Aporte relativo de los componentes en pacientes en riesgo nutricional"
)
Aporte relativo de los componentes en pacientes en riesgo nutricional
estado_nutricional_crib_eval Variable N Media Mediana Maximo Aporte_porcentaje
RIESGO cir_braquial 40 1.00 1.0 1 100.0
RIESGO forma 40 1.93 2.0 2 96.2
RIESGO imc_cat 40 2.83 3.0 3 94.2
RIESGO comidas 40 1.75 2.0 2 87.5
RIESGO neuro 40 1.70 2.0 2 85.0
RIESGO cir_panto 40 0.80 1.0 1 80.0
RIESGO ulceras 40 0.78 1.0 1 77.5
RIESGO agua 40 0.74 1.0 1 73.8
RIESGO bien_nutrido 40 1.35 1.5 2 67.5
RIESGO movi 40 1.30 1.5 2 65.0
RIESGO estado_salud 40 1.26 1.0 2 63.1
RIESGO vive_ind 40 0.60 1.0 1 60.0
RIESGO lacteos 40 0.58 0.5 1 57.5
RIESGO enf_ag 40 1.10 2.0 2 55.0
RIESGO frutas 40 0.55 1.0 1 55.0
RIESGO polim 40 0.50 0.5 1 50.0
RIESGO apetito 40 0.92 1.0 2 46.2
RIESGO per_peso 40 0.90 0.0 3 30.0
knitr::kable(
  tabla_normal,
  digits = 2,
  caption = "Aporte relativo de los componentes en pacientes con estado nutricional normal"
)
Aporte relativo de los componentes en pacientes con estado nutricional normal
estado_nutricional_crib_eval Variable N Media Mediana Maximo Aporte_porcentaje
NORMAL forma 37 1.97 2.0 2 98.7
NORMAL cir_braquial 37 0.97 1.0 1 97.3
NORMAL neuro 37 1.95 2.0 2 97.3
NORMAL imc_cat 37 2.89 3.0 3 96.4
NORMAL cir_panto 37 0.95 1.0 1 94.6
NORMAL movi 37 1.84 2.0 2 91.9
NORMAL apetito 37 1.81 2.0 2 90.5
NORMAL comidas 37 1.81 2.0 2 90.5
NORMAL agua 37 0.84 1.0 1 83.8
NORMAL enf_ag 37 1.68 2.0 2 83.8
NORMAL per_peso 37 2.51 3.0 3 83.8
NORMAL bien_nutrido 37 1.62 2.0 2 81.1
NORMAL ulceras 37 0.78 1.0 1 78.4
NORMAL estado_salud 37 1.53 2.0 2 76.3
NORMAL vive_ind 37 0.76 1.0 1 75.7
NORMAL frutas 37 0.68 1.0 1 67.6
NORMAL polim 37 0.65 1.0 1 64.9
NORMAL lacteos 37 0.64 0.5 1 63.5