library(kableExtra)
library(ggplot2)
library(dplyr)
## 
## Attaching package: 'dplyr'
## The following object is masked from 'package:kableExtra':
## 
##     group_rows
## The following objects are masked from 'package:stats':
## 
##     filter, lag
## The following objects are masked from 'package:base':
## 
##     intersect, setdiff, setequal, union
library(tidyverse)
## ── Attaching core tidyverse packages ──────────────────────── tidyverse 2.0.0 ──
## ✔ forcats   1.0.0     ✔ stringr   1.5.1
## ✔ lubridate 1.9.3     ✔ tibble    3.2.1
## ✔ purrr     1.0.2     ✔ tidyr     1.3.1
## ✔ readr     2.1.5
## ── Conflicts ────────────────────────────────────────── tidyverse_conflicts() ──
## ✖ dplyr::filter()     masks stats::filter()
## ✖ dplyr::group_rows() masks kableExtra::group_rows()
## ✖ dplyr::lag()        masks stats::lag()
## ℹ Use the conflicted package (<http://conflicted.r-lib.org/>) to force all conflicts to become errors
library(doBy)
## 
## Attaching package: 'doBy'
## 
## The following object is masked from 'package:dplyr':
## 
##     order_by
library(knitr)
library(kableExtra)
datos <- read.csv2("Base_datos_Fibrosis.csv")
dato_por_genero <- datos %>%
  group_by(genero) %>%
  count() %>%
  ungroup() %>%
  mutate(Porcentaje = n / sum(n)) %>%
  arrange(Porcentaje) %>%
  mutate(etiquetas = scales::percent(Porcentaje))

colors <- c("lightgreen", "#DEB7D9") 

ggplot(dato_por_genero, aes(x = "", y = Porcentaje, fill = genero)) +
  geom_col(color = "black") +
  geom_label(aes(label = etiquetas),
             position = position_stack(vjust = 0.5),
             show.legend = FALSE) +
  scale_fill_manual(values = colors) + 
  guides(fill = guide_legend(title = "Cantidad de sujetos según género")) +
  coord_polar(theta = "y") +
  ggtitle("")

print(dato_por_genero)
## # A tibble: 2 × 4
##   genero     n Porcentaje etiquetas
##   <chr>  <int>      <dbl> <chr>    
## 1 Mujer    150      0.464 46.4%    
## 2 Hombre   173      0.536 53.6%
# Datos numéricos
datos_numericos <- datos[, c("Glucemia", "Urea", "Creatinina", "Colesterol", "Triglicéridos",
                             "GOT", "GPT", "GGT", "Fosfatasa.Alcalina", "bilirrubina.total",
                             "proteínas.totales", "albúmina", "sodio", "potasio",
                             "leucocitos", "hematocrito", "plaquetas", "Índice.de.Quick",
                             "fibrinógeno")]

# Resumen estadístico
kable(summary(datos_numericos), caption = "Resumen estadístico de datos numéricos")
Resumen estadístico de datos numéricos
Glucemia Urea Creatinina Colesterol Triglicéridos GOT GPT GGT Fosfatasa.Alcalina bilirrubina.total proteínas.totales albúmina sodio potasio leucocitos hematocrito plaquetas Índice.de.Quick fibrinógeno
Min. : 14.0 Min. : 11.00 Min. :0.400 Min. : 20.0 Min. : 7.5 Min. : 13.00 Min. : 16.0 Min. : 12.0 Min. : 27.0 Min. :0.230 Min. :4.600 Min. :2.600 Min. :128.0 Min. :3.400 Min. : 1700 Min. :24.00 Min. : 10000 Min. : 45.00 Min. :123.0
1st Qu.: 88.0 1st Qu.: 23.50 1st Qu.:0.900 1st Qu.:158.5 1st Qu.:104.0 1st Qu.: 36.50 1st Qu.: 50.0 1st Qu.: 35.0 1st Qu.: 71.0 1st Qu.:0.700 1st Qu.:6.800 1st Qu.:4.000 1st Qu.:138.0 1st Qu.:4.200 1st Qu.: 4015 1st Qu.:38.00 1st Qu.:108000 1st Qu.: 96.00 1st Qu.:227.0
Median :101.0 Median : 31.00 Median :1.100 Median :180.0 Median :136.0 Median : 56.00 Median : 82.0 Median : 67.0 Median : 95.0 Median :1.000 Median :7.100 Median :4.300 Median :140.0 Median :4.500 Median : 5450 Median :41.00 Median :139000 Median :100.00 Median :270.5
Mean :112.2 Mean : 35.16 Mean :1.185 Mean :181.6 Mean :158.3 Mean : 88.52 Mean :118.8 Mean : 116.3 Mean :105.6 Mean :1.148 Mean :7.136 Mean :4.236 Mean :139.7 Mean :4.536 Mean : 5571 Mean :41.28 Mean :141053 Mean : 96.01 Mean :275.7
3rd Qu.:122.5 3rd Qu.: 43.00 3rd Qu.:1.390 3rd Qu.:204.0 3rd Qu.:190.0 3rd Qu.:107.50 3rd Qu.:138.0 3rd Qu.: 134.5 3rd Qu.:122.5 3rd Qu.:1.300 3rd Qu.:7.500 3rd Qu.:4.500 3rd Qu.:141.0 3rd Qu.:4.800 3rd Qu.: 6770 3rd Qu.:44.50 3rd Qu.:169000 3rd Qu.:100.00 3rd Qu.:313.0
Max. :352.0 Max. :174.00 Max. :9.400 Max. :337.0 Max. :591.0 Max. :752.00 Max. :766.0 Max. :1884.0 Max. :492.0 Max. :8.300 Max. :9.100 Max. :7.700 Max. :150.0 Max. :6.000 Max. :12640 Max. :57.00 Max. :297000 Max. :118.00 Max. :610.0
NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA’s :1
# Calcular la frecuencia de cada combinación de género y fibrosis
frecuencia_genero_fibrosis <- table(datos$fibrosis, datos$genero)

# Convertir los resultados en un data frame para facilitar el manejo
frecuencia_df <- as.data.frame(frecuencia_genero_fibrosis)
colnames(frecuencia_df) <- c("Fibrosis", "Genero", "Cantidad")

# Graficar con etiquetas de valores
ggplot(frecuencia_df, aes(x = Fibrosis, y = Cantidad, fill = Genero)) +
  geom_bar(stat = "identity", position = "dodge") +
  geom_text(aes(label = Cantidad), 
            position = position_dodge(width = 0.9), 
            vjust = -0.5, 
            size = 3, 
            color = "black") +
  labs(x = "Fibrosis", y = "Cantidad", fill = "Género",
       title = "Distribución de género en cada categoría de fibrosis") +
  theme_minimal()

generar_grafico_barras <- function(datos, variable, agrupacion1, agrupacion2, etiquetas_x = NULL, etiquetas_y = NULL, etiquetas_fill = NULL, titulo = NULL) {
  promedio_variable <- datos %>%
    group_by({{ agrupacion1 }}, {{ agrupacion2 }}) %>%
    summarize(promedio_variable = mean({{ variable }}, na.rm = TRUE))

  plot <- ggplot(promedio_variable, aes(x = promedio_variable, y = {{ agrupacion1 }}, fill = {{ agrupacion2 }})) +
    geom_bar(stat = "identity", position = "dodge") +
    geom_text(aes(label = round(promedio_variable, 2)), position = position_dodge(width = 0.9), vjust = 0.5, hjust = 1) +
    labs(x = ifelse(is.null(etiquetas_x), "Promedio de Variable", etiquetas_x),
         y = ifelse(is.null(etiquetas_y), "Fibrosis", etiquetas_y),
         fill = ifelse(is.null(etiquetas_fill), "Género", etiquetas_fill),
         title = ifelse(is.null(titulo), paste("Promedio de", deparse(substitute(variable)), "por Categoría de Fibrosis y Genéro"), titulo)) +
    theme_minimal()

  return(plot)
}
#Barras promedio para Glucemia 
grafico <- generar_grafico_barras(datos, Glucemia, fibrosis, genero)
## `summarise()` has grouped output by 'fibrosis'. You can override using the
## `.groups` argument.
print(grafico)

#Barras promedio para Urea
grafico <- generar_grafico_barras(datos, Urea, fibrosis, genero)
## `summarise()` has grouped output by 'fibrosis'. You can override using the
## `.groups` argument.
print(grafico)

#Barras promedio para Creatinina
grafico <- generar_grafico_barras(datos, Creatinina, fibrosis, genero)
## `summarise()` has grouped output by 'fibrosis'. You can override using the
## `.groups` argument.
print(grafico)

#Barras promedio para Colesterol
grafico <- generar_grafico_barras(datos, Colesterol, fibrosis, genero)
## `summarise()` has grouped output by 'fibrosis'. You can override using the
## `.groups` argument.
print(grafico)

#Barras promedio para Triglicéridos
grafico <- generar_grafico_barras(datos, Triglicéridos, fibrosis, genero)
## `summarise()` has grouped output by 'fibrosis'. You can override using the
## `.groups` argument.
print(grafico)

#Barras promedio para GOT 
grafico <- generar_grafico_barras(datos, GOT, fibrosis, genero)
## `summarise()` has grouped output by 'fibrosis'. You can override using the
## `.groups` argument.
print(grafico)

#Barras promedio para GPT
grafico <- generar_grafico_barras(datos,GPT, fibrosis, genero)
## `summarise()` has grouped output by 'fibrosis'. You can override using the
## `.groups` argument.
print(grafico)

#Barras promedio para GGT
grafico <- generar_grafico_barras(datos, GGT, fibrosis, genero)
## `summarise()` has grouped output by 'fibrosis'. You can override using the
## `.groups` argument.
print(grafico)

#Barras promedio para Fosfatasa Alcalina
grafico <- generar_grafico_barras(datos, Fosfatasa.Alcalina, fibrosis, genero)
## `summarise()` has grouped output by 'fibrosis'. You can override using the
## `.groups` argument.
print(grafico)

#Barras promedio para bilirrubina.total
grafico <- generar_grafico_barras(datos, bilirrubina.total, fibrosis, genero)
## `summarise()` has grouped output by 'fibrosis'. You can override using the
## `.groups` argument.
print(grafico)

#Barras promedio para proteínas.totales 
grafico <- generar_grafico_barras(datos, proteínas.totales, fibrosis, genero)
## `summarise()` has grouped output by 'fibrosis'. You can override using the
## `.groups` argument.
print(grafico)

#Barras promedio para albúmina
grafico <- generar_grafico_barras(datos, albúmina, fibrosis, genero)
## `summarise()` has grouped output by 'fibrosis'. You can override using the
## `.groups` argument.
print(grafico)

