1 LIBRERÍAS

library(tidyverse)
## ── Attaching core tidyverse packages ──────────────────────── tidyverse 2.0.0 ──
## ✔ dplyr     1.1.4     ✔ readr     2.1.5
## ✔ forcats   1.0.0     ✔ stringr   1.5.1
## ✔ ggplot2   3.5.2     ✔ tibble    3.3.0
## ✔ lubridate 1.9.4     ✔ tidyr     1.3.1
## ✔ purrr     1.1.0     
## ── Conflicts ────────────────────────────────────────── tidyverse_conflicts() ──
## ✖ dplyr::filter() masks stats::filter()
## ✖ dplyr::lag()    masks stats::lag()
## ℹ Use the conflicted package (<http://conflicted.r-lib.org/>) to force all conflicts to become errors
library(lme4)
## Cargando paquete requerido: Matrix
## 
## Adjuntando el paquete: 'Matrix'
## 
## The following objects are masked from 'package:tidyr':
## 
##     expand, pack, unpack
library(emmeans)
## Welcome to emmeans.
## Caution: You lose important information if you filter this package's results.
## See '? untidy'
library(car)
## Cargando paquete requerido: carData
## 
## Adjuntando el paquete: 'car'
## 
## The following object is masked from 'package:dplyr':
## 
##     recode
## 
## The following object is masked from 'package:purrr':
## 
##     some

2 PROBLEMA 1 - Crecimiento bacteriano

2.1 Datos

df1 <- data.frame(
Unidad = rep(1:9, 2),
Temperatura = rep(c(rep("T0",3), rep("T5",3), rep("T10",3)), 2),
Marisco = c(rep("O",9), rep("M",9)),
Bacterias = c(
4879, 68, 170900, 15670000, 2101000000, 26270000, 6084000000, 2953000, 2781000000,
2.276, 52, 37840, 103960, 89510000, 243300, 13651000000, 111750, 1078600000000000
)
)

# Transformación log10
df1 <- df1%>% mutate(LogBac = log10(Bacterias))

# Convertir a en factor
df1$Temperatura <- factor(df1$Temperatura)
df1$Marisco <- factor(df1$Marisco)

2.2 Modelo mixto

mod1 <- lmer(LogBac ~ Temperatura * Marisco + (1|Unidad), data = df1)

2.3 Resultados

anova(mod1) # ANOVA de efectos fijos
summary(mod1) # coeficientes
## Linear mixed model fit by REML ['lmerMod']
## Formula: LogBac ~ Temperatura * Marisco + (1 | Unidad)
##    Data: df1
## 
## REML criterion at convergence: 60.8
## 
## Scaled residuals: 
##      Min       1Q   Median       3Q      Max 
## -1.44575 -0.24705  0.02554  0.37969  1.69364 
## 
## Random effects:
##  Groups   Name        Variance Std.Dev.
##  Unidad   (Intercept) 3.879    1.970   
##  Residual             2.740    1.655   
## Number of obs: 18, groups:  Unidad, 9
## 
## Fixed effects:
##                         Estimate Std. Error t value
## (Intercept)               2.2170     1.4853   1.493
## TemperaturaT10            7.8550     2.1006   3.739
## TemperaturaT5             3.9013     2.1006   1.857
## MariscoO                  1.3675     1.3514   1.012
## TemperaturaT10:MariscoO  -2.8734     1.9112  -1.503
## TemperaturaT5:MariscoO    0.4932     1.9112   0.258
## 
## Correlation of Fixed Effects:
##             (Intr) TmpT10 TmprT5 MarscO TT10:M
## TempertrT10 -0.707                            
## TemperatrT5 -0.707  0.500                     
## MariscoO    -0.455  0.322  0.322              
## TmprtT10:MO  0.322 -0.455 -0.227 -0.707       
## TmprtrT5:MO  0.322 -0.227 -0.455 -0.707  0.500

2.4 Comparaciones múltiples (Tukey)

emm1 <- emmeans(mod1, ~ Temperatura * Marisco)
pairs(emm1, ajuste = "tukey")
##  contrast      estimate   SE   df t.ratio p.value
##  T0 M - T10 M    -7.855 2.10 8.93  -3.739  0.0387
##  T0 M - T5 M     -3.901 2.10 8.93  -1.857  0.4801
##  T0 M - T0 O     -1.367 1.35 6.00  -1.012  0.8983
##  T0 M - T10 O    -6.349 2.10 8.93  -3.023  0.1070
##  T0 M - T5 O     -5.762 2.10 8.93  -2.743  0.1582
##  T10 M - T5 M     3.954 2.10 8.93   1.882  0.4674
##  T10 M - T0 O     6.488 2.10 8.93   3.088  0.0975
##  T10 M - T10 O    1.506 1.35 6.00   1.114  0.8599
##  T10 M - T5 O     2.093 2.10 8.93   0.996  0.9079
##  T5 M - T0 O      2.534 2.10 8.93   1.206  0.8239
##  T5 M - T10 O    -2.448 2.10 8.93  -1.165  0.8423
##  T5 M - T5 O     -1.861 1.35 6.00  -1.377  0.7397
##  T0 O - T10 O    -4.982 2.10 8.93  -2.372  0.2602
##  T0 O - T5 O     -4.394 2.10 8.93  -2.092  0.3683
##  T10 O - T5 O     0.587 2.10 8.93   0.280  0.9997
## 
## Degrees-of-freedom method: kenward-roger 
## P value adjustment: tukey method for comparing a family of 6 estimates

2.5 Validación de supuestos

shapiro.test(resid(mod1)) # normalidad residuos
## 
##  Shapiro-Wilk normality test
## 
## data:  resid(mod1)
## W = 0.94571, p-value = 0.3617

