UNIVERSIDAD AUTONÓMA DE NUEVO
LEÓN
FACULTAD DE CIENCIAS BIOLOGICAS
BIOESTADÍSTICA
CIUDAD UNIVERSITARIA, SAN NICOLÁS DE LOS GARZA, NUEVO LEÓN
24 DE NOVIEMBRE DEL 2025
TAREA 7
> library(tidyr)
> library(readxl)
> library(ggplot2)
> library(ggpubr)
Attaching package: ggpubr’
The following object is masked from ‘package:cowplot’:
get_legend
> library(dplyr)
Attaching package: ‘dplyr’
The following objects are masked from ‘package:stats’:
filter, lag
The following objects are masked from ‘package:base’:
intersect, setdiff, setequal, union
> rat_chow <- c(660,655,690,670,640,675,650,645,680,685,640,660)
> enriched <- c(710,690,685,680,700,695,715,695,700,705,710,700)
> ratas <- [Link](
+ peso = c(rat_chow, enriched),
+ dieta = rep(c("Comercial", "Enriquecida"), each = 12)
+)
> # supuestos
> [Link](rat_chow)
Shapiro-Wilk normality test
data: rat_chow
W = 0.93994, p-value = 0.4973
> [Link](enriched)
Shapiro-Wilk normality test
data: enriched
W = 0.97056, p-value = 0.9166
> [Link](peso ~ dieta, data = ratas)
F test to compare two variances
data: peso by dieta
F = 2.7565, num df = 11, denom df = 11, p-value = 0.1071
alternative hypothesis: true ratio of variances is not equal to 1
95 percent confidence interval:
0.7935278 9.5751704
sample estimates:
ratio of variances
2.756477
> # prueba t
> [Link](peso ~ dieta, data = ratas, [Link] = TRUE)
Two Sample t-test
data: peso by dieta
t = -6.1871, df = 22, p-value = 3.157e-06
alternative hypothesis: true difference in means between group Comercial and group
Enriquecida is not equal to 0
95 percent confidence interval:
-48.40078 -24.09922
sample estimates:
mean in group Comercial mean in group Enriquecida
662.50 698.75
> # intervalos
> ratas %>%
+ group_by(dieta) %>%
+ summarise(
+ media = mean(peso),
+ IC_inf = mean(peso) - qt(0.975, df=11)*sd(peso)/sqrt(12),
+ IC_sup = mean(peso) + qt(0.975, df=11)*sd(peso)/sqrt(12)
+ )
# A tibble: 2 × 4
dieta media IC_inf IC_sup
<chr> <dbl> <dbl> <dbl>
1 Comercial 662. 651. 674.
2 Enriquecida 699. 692. 705.
> # boxplot
> ggboxplot(ratas, x = "dieta", y = "peso", color = "dieta", palette = "jco",
+ add = "mean_ci", ylab = "Peso del cortex (mg)", xlab = "Tipo de dieta")
TAREA 8
> library(readxl)
> library(ggplot2)
> library(dplyr)
> library(tidyr)
> library(ggpubr)
> library(BSDA)
Loading required package: lattice
Attaching package: ‘BSDA’
The following object is masked from ‘package:datasets’:
Orange> alpha <- 0.05
> datos1 <- read_excel("agelaius_implante.xlsx")
> # Verificar normalidad
> [Link](datos1$antes)
Shapiro-Wilk normality test
data: datos1$antes
W = 0.73117, p-value = 0.001159
> [Link](datos1$despues)
Shapiro-Wilk normality test
data: datos1$despues
W = 0.8182, p-value = 0.01131
> # t pareada
> t_test <- [Link](datos1$antes, datos1$despues, paired = TRUE)
> print(t_test)
Paired t-test
data: datos1$antes and datos1$despues
t = -1.2714, df = 12, p-value = 0.2277
alternative hypothesis: true mean difference is not equal to 0
95 percent confidence interval:
-0.15238464 0.04007695
sample estimates:
mean difference
-0.05615385
> # Wilcoxon
> wilcox_test <- [Link](datos1$antes, datos1$despues, paired = TRUE)
> print(wilcox_test)
Wilcoxon signed rank exact test
data: datos1$antes and datos1$despues
V = 30, p-value = 0.3054
alternative hypothesis: true location shift is not equal to 0
> # Sign test
> sign_test <- [Link](datos1$antes, datos1$despues)
> print(sign_test)
Dependent-samples Sign-Test
data: datos1$antes and datos1$despues
S = 4, p-value = 0.2668
alternative hypothesis: true median difference is not equal to 0
95 percent confidence interval:
-0.16027972 0.08027972
sample estimates:
median of x-y
-0.07
Achieved and Interpolated Confidence Intervals:
[Link] [Link] [Link]
Lower Achieved CI 0.9077 -0.1300 0.0500
Interpolated CI 0.9500 -0.1603 0.0803
Upper Achieved CI 0.9775 -0.1800 0.1000
> # Grafico
> datos1_long <- pivot_longer(datos1, cols = c("antes", "despues"),
+ names_to = "momento", values_to = "inmunocompetencia")
> ggplot(datos1_long, aes(x = momento, y = inmunocompetencia)) +
+ geom_boxplot(fill = "skyblue") +
+ geom_point(aes(group = ID),
+ position = position_jitter(width = 0.1), alpha = 0.6) +
+ stat_compare_means(method = "[Link]", paired = TRUE) +
+ labs(title = "Cambio en inmunocompetencia antes y despues del implante")
> datos2 <- read_excel("[Link]")
> # Normalidad
> [Link](datos2$Punto_I)
Shapiro-Wilk normality test
data: datos2$Punto_I
W = 0.93263, p-value = 0.5068
> [Link](datos2$Punto_II)
Shapiro-Wilk normality test
data: datos2$Punto_II
W = 0.92067, p-value = 0.3978
> # Prueba t pareada
> t_test2 <- [Link](datos2$Punto_I, datos2$Punto_II, paired = TRUE)
> print(t_test2)
Paired t-test
data: datos2$Punto_I and datos2$Punto_II
t = 2.8231, df = 8, p-value = 0.02239
alternative hypothesis: true mean difference is not equal to 0
95 percent confidence interval:
1.343145 13.323522
sample estimates:
mean difference
7.333333
> # Wilcoxon
> wilcox_test2 <- [Link](datos2$Punto_I, datos2$Punto_II, paired = TRUE)
> print(wilcox_test2)
Wilcoxon signed rank exact test
data: datos2$Punto_I and datos2$Punto_II
V = 39, p-value = 0.05469
alternative hypothesis: true location shift is not equal to 0
> # Grafico
> datos2_long <- pivot_longer(datos2, cols = c("Punto_I", "Punto_II"),
+ names_to = "Sitio", values_to = "Densidad")
> ggplot(datos2_long, aes(x = Sitio, y = Densidad)) +
+ geom_boxplot(fill = "lightgreen") +
+ geom_point(aes(group = ID),
+ position = position_jitter(width = 0.1), alpha = 0.6) +
+ stat_compare_means(method = "[Link]", paired = TRUE) +
+ labs(title = "Densidad de celulas nerviosas en intestino de caballos")
> datos3 <- read_excel("[Link]")
> # Normalidad
> [Link](datos3$Agosto)
Shapiro-Wilk normality test
data: datos3$Agosto
W = 0.87976, p-value = 0.07078
> [Link](datos3$Noviembre)
Shapiro-Wilk normality test
data: datos3$Noviembre
W = 0.72299, p-value = 0.0009517
> # Prueba t
> t_test3 <- [Link](datos3$Agosto, datos3$Noviembre, paired = TRUE)
> print(t_test3)
Paired t-test
data: datos3$Agosto and datos3$Noviembre
t = -2.3089, df = 12, p-value = 0.03956
alternative hypothesis: true mean difference is not equal to 0
95 percent confidence interval:
-9.5239348 -0.2760652
sample estimates:
mean difference
-4.9
> # Wilcoxon
> wilcox_test3 <- [Link](datos3$Agosto, datos3$Noviembre, paired = TRUE)
> print(wilcox_test3)
Wilcoxon signed rank exact test
data: datos3$Agosto and datos3$Noviembre
V = 16, p-value = 0.03979
alternative hypothesis: true location shift is not equal to 0
> # Grafico
> datos3_long <- pivot_longer(datos3, cols = c("Agosto", "Noviembre"),
+ names_to = "Mes", values_to = "Aluminio")
> ggplot(datos3_long, aes(x = Mes, y = Aluminio)) +
+ geom_boxplot(fill = "orange") +
+ geom_point(aes(group = ID),
+ position = position_jitter(width = 0.1), alpha = 0.6) +
+ stat_compare_means(method = "[Link]", paired = TRUE) +
+ labs(title = "Concentracion de aluminio en madera de alamo")
> datos4 <- read_excel("[Link]")
> # Normalidad
> [Link](datos4$Antes)
Shapiro-Wilk normality test
data: datos4$Antes
W = 0.95308, p-value = 0.3155
> [Link](datos4$Despues)
Shapiro-Wilk normality test
data: datos4$Despues
W = 0.93032, p-value = 0.09912
> # t pareada
> t_test4 <- [Link](datos4$Antes, datos4$Despues, paired = TRUE)
> print(t_test4)
Paired t-test
data: datos4$Antes and datos4$Despues
t = 23.759, df = 23, p-value < 2.2e-16
alternative hypothesis: true mean difference is not equal to 0
95 percent confidence interval:
4.161450 4.955217
sample estimates:
mean difference
4.558333
> # Wilcoxon
> wilcox_test4 <- [Link](datos4$Antes, datos4$Despues, paired = TRUE)
Warning message:
In [Link](datos4$Antes, datos4$Despues, paired = TRUE) :
cannot compute exact p-value with ties
> print(wilcox_test4)
Wilcoxon signed rank test with continuity correction
data: datos4$Antes and datos4$Despues
V = 300, p-value = 1.935e-05
alternative hypothesis: true location shift is not equal to 0
> # Grafico
> datos4_long <- pivot_longer(datos4, cols = c("Antes", "Despues"),
+ names_to = "Estado", values_to = "Actividad")
> ggplot(datos4_long, aes(x = Estado, y = Actividad)) +
+ geom_boxplot(fill = "purple") +
+ geom_point(aes(group = ID),
+ position = position_jitter(width = 0.1), alpha = 0.6) +
+ stat_compare_means(method = "[Link]", paired = TRUE) +
+ labs(title = "Actividad de EnzA en higado de trucha arcoiris")
TAREA 9
> library(readxl)
> library(ggplot2)
> library(car)
Loading required package: carData
Attaching package: ‘carData’
The following objects are masked from ‘package:BSDA’:
Vocab, Wool
Attaching package: ‘car’
The following object is masked from ‘package:dplyr’:
recode> library(dplyr)
> library(tidyr)
> insulina <- read_excel("[Link]")
> # Pasar de formato ancho a largo
> insulina_long <- insulina %>%
+ pivot_longer(cols = starts_with("C"),
+ names_to = "Camada",
+ values_to = "Insulina")
> # Quitar NA
> insulina_long <- insulina_long %>% drop_na()
> insulina_long$Camada <- [Link](insulina_long$Camada)
> # Supuestos
> [Link](insulina_long$Insulina)
Shapiro-Wilk normality test
data: insulina_long$Insulina
W = 0.95649, p-value = 0.06335
> leveneTest(Insulina ~ Camada, data = insulina_long)
Levene's Test for Homogeneity of Variance (center = median)
Df F value Pr(>F)
group 5 0.9115 0.4824
44
> # ANOVA
> modelo1 <- aov(Insulina ~ Camada, data = insulina_long)
> summary(modelo1)
Df Sum Sq Mean Sq F value Pr(>F)
Camada 5 89.6 17.926 2.394 0.0527 .
Residuals 44 329.5 7.488
---
Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
> # R2
> r2_1 <- summary(modelo1)[[1]]$`Sum Sq`[1] / sum(summary(modelo1)[[1]]$`Sum Sq`)
> cat("R2 del modelo 1:", round(r2_1, 3), "\n")
R2 del modelo 1: 0.214
> # Post-hoc
> TukeyHSD(modelo1)
Tukey multiple comparisons of means
95% family-wise confidence level
Fit: aov(formula = Insulina ~ Camada, data = insulina_long)
$Camada
diff lwr upr p adj
C2-C1 0.64 -4.5156442 5.7956442 0.9990330
C3-C1 1.08 -4.0756442 6.2356442 0.9886334
C4-C1 2.70 -2.4556442 7.8556442 0.6283067
C5-C1 5.28 0.1243558 10.4356442 0.0419208
Camada-C1 1.94 -2.0535448 5.9335448 0.6985702
C3-C2 0.44 -4.7156442 5.5956442 0.9998448
C4-C2 2.06 -3.0956442 7.2156442 0.8390911
C5-C2 4.64 -0.5156442 9.7956442 0.0996734
Camada-C2 1.30 -2.6935448 5.2935448 0.9250502
C4-C3 1.62 -3.5356442 6.7756442 0.9348838
C5-C3 4.20 -0.9556442 9.3556442 0.1694386
Camada-C3 0.86 -3.1335448 4.8535448 0.9871197
C5-C4 2.58 -2.5756442 7.7356442 0.6718059
Camada-C4 -0.76 -4.7535448 3.2335448 0.9926751
Camada-C5 -3.34 -7.3335448 0.6535448 0.1488617
> # Grafico
> ggplot(insulina_long, aes(x = Camada, y = Insulina)) +
+ geom_boxplot(fill = "skyblue") +
+ labs(title = "Liberacion de insulina por camada",
+ x = "Camada", y = "Insulina (pg/ml)")
TAREA 10
> library(readxl)
> library(ggplot2)
> library(car)
> library(multcomp)
Loading required package: mvtnorm
Loading required package: survival
Loading required package: [Link]
Loading required package: MASS
Attaching package: ‘MASS’
The following object is masked from ‘package:dplyr’:
select
Attaching package: ‘[Link]’
The following object is masked from ‘package:MASS’:
geyser
> library(dplyr)
> corteza <- read_excel("corteza_bifactorial.xlsx")
> corteza$alimento <- [Link](corteza$alimento)
> corteza$ambiente <- [Link](corteza$ambiente)
> # SUPUESTOS
> [Link](corteza$peso_cortex)
Shapiro-Wilk normality test
data: corteza$peso_cortex
W = 0.9744, p-value = 0.7749
> leveneTest(peso_cortex ~ alimento * ambiente, data = corteza)
Levene's Test for Homogeneity of Variance (center = median)
Df F value Pr(>F)
group 3 1.0674 0.3852
20
> # ANOVA BIFACTORIAL
> modelo1 <- aov(peso_cortex ~ alimento * ambiente, data = corteza)
> summary(modelo1)
Df Sum Sq Mean Sq F value Pr(>F)
alimento 1 3876 3876 19.77 0.000248 ***
ambiente 1 3626 3626 18.50 0.000348 ***
alimento:ambiente 1 51 51 0.26 0.615457
Residuals 20 3921 196
---
Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
> # R2
> r2_1 <- summary(modelo1)[[1]]$`Sum Sq`[1] / sum(summary(modelo1)[[1]]$`Sum Sq`)
> cat("R2 modelo corteza:", round(r2_1, 3), "\n")
R2 modelo corteza: 0.338
> # GRAFICA
> ggplot(corteza, aes(x = alimento, y = peso_cortex, fill = ambiente)) +
+ geom_boxplot() +
+ labs(title = "Peso del cortex segun alimento y ambiente",
+ y = "Peso cortex (mg)", x = "Alimento")
> vibrio <- read_excel("vibrio_bifactorial.xlsx")
> vibrio$alimento <- [Link](vibrio$alimento)
> vibrio$temp <- [Link](vibrio$temp)
> # SUPUESTOS
> [Link](vibrio$s_vibrio)
Shapiro-Wilk normality test
data: vibrio$s_vibrio
W = 0.90088, p-value = 0.00153
> leveneTest(s_vibrio ~ alimento * temp, data = vibrio)
Levene's Test for Homogeneity of Variance (center = median)
Df F value Pr(>F)
group 5 3.1459 0.01859 *
36
---
Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
> # ANOVA BIFACTORIAL
> modelo2 <- aov(s_vibrio ~ alimento * temp, data = vibrio)
> summary(modelo2)
Df Sum Sq Mean Sq F value Pr(>F)
alimento 2 5938 2969.2 10.763 0.000217 ***
temp 1 1522 1521.6 5.516 0.024456 *
alimento:temp 2 266 133.0 0.482 0.621373
Residuals 36 9931 275.9
---
Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
> # R2
> r2_2 <- summary(modelo2)[[1]]$`Sum Sq`[1] / sum(summary(modelo2)[[1]]$`Sum Sq`)
> cat("R2 modelo vibrio:", round(r2_2, 3), "\n")
R2 modelo vibrio: 0.336
> # GRAFICA
> ggplot(vibrio, aes(x = alimento, y = s_vibrio, fill = temp)) +
+ geom_boxplot() +
+ labs(title = "Supervivencia de Vibrio",
+ y = "Supervivencia (%)", x = "Alimento")
> veget <- read_excel("veget_bifactorial.xlsx")
> veget$dieta <- [Link](veget$dieta)
> veget$sexo <- [Link](veget$sexo)
> # SUPUESTOS
> [Link](veget$PA)
Shapiro-Wilk normality test
data: veget$PA
W = 0.91254, p-value = 0.01725
> leveneTest(PA ~ dieta * sexo, data = veget)
Levene's Test for Homogeneity of Variance (center = median)
Df F value Pr(>F)
group 5 1.1189 0.3769
24
> # ANOVA BIFACTORIAL
> modelo3 <- aov(PA ~ dieta * sexo, data = veget)
> summary(modelo3)
Df Sum Sq Mean Sq F value Pr(>F)
dieta 2 2389.4 1194.7 95.704 3.66e-12 ***
sexo 1 512.5 512.5 41.057 1.26e-06 ***
dieta:sexo 2 25.3 12.6 1.012 0.378
Residuals 24 299.6 12.5
---
Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
> # R2
> r2_3 <- summary(modelo3)[[1]]$`Sum Sq`[1] / sum(summary(modelo3)[[1]]$`Sum Sq`)
> cat("R2 modelo PA:", round(r2_3, 3), "\n")
R2 modelo PA: 0.74
> # GRAFICA
> ggplot(veget, aes(x = dieta, y = PA, fill = sexo)) +
+ geom_boxplot() +
+ labs(title = "Presion arterial segun dieta y sexo",
+ y = "Presion arterial (mmHg)", x = "Dieta")