#Barras promedio para sodio
grafico <- generar_grafico_barras(datos, sodio, fibrosis, genero)
## `summarise()` has grouped output by 'fibrosis'. You can override using the
## `.groups` argument.
print(grafico)

#Barras promedio para potasio
grafico <- generar_grafico_barras(datos, potasio, fibrosis, genero)
## `summarise()` has grouped output by 'fibrosis'. You can override using the
## `.groups` argument.
print(grafico)

#Barras promedio para leucocitos
grafico <- generar_grafico_barras(datos, leucocitos, fibrosis, genero)
## `summarise()` has grouped output by 'fibrosis'. You can override using the
## `.groups` argument.
print(grafico)

#Barras promedio para hematocrito
grafico <- generar_grafico_barras(datos, hematocrito, fibrosis, genero)
## `summarise()` has grouped output by 'fibrosis'. You can override using the
## `.groups` argument.
print(grafico)

#Barras promedio para plaquetas
grafico <- generar_grafico_barras(datos, plaquetas, fibrosis, genero)
## `summarise()` has grouped output by 'fibrosis'. You can override using the
## `.groups` argument.
print(grafico)

#Barras promedio para Índice.de.Quick
grafico <- generar_grafico_barras(datos, Índice.de.Quick, fibrosis, genero)
## `summarise()` has grouped output by 'fibrosis'. You can override using the
## `.groups` argument.
print(grafico)

#Barras promedio para fibrinógeno
grafico <- generar_grafico_barras(datos, fibrinógeno, fibrosis, genero)
## `summarise()` has grouped output by 'fibrosis'. You can override using the
## `.groups` argument.
print(grafico)

#promedio de Glucemia
promedio_variable <- datos %>%
  group_by(fibrosis) %>%
  summarize(promedio_variable = mean(Glucemia, na.rm = TRUE))

#Gráfico
ggplot(promedio_variable, aes(x = fibrosis, y = promedio_variable, fill = fibrosis)) +
  geom_col() +
  geom_text(aes(label = round(promedio_variable, 2)), vjust = -0.5, hjust = 0.5, color = "black", size = 3) +
  labs(x = "Fibrosis", y = "Promedio de Glucemia",
       title = "Promedio de Glucemia por Categoría de Fibrosis") +
  theme_minimal()

#promedio de Urea
promedio_Urea <- datos %>%
  group_by(fibrosis) %>%
  summarize(promedio_Urea = mean(Urea, na.rm = TRUE))

#Gráfico
ggplot(promedio_Urea, aes(x = fibrosis, y = promedio_Urea, fill = fibrosis)) +
  geom_col() +
  geom_text(aes(label = round(promedio_Urea, 2)), vjust = -0.5, hjust = 0.5, color = "black", size = 3) +
  labs(x = "Fibrosis", y = "Promedio de Urea",
       title = "Promedio de Urea por Categoría de Fibrosis") +
  theme_minimal()

#promedio de Creatinina
promedio_variable <- datos %>%
  group_by(fibrosis) %>%
  summarize(promedio_variable = mean(Creatinina, na.rm = TRUE))

#Gráfico
ggplot(promedio_variable, aes(x = fibrosis, y = promedio_variable, fill = fibrosis)) +
  geom_col() +
  geom_text(aes(label = round(promedio_variable, 2)), vjust = -0.5, hjust = 0.5, color = "black", size = 3) +
  labs(x = "Fibrosis", y = "Promedio de Creatinina",
       title = "Promedio de Creatinina por Categoría de Fibrosis") +
  theme_minimal()

#promedio de Colesterol
promedio_variable <- datos %>%
  group_by(fibrosis) %>%
  summarize(promedio_variable = mean(Colesterol, na.rm = TRUE))

#Gráfico
ggplot(promedio_variable, aes(x = fibrosis, y = promedio_variable, fill = fibrosis)) +
  geom_col() +
  geom_text(aes(label = round(promedio_variable, 2)), vjust = -0.5, hjust = 0.5, color = "black", size = 3) +
  labs(x = "Fibrosis", y = "Promedio de Colesterol",
       title = "Promedio de Colesterol por Categoría de Fibrosis") +
  theme_minimal()

#promedio de Triglicéridos
promedio_variable <- datos %>%
  group_by(fibrosis) %>%
  summarize(promedio_variable = mean(Triglicéridos, na.rm = TRUE))

#Gráfico
ggplot(promedio_variable, aes(x = fibrosis, y = promedio_variable, fill = fibrosis)) +
  geom_col() +
  geom_text(aes(label = round(promedio_variable, 2)), vjust = -0.5, hjust = 0.5, color = "black", size = 3) +
  labs(x = "Fibrosis", y = "Promedio de Triglicéridos",
       title = "Promedio de Triglicéridos por Categoría de Fibrosis") +
  theme_minimal()

#promedio GOT
promedio_variable <- datos %>%
  group_by(fibrosis) %>%
  summarize(promedio_variable = mean(GOT, na.rm = TRUE))

#Gráfico
ggplot(promedio_variable, aes(x = fibrosis, y = promedio_variable, fill = fibrosis)) +
  geom_col() +
  geom_text(aes(label = round(promedio_variable, 2)), vjust = -0.5, hjust = 0.5, color = "black", size = 3) +
  labs(x = "Fibrosis", y = "Promedio de GOT",
       title = "Promedio de GOT por Categoría de Fibrosis") +
  theme_minimal()

#promedio GPT
promedio_variable <- datos %>%
  group_by(fibrosis) %>%
  summarize(promedio_variable = mean(GPT, na.rm = TRUE))

#Gráfico
ggplot(promedio_variable, aes(x = fibrosis, y = promedio_variable, fill = fibrosis)) +
  geom_col() +
  geom_text(aes(label = round(promedio_variable, 2)), vjust = -0.5, hjust = 0.5, color = "black", size = 3) +
  labs(x = "Fibrosis", y = "Promedio de GPT",
       title = "Promedio de GPT por Categoría de Fibrosis") +
  theme_minimal()

#promedio GGT
promedio_variable <- datos %>%
  group_by(fibrosis) %>%
  summarize(promedio_variable = mean(GGT, na.rm = TRUE))

#Gráfico
ggplot(promedio_variable, aes(x = fibrosis, y = promedio_variable, fill = fibrosis)) +
  geom_col() +
  geom_text(aes(label = round(promedio_variable, 2)), vjust = -0.5, hjust = 0.5, color = "black", size = 3) +
  labs(x = "Fibrosis", y = "Promedio de GGT",
       title = "Promedio de GGT por Categoría de Fibrosis") +
  theme_minimal()

#promedio Fosfatasa Alcalina
promedio_variable <- datos %>%
  group_by(fibrosis) %>%
  summarize(promedio_variable = mean(Fosfatasa.Alcalina, na.rm = TRUE))

#Gráfico
ggplot(promedio_variable, aes(x = fibrosis, y = promedio_variable, fill = fibrosis)) +
  geom_col() +
  geom_text(aes(label = round(promedio_variable, 2)), vjust = -0.5, hjust = 0.5, color = "black", size = 3) +
  labs(x = "Fibrosis", y = "Promedio de Fosfatasa Alcalina",
       title = "Promedio de Fosfatasa Alcalina por Categoría de Fibrosis") +
  theme_minimal()

#promedio Bilirrubina total
promedio_variable <- datos %>%
  group_by(fibrosis) %>%
  summarize(promedio_variable = mean(bilirrubina.total, na.rm = TRUE))

#Gráfico
ggplot(promedio_variable, aes(x = fibrosis, y = promedio_variable, fill = fibrosis)) +
  geom_col() +
  geom_text(aes(label = round(promedio_variable, 2)), vjust = -0.5, hjust = 0.5, color = "black", size = 3) +
  labs(x = "Fibrosis", y = "Promedio de Bilirrubina Total",
       title = "Promedio de Bilirrubina Total por Categoría de Fibrosis") +
  theme_minimal()

#promedio proteínas totales
promedio_variable <- datos %>%
  group_by(fibrosis) %>%
  summarize(promedio_variable = mean(proteínas.totales, na.rm = TRUE))

#Gráfico
ggplot(promedio_variable, aes(x = fibrosis, y = promedio_variable, fill = fibrosis)) +
  geom_col() +
  geom_text(aes(label = round(promedio_variable, 2)), vjust = -0.5, hjust = 0.5, color = "black", size = 3) +
  labs(x = "Fibrosis", y = "Promedio de Proteínas totales   ",
       title = "Promedio de Proteínas totales por Categoría de Fibrosis") +
  theme_minimal()

#promedio albúmina
promedio_variable <- datos %>%
  group_by(fibrosis) %>%
  summarize(promedio_variable = mean(albúmina, na.rm = TRUE))

#Gráfico
ggplot(promedio_variable, aes(x = fibrosis, y = promedio_variable, fill = fibrosis)) +
  geom_col() +
  geom_text(aes(label = round(promedio_variable, 2)), vjust = -0.5, hjust = 0.5, color = "black", size = 3) +
  labs(x = "Fibrosis", y = "Promedio de Albúmia",
       title = "Promedio de Albúmia por Categoría de Fibrosis") +
  theme_minimal()

#promedio sodio
promedio_variable <- datos %>%
  group_by(fibrosis) %>%
  summarize(promedio_variable = mean(sodio, na.rm = TRUE))

#Gráfico
ggplot(promedio_variable, aes(x = fibrosis, y = promedio_variable, fill = fibrosis)) +
  geom_col() +
  geom_text(aes(label = round(promedio_variable, 2)), vjust = -0.5, hjust = 0.5, color = "black", size = 3) +
  labs(x = "Fibrosis", y = "Promedio de Sodio",
       title = "Promedio de Sodio por Categoría de Fibrosis") +
  theme_minimal()

#promedio potasio
promedio_variable <- datos %>%
  group_by(fibrosis) %>%
  summarize(promedio_variable = mean(potasio, na.rm = TRUE))

#Gráfico
ggplot(promedio_variable, aes(x = fibrosis, y = promedio_variable, fill = fibrosis)) +
  geom_col() +
  geom_text(aes(label = round(promedio_variable, 2)), vjust = -0.5, hjust = 0.5, color = "black", size = 3) +
  labs(x = "Fibrosis", y = "Promedio de Potasio",
       title = "Promedio de Potasio por Categoría de Fibrosis") +
  theme_minimal()

#promedio leucocitos
promedio_variable <- datos %>%
  group_by(fibrosis) %>%
  summarize(promedio_variable = mean(leucocitos, na.rm = TRUE))