2.6 Gráfica

ggplot(df1, aes(Temperatura, LogBac, fill=Marisco)) +
geom_boxplot() + theme_minimal() +
labs(title="Problema 1: Log10 Contenido bacteriano")

2.7 Conclusiones — Problema 1 (Crecimiento bacterial)

La temperatura de almacenamiento afecta significativamente el conteo bacteriano después de la transformación log10. T5 (p ≈ 0.0229) y especialmente T10 (p ≈ 0.000005) son mayores que T0; ANOVA global p ≈ 0.0049.

El tipo de marisco (ostión vs mejillón) no mostró efecto significativo (p ≈ 0.2152). Interacción T×M no significativa (p ≈ 0.2426), aunque T10×O muestra tendencia (p ≈ 0.066).

Las unidades (Unit) presentan variabilidad importante (bloque), por lo que es correcto modelarlas como efecto aleatorio.

Recomendación: controlar la temperatura de almacenamiento (evitar T5 y T10) e investigar condiciones de cada unidad de enfriamiento.

3 PROBLEMA 2 - Cuadro latino (Leche y Proteína)

3.1 Datos

df2 <- tribble(
  ~Vaca, ~Periodo, ~Tratamiento, ~Leche, ~Proteina,
  "A", "P1", "Control", 60.0, 3.01,
  "A", "P2", "5%",      65.0, 3.09,
  "A", "P3", "10%",     60.0, 3.10,
  "B", "P1", "5%",      72.0, 2.95,
  "B", "P2", "10%",     74.0, 2.89,
  "B", "P3", "Control", 65.0, 2.72,
  "C", "P1", "10%",     45.0, 3.50,
  "C", "P2", "Control", 49.0, 3.40,
  "C", "P3", "5%",      67.0, 3.30
)

# Convertir a en factor
df2 <- df2%>% mutate(
Vaca = factor(Vaca),
Periodo = factor(Periodo),
Tratamiento = factor(Tratamiento)
)

3.2 ANOVA para Leche

mod_leche <- aov(Leche ~ Tratamiento + Periodo + Vaca, data = df2)
car::Anova(mod_leche, type = 2)
emmeans(mod_leche, pairwise ~ Tratamiento)
## $emmeans
##  Tratamiento emmean   SE df lower.CL upper.CL
##  10%           59.7 4.54  2     40.1     79.2
##  5%            68.0 4.54  2     48.5     87.5
##  Control       58.0 4.54  2     38.5     77.5
## 
## Results are averaged over the levels of: Periodo, Vaca 
## Confidence level used: 0.95 
## 
## $contrasts
##  contrast      estimate   SE df t.ratio p.value
##  10% - 5%         -8.33 6.42  2  -1.299  0.5191
##  10% - Control     1.67 6.42  2   0.260  0.9642
##  5% - Control     10.00 6.42  2   1.558  0.4286
## 
## Results are averaged over the levels of: Periodo, Vaca 
## P value adjustment: tukey method for comparing a family of 3 estimates

3.3 Anova para proteina

mod_prot <- aov(Proteina ~ Tratamiento + Periodo + Vaca, data = df2)
car::Anova(mod_prot, type = 2)
emmeans(mod_prot, pairwise ~ Tratamiento)
## $emmeans
##  Tratamiento emmean     SE df lower.CL upper.CL
##  10%           3.16 0.0418  2     2.98     3.34
##  5%            3.11 0.0418  2     2.93     3.29
##  Control       3.04 0.0418  2     2.86     3.22
## 
## Results are averaged over the levels of: Periodo, Vaca 
## Confidence level used: 0.95 
## 
## $contrasts
##  contrast      estimate     SE df t.ratio p.value
##  10% - 5%          0.05 0.0591  2   0.846  0.7172
##  10% - Control     0.12 0.0591  2   2.032  0.3064
##  5% - Control      0.07 0.0591  2   1.185  0.5644
## 
## Results are averaged over the levels of: Periodo, Vaca 
## P value adjustment: tukey method for comparing a family of 3 estimates

3.4 Validación de supuestos

shapiro.test(resid(mod_leche))
## 
##  Shapiro-Wilk normality test
## 
## data:  resid(mod_leche)
## W = 0.7505, p-value = 0.005495
shapiro.test(resid(mod_prot))
## 
##  Shapiro-Wilk normality test
## 
## data:  resid(mod_prot)
## W = 0.81911, p-value = 0.03367

3.5 Gráficas

ggplot(df2, aes(Tratamiento, Leche, fill=Tratamiento)) +
geom_boxplot() + theme_minimal() +
labs(title="Problema 2: Volumen de Leche")

ggplot(df2, aes(Tratamiento, Proteina, fill=Tratamiento)) +
geom_boxplot() + theme_minimal() +
labs(title="Problema 2: % Proteína")

4 Conclusiones — Problema 2 (Cuadro latino: Leche y % Proteína)

  1. No se detectó efecto significativo de los tratamientos (5% o 10%) sobre volumen de leche (p = 0.4177) ni sobre % proteína (p = 0.3244).

  2. Existe efecto significativo entre vacas en % proteína (p ≈ 0.0225), indicando que la variabilidad entre animales es relevante.

  3. Los residuos no cumplen normalidad (Shapiro-Wilk: Leche p ≈ 0.0055; Proteína p ≈ 0.0337) y los df residuales son muy bajos (df = 2); por tanto interpretar resultados con cautela.

Recomendación: aumentar replicación (más vacas/periodos) o usar métodos robustos/no paramétricos para obtener conclusiones más confiables.