#Gráfico
ggplot(promedio_variable, aes(x = fibrosis, y = promedio_variable, fill = fibrosis)) +
  geom_col() +
  geom_text(aes(label = round(promedio_variable, 2)), vjust = -0.5, hjust = 0.5, color = "black", size = 3) +
  labs(x = "Fibrosis", y = "Promedio de Leucocitos",
       title = "Promedio de Leucocitos por Categoría de Fibrosis") +
  theme_minimal()

#promedio hematocrito
promedio_variable <- datos %>%
  group_by(fibrosis) %>%
  summarize(promedio_variable = mean(hematocrito, na.rm = TRUE))

#Gráfico
ggplot(promedio_variable, aes(x = fibrosis, y = promedio_variable, fill = fibrosis)) +
  geom_col() +
  geom_text(aes(label = round(promedio_variable, 2)), vjust = -0.5, hjust = 0.5, color = "black", size = 3) +
  labs(x = "Fibrosis", y = "Promedio de Hematocrito",
       title = "Promedio de Hematocrito por Categoría de Fibrosis") +
  theme_minimal()

#promedio plaquetas
promedio_variable <- datos %>%
  group_by(fibrosis) %>%
  summarize(promedio_variable = mean(plaquetas, na.rm = TRUE))

#Gráfico
ggplot(promedio_variable, aes(x = fibrosis, y = promedio_variable, fill = fibrosis)) +
  geom_col() +
  geom_text(aes(label = round(promedio_variable, 2)), vjust = -0.5, hjust = 0.5, color = "black", size = 3) +
  labs(x = "Fibrosis", y = "Promedio de Plaquetas",
       title = "Promedio de Plaquetas por Categoría de Fibrosis") +
  theme_minimal()

#promedio Índice.de.Quick
promedio_variable <- datos %>%
  group_by(fibrosis) %>%
  summarize(promedio_variable = mean(Índice.de.Quick, na.rm = TRUE))

#Gráfico
ggplot(promedio_variable, aes(x = fibrosis, y = promedio_variable, fill = fibrosis)) +
  geom_col() +
  geom_text(aes(label = round(promedio_variable, 2)), vjust = -0.5, hjust = 0.5, color = "black", size = 3) +
  labs(x = "Fibrosis", y = "Promedio de Índice.de.Quick",
       title = "Promedio de Índice de Quick por Categoría de Fibrosis") +
  theme_minimal()

#promedio fibrinógeno
promedio_variable <- datos %>%
  group_by(fibrosis) %>%
  summarize(promedio_variable = mean(fibrinógeno, na.rm = TRUE))

#Gráfico
ggplot(promedio_variable, aes(x = fibrosis, y = promedio_variable, fill = fibrosis)) +
  geom_col() +
  geom_text(aes(label = round(promedio_variable, 2)), vjust = -0.5, hjust = 0.5, color = "black", size = 3) +
  labs(x = "Fibrosis", y = "Promedio de Fibrinógeno",
       title = "Promedio de Fibrinógeno por Categoría de Fibrosis") +
  theme_minimal()

compute_summary_stats <- function(data, group_var, target_var) {
  summary_stats <- data %>%
    group_by({{ group_var }}) %>%
    summarize(
      Q1 = quantile({{ target_var }}, 0.25),
      median = median({{ target_var }}),
      Q3 = quantile({{ target_var }}, 0.75),
      min = min({{ target_var }}),
      max = max({{ target_var }}),
      outliers = list(boxplot.stats({{ target_var }})$out)
    )
  # Convertir los valores atípicos en texto
  summary_stats$outliers <- sapply(summary_stats$outliers, function(x) paste(x, collapse = ", "))
  
  return(summary_stats)
}
#boxplot
ggplot(datos, aes(x = fibrosis, y = Glucemia)) +
  geom_boxplot(fill = "skyblue", color = "blue") +
  labs(x = "Fibrosis Hepática", y = "Glucemia") +
  ggtitle("Boxplot de Glucemia según Fibrosis")

variable <- "Glucemia"  
summary_stats <- compute_summary_stats(datos, fibrosis, !!as.name(variable))
kable(summary_stats, caption = "Resumen Glucemia")
Resumen Glucemia
fibrosis Q1 median Q3 min max outliers
ausencia 90.00 102.0 122.00 69 290 290, 228, 172, 205, 226, 181, 218, 271, 192, 235, 237, 177, 203, 204
importante 84.50 120.5 133.00 14 352 317, 352
leve 86.00 101.0 121.00 45 280 280, 260, 176, 192, 211, 225, 190
moderada 87.75 96.5 117.25 68 162
#boxplot
ggplot(datos, aes(x = fibrosis, y = Urea)) +
  geom_boxplot(fill = "skyblue", color = "blue") +
  labs(x = "Fibrosis Hepática", y = "Urea") +
  ggtitle("Boxplot de Urea según Fibrosis")

variable <- "Urea"  
summary_stats <- compute_summary_stats(datos, fibrosis, !!as.name(variable))
kable(summary_stats, caption = "Resumen Urea")
Resumen Urea
fibrosis Q1 median Q3 min max outliers
ausencia 25.00 33.0 45.00 12 84 84
importante 21.75 26.5 34.00 18 58 58
leve 22.25 29.0 43.00 13 174 87, 174
moderada 22.00 29.0 45.25 11 106 106, 89
#boxplot
ggplot(datos, aes(x = fibrosis, y = Creatinina)) +
  geom_boxplot(fill = "skyblue", color = "blue") +
  labs(x = "Fibrosis", y = "Creatinina") +
  ggtitle("Boxplot de Creatinina según Fibrosis")

variable <- "Creatinina"  
summary_stats <- compute_summary_stats(datos, fibrosis, !!as.name(variable))
kable(summary_stats, caption = "Resumen Creatinina")
Resumen Creatinina
fibrosis Q1 median Q3 min max outliers
ausencia 1.000 1.200 1.500 0.40 4.3 3, 2.5, 2.8, 4.3, 2.3
importante 0.875 1.040 1.225 0.60 1.7
leve 0.800 1.055 1.200 0.50 9.4 1.9, 9.4, 1.8, 2
moderada 0.860 1.000 1.200 0.49 2.2 2.2, 2, 1.8

``

#boxplot
ggplot(datos, aes(x = fibrosis, y = Colesterol))+
  geom_boxplot(fill = "skyblue", color = "blue") +
  labs(x = "Fibrosis", y = "Colesterol") +
  ggtitle("Boxplot de Colesterol según Fibrosis")

variable <- "Colesterol"  
summary_stats <- compute_summary_stats(datos, fibrosis, !!as.name(variable))
kable(summary_stats, caption = "Resumen Colesterol")
Resumen Colesterol
fibrosis Q1 median Q3 min max outliers
ausencia 162.00 184.0 202.00 20 337 20, 337, 264, 85, 296, 88
importante 135.25 172.0 179.50 92 245
leve 161.00 182.5 208.75 82 316 291, 316, 82
moderada 148.25 174.0 203.00 88 270

``

#boxplot
ggplot(datos, aes(x = fibrosis, y = Triglicéridos))+
  geom_boxplot(fill = "skyblue", color = "blue") +
  labs(x = "Fibrosis", y = "Triglicéridos") +
  ggtitle("Boxplot de Triglicéridos según Fibrosis")

variable <- "Triglicéridos"  
summary_stats <- compute_summary_stats(datos, fibrosis, !!as.name(variable))
kable(summary_stats, caption = "Resumen Triglicéridos")
Resumen Triglicéridos
fibrosis Q1 median Q3 min max outliers
ausencia 106.00 134 199.00 49.0 591 343, 591, 427, 447, 344
importante 131.75 160 194.00 50.0 448 428, 448
leve 102.25 125 181.00 7.5 465 465, 351, 419, 365, 375, 326
moderada 99.25 152 204.75 56.0 344

``

#boxplot
ggplot(datos, aes(x = fibrosis, y = GOT)) +
  geom_boxplot(fill = "skyblue", color = "blue") +
  labs(x = "Fibrosis", y = "GOT") +
  ggtitle("Boxplot de GOT según Fibrosis")

variable <- "GOT"  
summary_stats <- compute_summary_stats(datos, fibrosis, !!as.name(variable))
kable(summary_stats, caption = "Resumen GOT")
Resumen GOT
fibrosis Q1 median Q3 min max outliers
ausencia 27.0 40.0 64.00 13 309 173, 136, 217, 120, 195, 139, 309, 144, 208, 130, 172, 136
importante 79.5 116.5 156.00 40 524 313, 524, 360
leve 44.5 62.5 116.75 13 331 331, 239, 241, 228
moderada 53.0 102.5 184.25 21 752 752, 407, 518, 583, 572

``

#boxplot
ggplot(datos, aes(x = fibrosis, y = GPT )) +
  geom_boxplot(fill = "skyblue", color = "blue") +
  labs(x = "Fibrosis", y = "GPT") +
  ggtitle("Boxplot de GPT según Fibrosis")

variable <- "GPT"  
summary_stats <- compute_summary_stats(datos, fibrosis, !!as.name(variable))
kable(summary_stats, caption = "Resumen GPT")
Resumen GPT
fibrosis Q1 median Q3 min max outliers
ausencia 36.00 60.0 97.00 19 350 202, 350, 226, 283, 315, 283, 309, 347, 278, 245
importante 106.25 143.0 236.75 31 589 589, 479
leve 60.75 95.5 149.50 16 568 568, 295, 446, 446, 328, 311, 337, 296, 358, 374
moderada 66.75 116.5 255.25 20 766 596, 766, 570

``

#boxplot
ggplot(datos, aes(x = fibrosis, y = GGT)) +
  geom_boxplot(fill = "skyblue", color = "blue") +
  labs(x = "Fibrosis", y = "GGT") +
  ggtitle("Boxplot de GGT según Fibrosis")

variable <- "GGT"  
summary_stats <- compute_summary_stats(datos, fibrosis, !!as.name(variable))
kable(summary_stats, caption = "Resumen GGT")
Resumen GGT
fibrosis Q1 median Q3 min max outliers
ausencia 31.00 57.0 91.00 13 696 315, 411, 296, 188, 368, 351, 182, 355, 369, 696, 379, 272
importante 51.25 73.5 122.75 19 176
leve 45.25 85.5 179.75 14 1884 807, 524, 719, 477, 1884, 531, 428, 642, 383, 423, 467
moderada 34.00 93.0 179.00 12 628 415, 628
#boxplot
ggplot(datos, aes(x = fibrosis, y = Fosfatasa.Alcalina)) +
  geom_boxplot(fill = "skyblue", color = "blue") +
  labs(x = "Fibrosis", y = "Fosfatasa Alcalina") +
  ggtitle("Boxplot de Fosfatasa Alcalina según Fibrosis")

variable <- "Fosfatasa.Alcalina"  
summary_stats <- compute_summary_stats(datos, fibrosis, !!as.name(variable))
kable(summary_stats, caption = "Resumen Fosfatasa Alcalina")
Resumen Fosfatasa Alcalina
fibrosis Q1 median Q3 min max outliers
ausencia 67.0 83.0 110.00 32 492 190, 182, 258, 236, 492, 182, 350
importante 97.5 109.0 151.75 63 213
leve 72.5 97.5 129.50 27 414 318, 275, 284, 414, 248, 243
moderada 76.5 101.5 130.50 48 260 260, 236, 231
#boxplot
ggplot(datos, aes(x = fibrosis, y = bilirrubina.total)) +
  geom_boxplot(fill = "skyblue", color = "blue") +
  labs(x = "Fibrosis", y = "Bilirrubina Total") +
  ggtitle("Boxplot de Bilirrubina Total según Fibrosis")

variable <- "bilirrubina.total"  
summary_stats <- compute_summary_stats(datos, fibrosis, !!as.name(variable))
kable(summary_stats, caption = "Resumen Bilirrubina Total")
Resumen Bilirrubina Total
fibrosis Q1 median Q3 min max outliers
ausencia 0.700 0.92 1.2000 0.30 3.2 2, 2, 3.2, 3.1
importante 0.700 1.00 1.5975 0.50 4.0 3.8, 4, 3.9
leve 0.700 1.00 1.4000 0.23 6.9 2.9, 2.5, 6.9, 2.6, 2.6, 3.4, 2.8, 5.9
moderada 0.675 0.93 1.3250 0.40 8.3 2.5, 3.24, 8.3
#boxplot
ggplot(datos, aes(x = fibrosis, y = proteínas.totales)) +
  geom_boxplot(fill = "skyblue", color = "blue") +
  labs(x = "Fibrosis", y = "Proteínas totales") +
  ggtitle("Boxplot de Proteínas totales según Fibrosis")

variable <- "proteínas.totales"  
summary_stats <- compute_summary_stats(datos, fibrosis, !!as.name(variable))
kable(summary_stats, caption = "Resumen Proteínas Totales")
Resumen Proteínas Totales
fibrosis Q1 median Q3 min max outliers
ausencia 6.700 7.10 7.5 4.6 8.6 4.6, 5.3, 5.4, 5.3
importante 6.950 7.25 7.7 5.7 8.2 5.7
leve 6.725 7.10 7.4 6.2 9.1 9.1, 9
moderada 6.890 7.20 7.6 5.6 8.5 5.6
#boxplot
ggplot(datos, aes(x = fibrosis, y = albúmina)) +
  geom_boxplot(fill = "skyblue", color = "blue") +
  labs(x = "Fibrosis", y = "Albúmina") +
  ggtitle("Boxplot de Albúmina según Fibrosis")

variable <- "albúmina"  
summary_stats <- compute_summary_stats(datos, fibrosis, !!as.name(variable))
kable(summary_stats, caption = "Resumen Albúmina")
Resumen Albúmina
fibrosis Q1 median Q3 min max outliers
ausencia 4.2 4.40 4.600 2.6 7.7 5.3, 3.2, 7.7, 2.7, 2.6
importante 3.5 3.85 4.225 2.9 4.6
leve 4.0 4.30 4.500 3.2 5.0 3.2
moderada 3.7 4.05 4.300 2.9 4.7
#boxplot
ggplot(datos, aes(x = fibrosis, y = sodio)) +
  geom_boxplot(fill = "skyblue", color = "blue") +
  labs(x = "Fibrosis", y = "Sodio") +
  ggtitle("Boxplot de Sodio según Fibrosis")

variable <- "sodio"  
summary_stats <- compute_summary_stats(datos, fibrosis, !!as.name(variable))
kable(summary_stats, caption = "Resumen Sodio")
Resumen Sodio
fibrosis Q1 median Q3 min max outliers
ausencia 138 140 142 128 150 150, 131, 128
importante 138 140 141 128 147 128, 147
leve 138 140 141 133 145 133
moderada 137 139 141 132 145
#boxplot
ggplot(datos, aes(x = fibrosis, y = potasio)) +
  geom_boxplot(fill = "skyblue", color = "blue") +
  labs(x = "Fibrosis", y = "Potasio") +
  ggtitle("Boxplot de Potasio según Fibrosis")

variable <- "potasio"  
summary_stats <- compute_summary_stats(datos, fibrosis, !!as.name(variable))
kable(summary_stats, caption = "Resumen Potasio")
Resumen Potasio
fibrosis Q1 median Q3 min max outliers
ausencia 4.3 4.60 4.800 3.6 6.0 5.9, 6, 5.8, 5.6
importante 4.1 4.45 4.725 3.4 5.4
leve 4.3 4.50 4.700 3.5 6.0 6, 5.5, 3.6, 5.5, 5.6, 3.5, 5.5, 5.6
moderada 4.2 4.40 4.800 3.8 6.0 6, 5.8
#boxplot
ggplot(datos, aes(x = fibrosis, y = leucocitos)) +
  geom_boxplot(fill = "skyblue", color = "blue") +
  labs(x = "Fibrosis", y = "Leucocitos") +
  ggtitle("Boxplot de Leucocitos según Fibrosis")

variable <- "leucocitos"  
summary_stats <- compute_summary_stats(datos, fibrosis, !!as.name(variable))
kable(summary_stats, caption = "Resumen Leucocitos")
Resumen Leucocitos
fibrosis Q1 median Q3 min max outliers
ausencia 4430.0 5650 7000.0 2440 12640 11610, 11010, 12640
importante 3307.5 4795 6837.5 1980 11240
leve 4217.5 5540 6657.5 2240 11950 11950, 11090, 10420, 10490
moderada 3695.0 4520 6085.0 1700 8690
#boxplot
ggplot(datos, aes(x = fibrosis, y = hematocrito)) +
  geom_boxplot(fill = "skyblue", color = "blue") +
  labs(x = "Fibrosis", y = "Hematocrito") +
  ggtitle("Boxplot de Hematocrito según Fibrosis")

variable <- "hematocrito"  
summary_stats <- compute_summary_stats(datos, fibrosis, !!as.name(variable))
kable(summary_stats, caption = "Resumen Hematocrito")
Resumen Hematocrito
fibrosis Q1 median Q3 min max outliers
ausencia 38.00 41 45.00 24.0 55 24
importante 37.75 41 45.00 30.0 47
leve 39.00 42 44.55 31.8 57 56.8, 57
moderada 37.90 40 43.00 31.0 53 53
#boxplot
ggplot(datos, aes(x = fibrosis, y = plaquetas)) +
  geom_boxplot(fill = "skyblue", color = "blue") +
  labs(x = "Fibrosis", y = "Plaquetas") +
  ggtitle("Boxplot de Plaquetas según Fibrosis")

variable <- "plaquetas"  
summary_stats <- compute_summary_stats(datos, fibrosis, !!as.name(variable))
kable(summary_stats, caption = "Resumen Plaquetas")
Resumen Plaquetas
fibrosis Q1 median Q3 min max outliers
ausencia 112000 140000 168000 10000 261000 261000, 10000, 258000
importante 81500 103000 124500 14000 229000 229000
leve 116000 149500 175000 35000 259000
moderada 91750 135500 162750 42000 297000 297000
#boxplot
ggplot(datos, aes(x = fibrosis, y = Índice.de.Quick)) +
  geom_boxplot(fill = "skyblue", color = "blue") +
  labs(x = "Fibrosis", y = "Índice de Quick") +
  ggtitle("Boxplot de Índice de Quick según Fibrosis")

variable <- "Índice.de.Quick"  
summary_stats <- compute_summary_stats(datos, fibrosis, !!as.name(variable))
kable(summary_stats, caption = "Resumen índice de Quick")
Resumen índice de Quick
fibrosis Q1 median Q3 min max outliers
ausencia 100 100.0 100.0 53 118 84, 103, 99, 99, 96, 98, 99, 102, 95, 96, 90, 92, 78, 96, 80, 99, 96, 70, 90, 98, 98, 84, 88, 95, 98, 53, 80, 86, 99, 118, 90, 94, 77.7, 94
importante 76 86.5 98.5 45 100
leve 98 100.0 100.0 71 100 76, 92, 92, 87, 93, 94, 90, 83, 94, 92, 85, 94, 76, 87, 89, 86, 90, 71, 86
moderada 90 98.5 100.0 53 100 53, 63, 56, 60
#boxplot
datos_sin_na_nan <- datos[!is.na(datos$fibrinógeno) & !is.nan(datos$fibrinógeno), ]
ggplot(datos_sin_na_nan, aes(x = fibrosis, y = fibrinógeno)) +
  geom_boxplot(fill = "skyblue", color = "blue") +
  labs(x = "Fibrosis", y = "Fibrinógeno") +
  ggtitle("Boxplot de Fibrinógeno según Fibrosis")

variable <- "fibrinógeno"  
summary_stats <- compute_summary_stats(datos_sin_na_nan, fibrosis, !!as.name(variable))
kable(summary_stats, caption = "Resumen Fibrinógeno")
Resumen Fibrinógeno
fibrosis Q1 median Q3 min max outliers
ausencia 240 276.0 312.00 163 610 438, 458, 531, 538, 455, 610
importante 196 230.0 258.75 143 387 387
leve 227 274.0 324.00 125 471 471
moderada 217 265.5 298.25 123 399
tabla_frecuencia_agrupada <- function(datos) {
 # Calcular frecuencia absoluta para la variable "datos"
  frecuencia_absoluta <- table(datos)
  
  # Calcular la frecuencia relativa
  frecuencia_relativa <- prop.table(frecuencia_absoluta)
  
  # Calcular la frecuencia porcentual
  frecuencia_porcentual <- frecuencia_relativa * 100
  
  # Calcular la frecuencia absoluta acumulada
  frecuencia_acumulada <- cumsum(frecuencia_absoluta)
  
  # Calcular la frecuencia relativa acumulada
  frecuencia_relativa_acumulada <- cumsum(frecuencia_relativa)
  
  # Calcular la frecuencia porcentual acumulada
  frecuencia_porcentual_acumulada <- cumsum(frecuencia_porcentual)

  # Crear el dataframe con los resultados
  tabla_resultado <- data.frame(
    Frecuencia_Absoluta = c(frecuencia_absoluta),
    Frecuencia_Relativa = c(frecuencia_relativa),
    Frecuencia_Porcentual = c(frecuencia_porcentual),
    Frecuencia_Absoluta_Acumulada = c(frecuencia_acumulada),
    Frecuencia_Relativa_Acumulada = c(frecuencia_relativa_acumulada),
    Frecuencia_Porcentual_Acumulada = c(frecuencia_porcentual_acumulada)
  )
    tabla_resultado <- tabla_resultado[, !grepl(".frecuencias", colnames(tabla_resultado))]
  
    colnames(tabla_resultado) <- c("Frecuencia Absoluta", 
                                 "Frecuencia Relativa", 
                                 "Frecuencia Porcentual", 
                                 "Frecuencia Absoluta Acumulada", 
                                 "Frecuencia Relativa Acumulada", 
                                 "Frecuencia Porcentual Acumulada")

  return(tabla_resultado)
}

# Ejemplo de uso de la función con la variable "género"
resultado <- tabla_frecuencia_agrupada(datos$genero)

# Imprimir el resultado
kable(resultado)
Frecuencia Absoluta Frecuencia Relativa Frecuencia Porcentual Frecuencia Absoluta Acumulada Frecuencia Relativa Acumulada Frecuencia Porcentual Acumulada
Hombre 173 0.5356037 53.56037 173 0.5356037 53.56037
Mujer 150 0.4643963 46.43963 323 1.0000000 100.00000
tabla_frecuencia_agrupada <- function(datos) {
 # Calcular frecuencia absoluta para la variable "datos"
  frecuencia_absoluta <- table(datos)
  
  # Calcular la frecuencia relativa
  frecuencia_relativa <- prop.table(frecuencia_absoluta)
  
  # Calcular la frecuencia porcentual
  frecuencia_porcentual <- frecuencia_relativa * 100
  
  # Calcular la frecuencia absoluta acumulada
  frecuencia_acumulada <- cumsum(frecuencia_absoluta)
  
  # Calcular la frecuencia relativa acumulada
  frecuencia_relativa_acumulada <- cumsum(frecuencia_relativa)
  
  # Calcular la frecuencia porcentual acumulada
  frecuencia_porcentual_acumulada <- cumsum(frecuencia_porcentual)

  # Crear el dataframe con los resultados
  tabla_resultado <- data.frame(
    Frecuencia_Absoluta = c(frecuencia_absoluta),
    Frecuencia_Relativa = c(frecuencia_relativa),
    Frecuencia_Porcentual = c(frecuencia_porcentual),
    Frecuencia_Absoluta_Acumulada = c(frecuencia_acumulada),
    Frecuencia_Relativa_Acumulada = c(frecuencia_relativa_acumulada),
    Frecuencia_Porcentual_Acumulada = c(frecuencia_porcentual_acumulada)
  )
    tabla_resultado <- tabla_resultado[, !grepl(".frecuencias", colnames(tabla_resultado))]
  
    colnames(tabla_resultado) <- c("Frecuencia Absoluta", 
                                 "Frecuencia Relativa", 
                                 "Frecuencia Porcentual", 
                                 "Frecuencia Absoluta Acumulada", 
                                 "Frecuencia Relativa Acumulada", 
                                 "Frecuencia Porcentual Acumulada")

  return(tabla_resultado)
}

# Ejemplo de uso de la función con la variable "género"
resultado <- tabla_frecuencia_agrupada(datos$fibrosis)

# Imprimir el resultado
kable(resultado)
Frecuencia Absoluta Frecuencia Relativa Frecuencia Porcentual Frecuencia Absoluta Acumulada Frecuencia Relativa Acumulada Frecuencia Porcentual Acumulada
ausencia 141 0.4365325 43.65325 141 0.4365325 43.65325
importante 20 0.0619195 6.19195 161 0.4984520 49.84520
leve 110 0.3405573 34.05573 271 0.8390093 83.90093
moderada 52 0.1609907 16.09907 323 1.0000000 100.00000
#dispersión para Glucemia
Glucemia.GRAPH <- ggplot(datos, aes(x = fibrosis, y = Glucemia, color = fibrosis)) +
  geom_point(alpha = 0.7, size = 3) +
  labs(x = "Categoría de Fibrosis", y = "Glucemia", color = "Categoría de Fibrosis", title = "Comparación de Glucemia por categoría de fibrosis") +
  theme_minimal()

#dispersión para Urea
Urea.GRAPH <- ggplot(datos, aes(x = fibrosis, y = Urea, color = fibrosis)) +
  geom_point(alpha = 0.7, size = 3) +
  labs(x = "Categoría de Fibrosis", y = "Urea", color = "Categoría de Fibrosis", title = "Comparación de Urea por categoría de fibrosis") +
  theme_minimal()

#dispersión para Creatinina 
Creatinina.GRAPH <- ggplot(datos, aes(x = fibrosis, y = Creatinina, color = fibrosis)) +
  geom_point(alpha = 0.7, size = 3) +
  labs(x = "Categoría de Fibrosis", y = "Creatinina", color = "Categoría de Fibrosis", title = "Comparación de Creatinina por categoría de fibrosis") +
  theme_minimal()

#dispersión para Colesterol 
Colesterol.GRAPH <- ggplot(datos, aes(x = fibrosis, y = Colesterol, color = fibrosis)) +
  geom_point(alpha = 0.7, size = 3) +
  labs(x = "Categoría de Fibrosis", y = "Colesterol", color = "Categoría de Fibrosis", title = "Comparación de Colesterol por categoría de fibrosis") +
  theme_minimal()

#dispersión para Triglicéridos
Triglicéridos.GRAPH <- ggplot(datos, aes(x = fibrosis, y = Triglicéridos, color = fibrosis)) +
  geom_point(alpha = 0.7, size = 3) +
  labs(x = "Categoría de Fibrosis", y = "Triglicéridos", color = "Categoría de Fibrosis", title = "Comparación de Triglicéridos por categoría de fibrosis") +
  theme_minimal()

#dispersión para GOT
GOT.GRAPH <- ggplot(datos, aes(x = fibrosis, y = GOT, color = fibrosis)) +
  geom_point(alpha = 0.7, size = 3) +
  labs(x = "Categoría de Fibrosis", y = "GOT", color = "Categoría de Fibrosis", title = "Comparación de GOT por categoría de fibrosis") +
  theme_minimal()

#dispersión para GPT
GPT.GRAPH <-ggplot(datos, aes(x = fibrosis, y = GPT, color = fibrosis)) +
  geom_point(alpha = 0.7, size = 3) +
  labs(x = "Categoría de Fibrosis", y = "GPT", color = "Categoría de Fibrosis", title = "Comparación de GPT por categoría de fibrosis") +
  theme_minimal()

#dispersión para GGT
GGT.GRAPH <- ggplot(datos, aes(x = fibrosis, y = GGT, color = fibrosis)) +
  geom_point(alpha = 0.7, size = 3) +
  labs(x = "Categoría de Fibrosis", y = "GGT", color = "Categoría de Fibrosis", title = "Comparación de GGT por categoría de fibrosis") +
  theme_minimal()

#dispersión para Fosfatasa Alcalina  
Fosfatasa.Alcalina.GRAPH <- ggplot(datos, aes(x = fibrosis, y = Fosfatasa.Alcalina, color = fibrosis)) +
  geom_point(alpha = 0.7, size = 3) +
  labs(x = "Categoría de Fibrosis", y = "Fosfatasa Alcalina", color = "Categoría de Fibrosis", title = "Comparación de Fosfatasa Alcalina por categoría de fibrosis") +
  theme_minimal()

#dispersión para bilirrubina total
bilirrubina.total.GRAPH <- ggplot(datos, aes(x = fibrosis, y = bilirrubina.total, color = fibrosis)) +
  geom_point(alpha = 0.7, size = 3) +
  labs(x = "Categoría de Fibrosis", y = "Bilirrubina total", color = "Categoría de Fibrosis", title = "Comparación de Bilirrubina total por categoría de fibrosis") +
  theme_minimal()

#dispersión para proteínas totales  
proteínas.totales.GRAPH <- ggplot(datos, aes(x = fibrosis, y = proteínas.totales, color = fibrosis)) +
  geom_point(alpha = 0.7, size = 3) +
  labs(x = "Categoría de Fibrosis", y = "Proteínas totales", color = "Categoría de Fibrosis", title = "Comparación de Proteínas totales por categoría de fibrosis") +
  theme_minimal()

#dispersión para albúmina
albúmina.GRAPH <- ggplot(datos, aes(x = fibrosis, y = albúmina, color = fibrosis)) +
  geom_point(alpha = 0.7, size = 3) +
  labs(x = "Categoría de Fibrosis", y = "Albúmina", color = "Categoría de Fibrosis", title = "Comparación de Albúmina por categoría de fibrosis") +
  theme_minimal()

#dispersión para sodio
sodio.GRAPH <- ggplot(datos, aes(x = fibrosis, y = sodio, color = fibrosis)) +
  geom_point(alpha = 0.7, size = 3) +
  labs(x = "Categoría de Fibrosis", y = "Sodio", color = "Categoría de Fibrosis", title = "Comparación de Sodio por categoría de fibrosis") +
  theme_minimal()

#dispersión para Potasio
potasio.GRAPH <- ggplot(datos, aes(x = fibrosis, y = potasio, color = fibrosis)) +
  geom_point(alpha = 0.7, size = 3) +
  labs(x = "Categoría de Fibrosis", y = "Potasio", color = "Categoría de Fibrosis", title = "Comparación de Potasio por categoría de fibrosis") +
  theme_minimal()

#dispersión para leucocitos
leucocitos.GRAPH <- ggplot(datos, aes(x = fibrosis, y = leucocitos, color = fibrosis)) +
  geom_point(alpha = 0.7, size = 3) +
  labs(x = "Categoría de Fibrosis", y = "Leucocitos", color = "Categoría de Fibrosis", title = "Comparación de Leucocitos por categoría de fibrosis") +
  theme_minimal()

#dispersión para Hematocrito    
hematocrito.GRAPH <- ggplot(datos, aes(x = fibrosis, y = hematocrito, color = fibrosis)) +
  geom_point(alpha = 0.7, size = 3) +
  labs(x = "Categoría de Fibrosis", y = "Hematocrito    ", color = "Categoría de Fibrosis", title = "Comparación de Hematocrito por categoría de fibrosis") +
  theme_minimal()

#dispersión para plaquetas
plaquetas.GRAPH <- ggplot(datos, aes(x = fibrosis, y = plaquetas, color = fibrosis)) +
  geom_point(alpha = 0.7, size = 3) +
  labs(x = "Categoría de Fibrosis", y = "Plaquetas", color = "Categoría de Fibrosis", title = "Comparación de Plaquetas por categoría de fibrosis") +
  theme_minimal()

#dispersión para Índice de Quick
Índice.de.Quick.GRAPH <- ggplot(datos, aes(x = fibrosis, y = Índice.de.Quick, color = fibrosis)) +
  geom_point(alpha = 0.7, size = 3) +
  labs(x = "Categoría de Fibrosis", y = "Índice de Quick", color = "Categoría de Fibrosis", title = "Comparación de Índice de Quick por categoría de fibrosis") +
  theme_minimal()

#dispersión para fibrinógeno
fibrinógeno.GRAPH <- ggplot(datos, aes(x = fibrosis, y = fibrinógeno, color = fibrosis)) +
  geom_point(alpha = 0.7, size = 3) +
  labs(x = "Categoría de Fibrosis", y = "Fibrinógeno", color = "Categoría de Fibrosis", title = "Comparación de Fibrinógeno por categoría de fibrosis") +
  theme_minimal()


print(Glucemia.GRAPH)

print(Urea.GRAPH)

print(Creatinina.GRAPH)

print(Colesterol.GRAPH)

print(Triglicéridos.GRAPH)

print(GOT.GRAPH)

print(GPT.GRAPH)

print(GGT.GRAPH)

print(Fosfatasa.Alcalina.GRAPH)

print(bilirrubina.total.GRAPH)

print(proteínas.totales.GRAPH)

print(albúmina.GRAPH)

print(sodio.GRAPH)

print(potasio.GRAPH)

print(leucocitos.GRAPH)

print(plaquetas.GRAPH)

print(Índice.de.Quick.GRAPH)

print(fibrinógeno.GRAPH)
## Warning: Removed 1 row containing missing values or values outside the scale range
## (`geom_point()`).

ggplot() +
  geom_point(datos, mapping=aes(x=Individuo, y= Glucemia, color = genero)) +
  facet_wrap(~ fibrosis)

ggplot() +
  geom_point(datos, mapping=aes(x=Individuo, y= Urea, color = genero)) +
  facet_wrap(~ fibrosis)

ggplot() +
  geom_point(datos, mapping=aes(x=Individuo, y= Creatinina, color = genero)) +
  facet_wrap(~ fibrosis)

ggplot() +
  geom_point(datos, mapping=aes(x=Individuo, y= Colesterol, color = genero)) +
  facet_wrap(~ fibrosis)

ggplot() +
  geom_point(datos, mapping=aes(x=Individuo, y= Triglicéridos, color = genero)) +
  facet_wrap(~ fibrosis)

ggplot() +
  geom_point(datos, mapping=aes(x=Individuo, y= GOT, color = genero)) +
  facet_wrap(~ fibrosis)

ggplot() +
  geom_point(datos, mapping=aes(x=Individuo, y= GPT, color = genero)) +
  facet_wrap(~ fibrosis)

ggplot() +
  geom_point(datos, mapping=aes(x=Individuo, y= GGT, color = genero)) +
  facet_wrap(~ fibrosis)

ggplot() +
  geom_point(datos, mapping=aes(x=Individuo, y= Fosfatasa.Alcalina, color = genero)) +
  facet_wrap(~ fibrosis)

ggplot() +
  geom_point(datos, mapping=aes(x=Individuo, y= bilirrubina.total, color = genero)) +
  facet_wrap(~ fibrosis)

ggplot() +
  geom_point(datos, mapping=aes(x=Individuo, y= proteínas.totales, color = genero)) +
  facet_wrap(~ fibrosis)

ggplot() +
  geom_point(datos, mapping=aes(x=Individuo, y= albúmina, color = genero)) +
  facet_wrap(~ fibrosis)

ggplot() +
  geom_point(datos, mapping=aes(x=Individuo, y= sodio, color = genero)) +
  facet_wrap(~ fibrosis)

ggplot() +
  geom_point(datos, mapping=aes(x=Individuo, y= potasio, color = genero)) +
  facet_wrap(~ fibrosis)

ggplot() +
  geom_point(datos, mapping=aes(x=Individuo, y= leucocitos, color = genero)) +
  facet_wrap(~ fibrosis)

ggplot() +
  geom_point(datos, mapping=aes(x=Individuo, y= hematocrito, color = genero)) +
  facet_wrap(~ fibrosis)

ggplot() +
  geom_point(datos, mapping=aes(x=Individuo, y= plaquetas, color = genero)) +
  facet_wrap(~ fibrosis)

ggplot() +
  geom_point(datos, mapping=aes(x=Individuo, y= Índice.de.Quick, color = genero)) +
  facet_wrap(~ fibrosis)

ggplot() +
  geom_point(datos, mapping=aes(x=Individuo, y= fibrinógeno, color = genero)) +
  facet_wrap(~ fibrosis)
## Warning: Removed 1 row containing missing values or values outside the scale range
## (`geom_point()`).

ggplot(datos, aes(x=Individuo, y= proteínas.totales, color= bilirrubina.total)) +
  geom_point() +
  facet_wrap(~fibrosis) +
  scale_color_gradient(low = "blue", high = "red") 

ggplot(datos, aes( x= Colesterol, y = Triglicéridos, color = Colesterol)) +
  geom_point() +
  facet_wrap(~fibrosis) +
  scale_color_gradient(low = "blue", high = "red") 

ggplot(datos, aes( x= Índice.de.Quick, y = fibrinógeno, color = Índice.de.Quick)) +
  geom_point() +
  facet_wrap(~fibrosis) +
  scale_color_gradient(low = "blue", high = "red") 
## Warning: Removed 1 row containing missing values or values outside the scale range
## (`geom_point()`).

tablafrec <- function(datos, variable, nombre_variable = NULL) {
  TF <- as.data.frame(table(cut(datos[[variable]], breaks = 10)))
  tablafrec <- transform(TF,
                         FreqAc = cumsum(Freq),
                         Rel = round(prop.table(Freq), 2),
                         RelAc = round(cumsum(prop.table(Freq)), 2),
                         FreqPer = round(prop.table(Freq), 2) * 100,
                         FreqPerAc = round(cumsum(prop.table(Freq)), 2) * 100
  )
  if (!is.null(nombre_variable)) {
    names(tablafrec)[1] <- nombre_variable
  }
  return(tablafrec)
}
Glusemia <- datos$Glucemia
h <- hist(Glusemia,  xlim=c(0,400), ylim=c(0,200), col="darkseagreen1", main="Histograma Glusemia")
text(h$mids, h$counts, labels=h$counts, adj=c(0.5, -0.5))

Urea <- datos$Urea
h <- hist(Urea, xlim=c(0,190), ylim=c(0,200), col="darkseagreen2", main="Histograma Urea")
eje_x <- seq(0, 200, by = 20) 
axis(1, at = eje_x)
#etiquetas 
text(h$mids, h$counts, labels=h$counts, adj=c(0.5, -0.5))

Creatinina <- datos$Creatinina
h <- hist(Creatinina, xlim=c(0,10), ylim=c(0,200), col="darkseagreen2", main="Histograma Creatinina")
eje_x <- seq(0, 10) 
axis(1, at = eje_x)
#etiquetas 
text(h$mids, h$counts, labels=h$counts, adj=c(0.5, -0.5))

Colesterol <- datos$Colesterol
h <- hist(Colesterol, xlim=c(0,350), ylim=c(0,200), col="darkseagreen2", main="Histograma Colesterol")
#etiquetas 
text(h$mids, h$counts, labels=h$counts, adj=c(0.5, -0.5))

Triglicéridos <- datos$Triglicéridos
h <- hist(Triglicéridos, xlim=c(0,600), ylim=c(0,120), col="darkseagreen2", main="Histograma Triglicéridos")
#etiquetas 
text(h$mids, h$counts, labels=h$counts, adj=c(0.5, -0.5))

GOT <- datos$GOT
h <- hist(GOT, xlim=c(0,800), ylim=c(0,250), col="darkseagreen2", main="Histograma GOT")
#etiquetas 
text(h$mids, h$counts, labels=h$counts, adj=c(0.5, -0.5))

GPT <- datos$GPT
h <- hist(GPT, xlim=c(0,800), ylim=c(0,200), col="darkseagreen2", main="Histograma GPT")
#etiquetas 
text(h$mids, h$counts, labels=h$counts, adj=c(0.5, -0.5))

GGT <- datos$GGT
h <- hist(GGT, xlim=c(0,2000), ylim=c(0,300), col="darkseagreen2", main="Histograma GGT")
#etiquetas 
text(h$mids, h$counts, labels=h$counts, adj=c(0.5, -0.5))

Fosfatasa.Alcalina <- datos$Fosfatasa.Alcalina
h <- hist(Fosfatasa.Alcalina, xlim=c(0,500), ylim=c(0,200), col="darkseagreen2", main="Histograma Fosfatasa Alcalina")
#etiquetas 
text(h$mids, h$counts, labels=h$counts, adj=c(0.5, -0.5))

bilirrubina.total <- datos$bilirrubina.total
intervalos <- seq(0, 10, by = 0.5)
h <- hist(bilirrubina.total, breaks = intervalos, xlim=c(0.2,10), ylim=c(0,200), col="darkseagreen2", main="Histograma Bilirrubina total")
#etiquetas 
text(h$mids, h$counts, labels=h$counts, adj=c(0.5, -0.5))

proteínas.totales <- datos$proteínas.totales
h <- hist(proteínas.totales, xlim=c(4.5,9.5), ylim=c(0,120), col="darkseagreen2", main="Histograma Proteínas totales")
#etiquetas 
text(h$mids, h$counts, labels=h$counts, adj=c(0.5, -0.5))

albúmina <- datos$albúmina
h <- hist(albúmina, xlim=c(2,8), ylim=c(0,200), col="darkseagreen2", main="Histograma Albúmina")
#etiquetas 
text(h$mids, h$counts, labels=h$counts, adj=c(0.5, -0.5))

sodio <- datos$sodio
h <- hist(sodio, xlim=c(125,150), ylim=c(0,120), col="darkseagreen2", main="Histograma Sodio")
#etiquetas 
text(h$mids, h$counts, labels=h$counts, adj=c(0.5, -0.5))

potasio <- datos$potasio
h <- hist(potasio, xlim=c(3,6), ylim=c(0,80), col="darkseagreen2", main="Histograma Potasio")
#etiquetas 
text(h$mids, h$counts, labels=h$counts, adj=c(0.5, -0.5))

leucocitos <- datos$leucocitos
h <- hist(leucocitos, xlim=c(1500, 12750), ylim=c(0,80), col="darkseagreen2", main="Histograma Leucocitos")
#etiquetas 
text(h$mids, h$counts, labels=h$counts, adj=c(0.5, -0.5))

hematocrito <- datos$hematocrito
h <- hist(hematocrito, xlim=c(20,60), ylim=c(0,130), col="darkseagreen2", main="Histograma Hematocrito")
#etiquetas 
text(h$mids, h$counts, labels=h$counts, adj=c(0.5, -0.5))

plaquetas <- datos$plaquetas

h <- hist(plaquetas, xlim=c(10000,300000), ylim=c(0,150), col="darkseagreen2", main="Histograma Plaquetas")
#etiquetas 
text(h$mids, h$counts, labels=h$counts, adj=c(0.5, -0.5))

Índice.de.Quick <- datos$Índice.de.Quick
h <- hist(Índice.de.Quick, xlim=c(40,120), ylim=c(0,300), col="darkseagreen2", main="Histograma Índice de Quick")
#etiquetas 
text(h$mids, h$counts, labels=h$counts, adj=c(0.5, -0.5))

fibrinógeno <- datos$fibrinógeno
h <- hist(fibrinógeno, xlim=c(120,620), ylim=c(0,120), col="darkseagreen2", main="Histograma Fibrinógeno")
#etiquetas 
text(h$mids, h$counts, labels=h$counts, adj=c(0.5, -0.5))

TFUrea <- as.data.frame(table(Urea = cut(datos$Urea, breaks = 10)))

TFUrea <- transform(TFUrea,
                    FreqAc = cumsum(Freq),
                    Rel = round(prop.table(Freq), 2),
                    RelAc = round(cumsum(prop.table(Freq)), 2)
)
kable(TFUrea)
Urea Freq FreqAc Rel RelAc
(10.8,27.3] 132 132 0.41 0.41
(27.3,43.6] 111 243 0.34 0.75
(43.6,59.9] 54 297 0.17 0.92
(59.9,76.2] 21 318 0.07 0.98
(76.2,92.5] 3 321 0.01 0.99
(92.5,109] 1 322 0.00 1.00
(109,125] 0 322 0.00 1.00
(125,141] 0 322 0.00 1.00
(141,158] 0 322 0.00 1.00
(158,174] 1 323 0.00 1.00
#Tabla de Frecuencia
Tabla.frec <- function(datos, variable, num_breaks = 10) {
  Variable <- as.data.frame(table(Var = cut(datos[[variable]], breaks = num_breaks)))
  
  Variable <- transform(Variable,
                          Rel = round(prop.table(Freq), 3),
                          Rel.per = round(prop.table(Freq) * 100, 3),
                          FreqAc = cumsum(Freq),
                          RelAc = round(cumsum(prop.table(Freq)), 3),
                          Freq.PerAc = round(cumsum(prop.table(Freq) * 100), 3) 
                        
  )

  return(Variable)
}
resultados <- Tabla.frec(datos, "Glucemia")
kable(resultados,  caption = "Tabla de frecuencia Glucemia")
Tabla de frecuencia Glucemia
Var Freq Rel Rel.per FreqAc RelAc Freq.PerAc
(13.7,47.8] 2 0.006 0.619 2 0.006 0.619
(47.8,81.6] 37 0.115 11.455 39 0.121 12.074
(81.6,115] 188 0.582 58.204 227 0.703 70.279
(115,149] 58 0.180 17.957 285 0.882 88.235
(149,183] 18 0.056 5.573 303 0.938 93.808
(183,217] 8 0.025 2.477 311 0.963 96.285
(217,251] 6 0.019 1.858 317 0.981 98.142
(251,284] 3 0.009 0.929 320 0.991 99.071
(284,318] 2 0.006 0.619 322 0.997 99.690
(318,352] 1 0.003 0.310 323 1.000 100.000
resultados <- Tabla.frec(datos, "Urea")
kable(resultados,  caption = "Tabla de frecuencia Urea")
Tabla de frecuencia Urea
Var Freq Rel Rel.per FreqAc RelAc Freq.PerAc
(10.8,27.3] 132 0.409 40.867 132 0.409 40.867
(27.3,43.6] 111 0.344 34.365 243 0.752 75.232
(43.6,59.9] 54 0.167 16.718 297 0.920 91.950
(59.9,76.2] 21 0.065 6.502 318 0.985 98.452
(76.2,92.5] 3 0.009 0.929 321 0.994 99.381
(92.5,109] 1 0.003 0.310 322 0.997 99.690
(109,125] 0 0.000 0.000 322 0.997 99.690
(125,141] 0 0.000 0.000 322 0.997 99.690
(141,158] 0 0.000 0.000 322 0.997 99.690
(158,174] 1 0.003 0.310 323 1.000 100.000
resultados <- Tabla.frec(datos, "Creatinina")
kable(resultados,  caption = "Tabla de frecuencia Creatinina")
Tabla de frecuencia Creatinina
Var Freq Rel Rel.per FreqAc RelAc Freq.PerAc
(0.391,1.3] 238 0.737 73.684 238 0.737 73.684
(1.3,2.2] 79 0.245 24.458 317 0.981 98.142
(2.2,3.1] 4 0.012 1.238 321 0.994 99.381
(3.1,4] 0 0.000 0.000 321 0.994 99.381
(4,4.9] 1 0.003 0.310 322 0.997 99.690
(4.9,5.8] 0 0.000 0.000 322 0.997 99.690
(5.8,6.7] 0 0.000 0.000 322 0.997 99.690
(6.7,7.6] 0 0.000 0.000 322 0.997 99.690
(7.6,8.5] 0 0.000 0.000 322 0.997 99.690
(8.5,9.41] 1 0.003 0.310 323 1.000 100.000
resultados <- Tabla.frec(datos, "Colesterol")
kable(resultados,  caption = "Tabla de frecuencia Colesterol")
Tabla de frecuencia Colesterol
Var Freq Rel Rel.per FreqAc RelAc Freq.PerAc
(19.7,51.7] 1 0.003 0.310 1 0.003 0.310
(51.7,83.4] 1 0.003 0.310 2 0.006 0.619
(83.4,115] 12 0.037 3.715 14 0.043 4.334
(115,147] 42 0.130 13.003 56 0.173 17.337
(147,178] 99 0.307 30.650 155 0.480 47.988
(178,210] 103 0.319 31.889 258 0.799 79.876
(210,242] 41 0.127 12.693 299 0.926 92.570
(242,274] 20 0.062 6.192 319 0.988 98.762
(274,305] 2 0.006 0.619 321 0.994 99.381
(305,337] 2 0.006 0.619 323 1.000 100.000
resultados <- Tabla.frec(datos, "Triglicéridos")
kable(resultados,  caption = "Tabla de frecuencia Triglicéridos")
Tabla de frecuencia Triglicéridos
Var Freq Rel Rel.per FreqAc RelAc Freq.PerAc
(6.92,65.8] 12 0.037 3.715 12 0.037 3.715
(65.8,124] 126 0.390 39.009 138 0.427 42.724
(124,183] 92 0.285 28.483 230 0.712 71.207
(183,241] 50 0.155 15.480 280 0.867 86.687
(241,299] 21 0.065 6.502 301 0.932 93.189
(299,358] 13 0.040 4.025 314 0.972 97.214
(358,416] 2 0.006 0.619 316 0.978 97.833
(416,474] 6 0.019 1.858 322 0.997 99.690
(474,533] 0 0.000 0.000 322 0.997 99.690
(533,592] 1 0.003 0.310 323 1.000 100.000
resultados <- Tabla.frec(datos, "GOT")
kable(resultados,  caption = "Tabla de frecuencia GOT")
Tabla de frecuencia GOT
Var Freq Rel Rel.per FreqAc RelAc Freq.PerAc
(12.3,86.9] 219 0.678 67.802 219 0.678 67.802
(86.9,161] 63 0.195 19.505 282 0.873 87.307
(161,235] 24 0.074 7.430 306 0.947 94.737
(235,309] 5 0.015 1.548 311 0.963 96.285
(309,382] 6 0.019 1.858 317 0.981 98.142
(382,456] 1 0.003 0.310 318 0.985 98.452
(456,530] 2 0.006 0.619 320 0.991 99.071
(530,604] 2 0.006 0.619 322 0.997 99.690
(604,678] 0 0.000 0.000 322 0.997 99.690
(678,753] 1 0.003 0.310 323 1.000 100.000
resultados <- Tabla.frec(datos, "GPT")
kable(resultados,  caption = "Tabla de frecuencia GPT")
Tabla de frecuencia GPT
Var Freq Rel Rel.per FreqAc RelAc Freq.PerAc
(15.2,91] 176 0.545 54.489 176 0.545 54.489
(91,166] 84 0.260 26.006 260 0.805 80.495
(166,241] 24 0.074 7.430 284 0.879 87.926
(241,316] 18 0.056 5.573 302 0.935 93.498
(316,391] 9 0.028 2.786 311 0.963 96.285
(391,466] 5 0.015 1.548 316 0.978 97.833
(466,541] 2 0.006 0.619 318 0.985 98.452
(541,616] 4 0.012 1.238 322 0.997 99.690
(616,691] 0 0.000 0.000 322 0.997 99.690
(691,767] 1 0.003 0.310 323 1.000 100.000
resultados <- Tabla.frec(datos, "GGT")
kable(resultados,  caption = "Tabla de frecuencia GGT")
Tabla de frecuencia GGT
Var Freq Rel Rel.per FreqAc RelAc Freq.PerAc
(10.1,199] 280 0.867 86.687 280 0.867 86.687
(199,386] 29 0.090 8.978 309 0.957 95.666
(386,574] 8 0.025 2.477 317 0.981 98.142
(574,761] 4 0.012 1.238 321 0.994 99.381
(761,948] 1 0.003 0.310 322 0.997 99.690
(948,1.14e+03] 0 0.000 0.000 322 0.997 99.690
(1.14e+03,1.32e+03] 0 0.000 0.000 322 0.997 99.690
(1.32e+03,1.51e+03] 0 0.000 0.000 322 0.997 99.690
(1.51e+03,1.7e+03] 0 0.000 0.000 322 0.997 99.690
(1.7e+03,1.89e+03] 1 0.003 0.310 323 1.000 100.000
resultados <- Tabla.frec(datos, "Fosfatasa.Alcalina")
kable(resultados,  caption = "Tabla de frecuencia Fosfatasa Alcalina")
Tabla de frecuencia Fosfatasa Alcalina
Var Freq Rel Rel.per FreqAc RelAc Freq.PerAc
(26.5,73.5] 94 0.291 29.102 94 0.291 29.102
(73.5,120] 142 0.440 43.963 236 0.731 73.065
(120,166] 57 0.176 17.647 293 0.907 90.712
(166,213] 16 0.050 4.954 309 0.957 95.666
(213,260] 7 0.022 2.167 316 0.978 97.833
(260,306] 3 0.009 0.929 319 0.988 98.762
(306,352] 2 0.006 0.619 321 0.994 99.381
(352,399] 0 0.000 0.000 321 0.994 99.381
(399,446] 1 0.003 0.310 322 0.997 99.690
(446,492] 1 0.003 0.310 323 1.000 100.000
resultados <- Tabla.frec(datos, "bilirrubina.total")
kable(resultados,  caption = "Tabla de frecuencia Bilirrubina total")
Tabla de frecuencia Bilirrubina total
Var Freq Rel Rel.per FreqAc RelAc Freq.PerAc
(0.222,1.04] 184 0.570 56.966 184 0.570 56.966
(1.04,1.84] 109 0.337 33.746 293 0.907 90.712
(1.84,2.65] 18 0.056 5.573 311 0.963 96.285
(2.65,3.46] 6 0.019 1.858 317 0.981 98.142
(3.46,4.27] 3 0.009 0.929 320 0.991 99.071
(4.27,5.07] 0 0.000 0.000 320 0.991 99.071
(5.07,5.88] 0 0.000 0.000 320 0.991 99.071
(5.88,6.69] 1 0.003 0.310 321 0.994 99.381
(6.69,7.49] 1 0.003 0.310 322 0.997 99.690
(7.49,8.31] 1 0.003 0.310 323 1.000 100.000
resultados <- Tabla.frec(datos, "proteínas.totales")
kable(resultados,  caption = "Tabla de frecuencia Proteínas totales")
Tabla de frecuencia Proteínas totales
Var Freq Rel Rel.per FreqAc RelAc Freq.PerAc
(4.6,5.05] 1 0.003 0.310 1 0.003 0.310
(5.05,5.5] 3 0.009 0.929 4 0.012 1.238
(5.5,5.95] 3 0.009 0.929 7 0.022 2.167
(5.95,6.4] 17 0.053 5.263 24 0.074 7.430
(6.4,6.85] 77 0.238 23.839 101 0.313 31.269
(6.85,7.3] 108 0.334 33.437 209 0.647 64.706
(7.3,7.75] 66 0.204 20.433 275 0.851 85.139
(7.75,8.2] 36 0.111 11.146 311 0.963 96.285
(8.2,8.65] 10 0.031 3.096 321 0.994 99.381
(8.65,9.1] 2 0.006 0.619 323 1.000 100.000
resultados <- Tabla.frec(datos, "albúmina")
kable(resultados,  caption = "Tabla de frecuencia Albúmina")
Tabla de frecuencia Albúmina
Var Freq Rel Rel.per FreqAc RelAc Freq.PerAc
(2.59,3.11] 6 0.019 1.858 6 0.019 1.858
(3.11,3.62] 20 0.062 6.192 26 0.080 8.050
(3.62,4.13] 93 0.288 28.793 119 0.368 36.842
(4.13,4.64] 163 0.505 50.464 282 0.873 87.307
(4.64,5.15] 39 0.121 12.074 321 0.994 99.381
(5.15,5.66] 1 0.003 0.310 322 0.997 99.690
(5.66,6.17] 0 0.000 0.000 322 0.997 99.690
(6.17,6.68] 0 0.000 0.000 322 0.997 99.690
(6.68,7.19] 0 0.000 0.000 322 0.997 99.690
(7.19,7.71] 1 0.003 0.310 323 1.000 100.000
resultados <- Tabla.frec(datos, "sodio")
kable(resultados,  caption = "Tabla de frecuencia Sodio")
Tabla de frecuencia Sodio
Var Freq Rel Rel.per FreqAc RelAc Freq.PerAc
(128,130] 2 0.006 0.619 2 0.006 0.619
(130,132] 3 0.009 0.929 5 0.015 1.548
(132,135] 4 0.012 1.238 9 0.028 2.786
(135,137] 30 0.093 9.288 39 0.121 12.074
(137,139] 99 0.307 30.650 138 0.427 42.724
(139,141] 108 0.334 33.437 246 0.762 76.161
(141,143] 43 0.133 13.313 289 0.895 89.474
(143,146] 32 0.099 9.907 321 0.994 99.381
(146,148] 1 0.003 0.310 322 0.997 99.690
(148,150] 1 0.003 0.310 323 1.000 100.000
resultados <- Tabla.frec(datos, "potasio")
kable(resultados,  caption = "Tabla de frecuencia Potasio")
Tabla de frecuencia Potasio
Var Freq Rel Rel.per FreqAc RelAc Freq.PerAc
(3.4,3.66] 4 0.012 1.238 4 0.012 1.238
(3.66,3.92] 21 0.065 6.502 25 0.077 7.740
(3.92,4.18] 33 0.102 10.217 58 0.180 17.957
(4.18,4.44] 85 0.263 26.316 143 0.443 44.272
(4.44,4.7] 89 0.276 27.554 232 0.718 71.827
(4.7,4.96] 42 0.130 13.003 274 0.848 84.830
(4.96,5.22] 27 0.084 8.359 301 0.932 93.189
(5.22,5.48] 8 0.025 2.477 309 0.957 95.666
(5.48,5.74] 8 0.025 2.477 317 0.981 98.142
(5.74,6] 6 0.019 1.858 323 1.000 100.000
resultados <- Tabla.frec(datos, "leucocitos")
kable(resultados,  caption = "Tabla de frecuencia Leucocitos")
Tabla de frecuencia Leucocitos
Var Freq Rel Rel.per FreqAc RelAc Freq.PerAc
(1.69e+03,2.79e+03] 19 0.059 5.882 19 0.059 5.882
(2.79e+03,3.89e+03] 53 0.164 16.409 72 0.223 22.291
(3.89e+03,4.98e+03] 65 0.201 20.124 137 0.424 42.415
(4.98e+03,6.08e+03] 65 0.201 20.124 202 0.625 62.539
(6.08e+03,7.17e+03] 54 0.167 16.718 256 0.793 79.257
(7.17e+03,8.26e+03] 39 0.121 12.074 295 0.913 91.331
(8.26e+03,9.36e+03] 14 0.043 4.334 309 0.957 95.666
(9.36e+03,1.05e+04] 7 0.022 2.167 316 0.978 97.833
(1.05e+04,1.15e+04] 4 0.012 1.238 320 0.991 99.071
(1.15e+04,1.27e+04] 3 0.009 0.929 323 1.000 100.000
resultados <- Tabla.frec(datos, "hematocrito")
kable(resultados,  caption = "Tabla de frecuencia Hematocrito")
Tabla de frecuencia Hematocrito
Var Freq Rel Rel.per FreqAc RelAc Freq.PerAc
(24,27.3] 1 0.003 0.310 1 0.003 0.310
(27.3,30.6] 3 0.009 0.929 4 0.012 1.238
(30.6,33.9] 8 0.025 2.477 12 0.037 3.715
(33.9,37.2] 49 0.152 15.170 61 0.189 18.885
(37.2,40.5] 82 0.254 25.387 143 0.443 44.272
(40.5,43.8] 78 0.241 24.149 221 0.684 68.421
(43.8,47.1] 72 0.223 22.291 293 0.907 90.712
(47.1,50.4] 23 0.071 7.121 316 0.978 97.833
(50.4,53.7] 4 0.012 1.238 320 0.991 99.071
(53.7,57] 3 0.009 0.929 323 1.000 100.000
resultados <- Tabla.frec(datos, "plaquetas")
kable(resultados,  caption = "Tabla de frecuencia Plaquetas")
Tabla de frecuencia Plaquetas
Var Freq Rel Rel.per FreqAc RelAc Freq.PerAc
(9.71e+03,3.87e+04] 3 0.009 0.929 3 0.009 0.929
(3.87e+04,6.74e+04] 12 0.037 3.715 15 0.046 4.644
(6.74e+04,9.61e+04] 35 0.108 10.836 50 0.155 15.480
(9.61e+04,1.25e+05] 80 0.248 24.768 130 0.402 40.248
(1.25e+05,1.54e+05] 69 0.214 21.362 199 0.616 61.610
(1.54e+05,1.82e+05] 68 0.211 21.053 267 0.827 82.663
(1.82e+05,2.11e+05] 31 0.096 9.598 298 0.923 92.260
(2.11e+05,2.4e+05] 15 0.046 4.644 313 0.969 96.904
(2.4e+05,2.68e+05] 9 0.028 2.786 322 0.997 99.690
(2.68e+05,2.97e+05] 1 0.003 0.310 323 1.000 100.000
resultados <- Tabla.frec(datos, "Índice.de.Quick")
kable(resultados,  caption = "Tabla de frecuencia   Índice de Quick")
Tabla de frecuencia Índice de Quick
Var Freq Rel Rel.per FreqAc RelAc Freq.PerAc
(44.9,52.3] 1 0.003 0.310 1 0.003 0.310
(52.3,59.6] 4 0.012 1.238 5 0.015 1.548
(59.6,66.9] 3 0.009 0.929 8 0.025 2.477
(66.9,74.2] 4 0.012 1.238 12 0.037 3.715
(74.2,81.5] 13 0.040 4.025 25 0.077 7.740
(81.5,88.8] 18 0.056 5.573 43 0.133 13.313
(88.8,96.1] 39 0.121 12.074 82 0.254 25.387
(96.1,103] 240 0.743 74.303 322 0.997 99.690
(103,111] 0 0.000 0.000 322 0.997 99.690
(111,118] 1 0.003 0.310 323 1.000 100.000
resultados <- Tabla.frec(datos, "fibrinógeno")
kable(resultados,  caption = "Tabla de frecuencia Fibrinógeno")
Tabla de frecuencia Fibrinógeno
Var Freq Rel Rel.per FreqAc RelAc Freq.PerAc
(123,172] 13 0.040 4.037 13 0.040 4.037
(172,220] 48 0.149 14.907 61 0.189 18.944
(220,269] 98 0.304 30.435 159 0.494 49.379
(269,318] 90 0.280 27.950 249 0.773 77.329
(318,366] 47 0.146 14.596 296 0.919 91.925
(366,415] 15 0.047 4.658 311 0.966 96.584
(415,464] 7 0.022 2.174 318 0.988 98.758
(464,513] 1 0.003 0.311 319 0.991 99.068
(513,561] 2 0.006 0.621 321 0.997 99.689
(561,610] 1 0.003 0.311 322 1.000 100.000